public LightDataModel AddOrUpdateLight(Light light, GroupDataModel roomGroup) { string lightKey = $"light-{light.Id}"; LightDataModel lightDataModel = TryGetDynamicChild(lightKey, out DynamicChild <LightDataModel> dynamicChild) ? dynamicChild.Value : AddDynamicChild(lightKey, new LightDataModel(light), light.Name).Value; lightDataModel.HueLight = light; lightDataModel.UpdateColor(); if (GroupType != GroupType.Room && roomGroup != null) { lightDataModel.DataModelDescription.Name = $"{light.Name} - {roomGroup.Name}"; } return(lightDataModel); }
public LightDataModel AddOrUpdateLight(Light light, GroupDataModel roomGroup) { string lightKey = $"light-{light.Id}"; LightDataModel lightDataModel = DynamicChild <LightDataModel>(lightKey); if (lightDataModel == null) { lightDataModel = AddDynamicChild(new LightDataModel(light), lightKey, light.Name); } lightDataModel.HueLight = light; lightDataModel.UpdateColor(); if (GroupType != GroupType.Room && roomGroup != null) { lightDataModel.DataModelDescription.Name = $"{light.Name} - {roomGroup.Name}"; } return(lightDataModel); }
public LightDataModel AddOrUpdateLight(Light light, GroupDataModel roomGroup) { // Find or add the dynamic child and update it with the latest light info string lightKey = $"light-{light.Id}"; LightDataModel lightDataModel = TryGetDynamicChild(lightKey, out DynamicChild <LightDataModel> dynamicChild) ? dynamicChild.Value : AddDynamicChild(lightKey, new LightDataModel(light), light.Name).Value; // Simply setting HueLight will cause all properties (which are calculated properties) to update lightDataModel.HueLight = light; // Colors are likely accessed often and are therefore calculated once per update lightDataModel.UpdateColor(); // If not in a room, add the zone name to the light name if (GroupType != GroupType.Room && roomGroup != null) { lightDataModel.DataModelDescription.Name = $"{light.Name} - {roomGroup.Name}"; } return(lightDataModel); }