Light.fromJson constructor

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

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

Implementation

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

  return Light(
    id: data[ApiFields.id] ?? "",
    idV1: data[ApiFields.idV1] ?? "",
    type: ResourceType.fromString(data[ApiFields.type] ?? ""),
    owner: Relative.fromJson(
        Map<String, dynamic>.from(data[ApiFields.owner] ?? {})),
    metadata: LightMetadata.fromJson(
        Map<String, dynamic>.from(data[ApiFields.metadata] ?? {})),
    on: LightOn.fromJson(
        Map<String, dynamic>.from(data[ApiFields.isOn] ?? {})),
    dimming: LightDimmingFull.fromJson(
        Map<String, dynamic>.from(data[ApiFields.dimming] ?? {})),
    dimmingDelta: data[ApiFields.dimmingDelta] == null
        ? null
        : LightDimmingDelta.fromJson(
            Map<String, dynamic>.from(data[ApiFields.dimmingDelta] ?? {})),
    colorTemperature: LightColorTemperature.fromJson(
        data[ApiFields.colorTemperature] ?? {}),
    colorTemperatureDelta: data[ApiFields.colorTemperatureDelta] == null
        ? null
        : LightColorTemperatureDelta.fromJson(Map<String, dynamic>.from(
            data[ApiFields.colorTemperatureDelta] ?? {})),
    color: LightColor.fromJson(
        Map<String, dynamic>.from(data[ApiFields.color] ?? {})),
    dynamics: LightDynamics.fromJson(
        Map<String, dynamic>.from(data[ApiFields.dynamics] ?? {})),
    alert: LightAlert.fromJson(
        Map<String, dynamic>.from(data[ApiFields.alert] ?? {})),
    signaling: LightSignaling.fromJson(
        Map<String, dynamic>.from(data[ApiFields.signaling] ?? {})),
    mode: LightMode.fromString(data[ApiFields.mode] ?? ""),
    gradient: LightGradientFull.fromJson(
        Map<String, dynamic>.from(data[ApiFields.gradient] ?? {})),
    effects: LightEffects.fromJson(
        Map<String, dynamic>.from(data[ApiFields.effects] ?? {})),
    timedEffects: LightTimedEffects.fromJson(
        Map<String, dynamic>.from(data[ApiFields.timedEffects] ?? {})),
    powerUp: LightPowerUp.fromJson(
        Map<String, dynamic>.from(data[ApiFields.powerUp] ?? {})),
  );
}