GroupedLight.fromJson constructor

GroupedLight.fromJson(
  1. Map<String, dynamic> dataMap
)

Creates a GroupedLight object from the JSON response to a GET request.

Implementation

factory GroupedLight.fromJson(Map<String, dynamic> dataMap) {
  // Handle entire response given with no filter.
  Map<String, dynamic> data = MiscTools.extractData(dataMap);

  return GroupedLight(
    type: ResourceType.fromString(data[ApiFields.type] ?? ""),
    id: data[ApiFields.id] ?? "",
    idV1: data[ApiFields.idV1] ?? "",
    owner: Relative.fromJson(
        Map<String, dynamic>.from(data[ApiFields.owner] ?? {})),
    on: LightOn.fromJson(
        Map<String, dynamic>.from(data[ApiFields.isOn] ?? {})),
    dimming: LightDimming.fromJson(
        Map<String, dynamic>.from(data[ApiFields.dimming] ?? {})),
    dimmingDelta: data[ApiFields.dimmingDelta] == null
        ? null
        : LightDimmingDelta.fromJson(
            Map<String, dynamic>.from(data[ApiFields.dimmingDelta] ?? {})),
    colorTemperature: data[ApiFields.colorTemperature] == null
        ? null
        : LightPowerUpColorColorTemperature.fromJson(
            data[ApiFields.colorTemperature] ?? {}),
    colorTemperatureDelta: data[ApiFields.colorTemperatureDelta] == null
        ? null
        : LightColorTemperatureDelta.fromJson(Map<String, dynamic>.from(
            data[ApiFields.colorTemperatureDelta] ?? {})),
    xy: data[ApiFields.color] == null
        ? null
        : LightColorXy.fromJson(
            Map<String, dynamic>.from(
              Map<String, dynamic>.from(
                      data[ApiFields.color] ?? {})[ApiFields.xy] ??
                  {},
            ),
          ),
    alert: LightAlert.fromJson(
        Map<String, dynamic>.from(data[ApiFields.alert] ?? {})),
    durationMilliseconds: data[ApiFields.duration],
  );
}