Exemplo n.º 1
0
        public static int CustomPut(string light, string dataString, bool forceDelay = false)
        {
            Uri dataUri = new Uri(AddressBuild.LightState(light));

            PutData(dataUri, dataString, forceDelay);
            return(0);
        }
Exemplo n.º 2
0
        private static void ChangeValue(string light, int value, string valueName)
        {
            dynamic jsonValue = new ExpandoObject();
            var     jsonRef   = (IDictionary <string, object>)jsonValue;

            jsonRef[valueName] = value;

            Uri dataUri = new Uri(AddressBuild.LightState(light));

            TimePut(dataUri, JsonParser.Serialize(jsonValue));
            JsonParser.Modify(Storage.latestData, new string[] { "lights", light, "state", valueName }, (int)value);
        }
Exemplo n.º 3
0
        public static int ToggleLight(string light, bool isOn)
        {
            dynamic jsonToggle = new ExpandoObject();

            if (isOn == true)
            {
                jsonToggle.on = true;
            }
            else
            {
                jsonToggle.on = false;
            }

            Uri dataUri = new Uri(AddressBuild.LightState(light));

            JsonParser.Modify(Storage.latestData, new string[] { "lights", light, "state", "on" }, isOn);
            PutData(dataUri, JsonParser.Serialize(jsonToggle));
            return(0);
        }
Exemplo n.º 4
0
        //Controls timePutAllowed
        private static void EffectTimerOn()
        {
            bufferData.bri = 0;
            bufferData.hue = 0;
            bufferData.sat = 0;

            int arrayLength = Storage.groupData.lights.Length;

            lightArray = new Uri[arrayLength];
            int i = 0;

            foreach (string light in Storage.groupData.lights)
            {
                lightArray[i] = new Uri(AddressBuild.LightState(light));
                i++;
            }

            lastLight            = 0;
            effectTimer.Elapsed += OnTimedEvent;
            effectTimer.Enabled  = true;
            ToggleEffectsOn();
        }
Exemplo n.º 5
0
        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);
        }