ChannelOccupancy.fromJson constructor

ChannelOccupancy.fromJson(
  1. String channelName,
  2. Map<String, dynamic> channelObject
)

Implementation

factory ChannelOccupancy.fromJson(
    String channelName, Map<String, dynamic> channelObject) {
  var uuids = <String, OccupantInfo>{};

  if (channelObject['uuids'] != null) {
    for (var uuid in channelObject['uuids']) {
      if (uuid is String) {
        uuids[uuid] = OccupantInfo(uuid);
      } else if (uuid is Map<String, dynamic>) {
        uuids[uuid['uuid'] as String] = OccupantInfo(uuid['uuid'] as String,
            state: uuid['state'] as Map<String, dynamic>);
      }
    }
  }

  return ChannelOccupancy(
      channelName, uuids, channelObject['occupancy'] as int);
}