public static void ChangeBrightness(string light, int brightness) { ChangeValue(light, brightness, "bri"); if (brightness <= 2) { ToggleLight(light, false); } else { if (JsonParser.Read(Storage.latestData, new string[] { "lights", light, "state", "on" }) == false) { ToggleLight(light, true); } } }
public static void ModeOn(string modeName) { //Turn on the lights if any of them are disabled foreach (string light in Storage.groupData.lights) { if (JsonParser.Read(Storage.latestData, new string[] { "lights", light, "state", "on" }) == false) { PutEvents.ToggleLight(light, true); } } effectMode = modeName; Platform.NotifyCheck(modeName, true); switch (effectMode) { case "test": case "ambient": effectTimer.Interval = 150; bufferData.transitiontime = Platform.ReadSetting("ambientTransition"); break; case "daylight": effectTimer.Interval = 1500; bufferData.transitiontime = 40; if (Platform.ReadSetting("daylightSetting") == 0) //Regional { chosenSunrise = SunriseEquation.JulianToTime(SunriseEquation.sunrise); chosenSunset = SunriseEquation.JulianToTime(SunriseEquation.sunset); } else if (Platform.ReadSetting("daylightSetting") == 1) //Equinox { chosenSunrise = 480; //06:00 chosenSunset = 1080; //18:00 } else if (Platform.ReadSetting("daylightSetting") == 2) //Startup { chosenSunrise = SunriseEquation.JulianToTime(SunriseEquation.startup); chosenSunset = SunriseEquation.JulianToTime(SunriseEquation.startup + 0.5); } break; } if (!effectsOn) { EffectTimerOn(); } }
public static bool IsSceneMatch(string scene) { int i = 1, light = 1, margin = 2; foreach (string lightLabel in Storage.groupData.lights) { if (JsonParser.Read(Storage.sceneData, new string[] { scene, "state", i.ToString() }) != null) { light = i; } dynamic sceneData = JsonParser.Read(Storage.sceneData, new string[] { scene, "state", light.ToString() }); dynamic latestData = JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "state" }); if (Math.Abs(sceneData.bri - latestData.bri) > margin) { return(false); } if (((IDictionary <String, object>)sceneData).ContainsKey("hue") && ((IDictionary <String, object>)latestData).ContainsKey("hue")) { try { if (Math.Abs(sceneData.hue - latestData.hue) > margin) { return(false); } if (Math.Abs(sceneData.sat - latestData.sat) > margin) { return(false); } } catch { } } else if (((IDictionary <String, object>)sceneData).ContainsKey("ct") && ((IDictionary <String, object>)latestData).ContainsKey("ct")) { try { if (Math.Abs(sceneData.ct - latestData.ct) > margin) { return(false); } } catch { } } i++; } return(true); }
public static void EffectsOff() { if (effectTimer.Enabled) { effectMode = ""; effectTimer.Elapsed -= OnTimedEvent; effectTimer.Enabled = false; foreach (string light in Storage.groupData.lights) //Restore last scene data from backup { JsonParser.Create(Storage.latestData, new string[] { "lights", light, "state" }, JsonParser.Read(Storage.sceneBackup, new string[] { light, "state" })); PutEvents.CustomPut(light, JsonParser.Serialize(JsonParser.Read(Storage.sceneBackup, new string[] { light, "state" })), true); } effectsOn = false; Platform.NotifyCheck("", false); } }
public static bool IsSceneMatch(string scene) { int i = 1, light = 1, margin = 2; foreach (string lightLabel in Storage.groupData.lights) { if (JsonParser.Read(Storage.sceneData, new string[] { scene, "state", i.ToString() }) != null) { light = i; } dynamic sceneData = JsonParser.Read(Storage.sceneData, new string[] { scene, "state", light.ToString() }); dynamic latestData = JsonParser.Read(Storage.latestData, new string[] { "lights", lightLabel, "state" }); if (Math.Abs(sceneData.bri - latestData.bri) > margin) { return(false); } if (sceneData.hue != null) { if (Math.Abs(sceneData.hue - latestData.hue) > margin) { return(false); } if (Math.Abs(sceneData.sat - latestData.sat) > margin) { return(false); } } else if (sceneData.ct != null) { if (Math.Abs(sceneData.ct - latestData.ct) > margin) { return(false); } } i++; } return(true); }
public static int ChangeScene(string scene, bool hardCoded) { //Turn on the lights if any of them are disabled foreach (string light in Storage.groupData.lights) { if (JsonParser.Read(Storage.latestData, new string[] { "lights", light, "state", "on" }) == false) { ToggleLight(light, true); } } dynamic tileColor; int tileColorValue; if (hardCoded) { foreach (string light in Storage.groupData.lights) { Uri dataUri = new Uri(AddressBuild.LightState(light)); PutData(dataUri, JsonParser.Serialize(JsonParser.Read(Storage.defaultScenes, new string[] { scene, "state", "1" }))); } tileColorValue = (int)JsonParser.Read(Storage.defaultScenes, new string[] { scene, "tilecolor" }); tileColor = Storage.tileColors(tileColorValue); } else { if (JsonParser.Read(Storage.sceneData, new string[] { scene }) != null) { int i = 1; int limit = 0; foreach (dynamic light in JsonParser.Read(Storage.sceneData, new string[] { scene, "state" })) { limit++; } foreach (string light in Storage.groupData.lights) { Uri dataUri = new Uri(AddressBuild.LightState(light)); PutData(dataUri, JsonParser.Serialize(JsonParser.Read(Storage.sceneData, new string[] { scene, "state", i.ToString() }))); if (i < limit) { i++; } } tileColorValue = (int)JsonParser.Read(Storage.sceneData, new string[] { scene, "tilecolor" }); tileColor = Storage.tileColors(tileColorValue); } else { //Error handling for missing scene data tileColorValue = 0; tileColor = Storage.tileColors(tileColorValue); } } //Change accent to match tile background ChangeAccent(tileColorValue); //Store scene name Storage.currentScene = scene; return(0); }