Exemple #1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            var lightId = (int)e.Parameter;

            chosenLight = lightsList.Find(x => x.Id == lightId);

            if (chosenLight != null)
            {
                toggleSwitch.IsOn = chosenLight.On;
                hue.Value = chosenLight.Hue;
                saturation.Value = chosenLight.Saturation;
                brightness.Value = chosenLight.Brightness;
            }

            loadingPage = false;
        }
Exemple #2
0
        public async static Task parseLights(ObservableCollection<Light> lightsCollection)
        {
            String httpResponse = await getLightsFromService();
            lightsCollection.Clear();
            HueStore.Instance.lights.Clear();

            var lights = HueStore.Instance.lights;

            Light light;

            try
            {
                JsonObject bridgeObject = JsonObject.Parse(httpResponse);
                // var lightObject = bridgeObject.GetNamedObject("lights");

                foreach (string lightID in bridgeObject.Keys)
                {
                    JsonObject lightUniqueObject = bridgeObject.GetNamedObject(lightID);
                    JsonObject stateObject = lightUniqueObject.GetNamedObject("state");

                    light = new Light();
                    light.Id = Convert.ToInt32(lightID);
                    light.Name = lightUniqueObject.GetNamedString("name");
                    light.On = stateObject.GetNamedBoolean("on");
                    light.Hue = Convert.ToInt32(stateObject.GetNamedNumber("hue"));
                    light.Saturation = Convert.ToInt32(stateObject.GetNamedNumber("sat"));
                    light.Brightness = Convert.ToInt32(stateObject.GetNamedNumber("bri"));

                    light.Colour = ColorFromHSV((double)light.Hue, (double)light.Saturation, (double)light.Brightness);

                    lights.Add(light);
                    lightsCollection.Add(light);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.Write(e);
            }
        }