Esempio n. 1
0
        public static void UpdateLightWithJObject(Light light, JObject json)
        {
            try
            {
                // Name
                JToken nameToken;
                if(json.TryGetValue("name", out nameToken))
                {
                    light.Name = json["name"].ToString();
                }

                // State
                JToken stateToken;
                if (json.TryGetValue("state", out stateToken))
                {
                    JObject stateJson = (JObject)json["state"];
                    light.IsOn = bool.Parse(stateJson["on"].ToString());
                    light.Brightness = int.Parse(stateJson["bri"].ToString());
                    light.Hue = int.Parse(stateJson["hue"].ToString());
                    light.Saturation = int.Parse(stateJson["sat"].ToString());

                    JArray coordArray = (JArray)stateJson["xy"];
                    light.X = double.Parse(coordArray[0].ToString());
                    light.Y = double.Parse(coordArray[1].ToString());

                    light.Temperature = int.Parse(stateJson["ct"].ToString());
                    light.AlertEffect = stateJson["alert"].ToString();
                    light.Effect = stateJson["effect"].ToString();

                    light.ColorMode = stateJson["colormode"].ToString();
                    light.IsReachable = bool.Parse(stateJson["reachable"].ToString());
                }
            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Esempio n. 2
0
 public void InvalidateLightProperties(Light light)
 {
     if (LightPropertyChanged != null)
     {
         LightPropertyChanged(light, null);
     }
 }
Esempio n. 3
0
        public static void UpdateBridgeLightsWithJObject(Bridge bridge, JObject json)
        {
            try
            {
                // Get light keys
                IList<string> lightKeys = json.Properties().Select(p => p.Name).ToList();

                bridge.LightList.Clear();
                bridge.LightCache.Clear();

                foreach(var lightId in lightKeys)
                {
                    Light light = new Light();
                    light.LightId = lightId;
                    bridge.LightList.Add(light);
                    bridge.LightCache[lightId] = light;

                    JObject lightJson = (JObject)json[lightId];
                    LightFactory.UpdateLightWithJObject(light, lightJson);
                }
            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }