Пример #1
0
        private async Task<List<Hue>> requestHueList()
        {
            List<Hue> hueList = new List<Hue>();

            var response = await bridgeBaseUrl
                .AppendPathSegment("lights")
                .GetJsonAsync();

            foreach (KeyValuePair<string, object> item in response)
            {
                IDictionary<string, object> itemDict = (ExpandoObject) item.Value;
                IDictionary<string, object> stateDict = (ExpandoObject) itemDict["state"];

                Hue h = new Hue(
                    int.Parse(item.Key),
                    itemDict.ContainsKey("uniqueid") ? (string) itemDict["uniqueid"] : "",
                    (string) itemDict["name"],
                    (bool) stateDict["on"],
                    double.Parse(stateDict["hue"].ToString()),
                    double.Parse(stateDict["bri"].ToString()),
                    double.Parse(stateDict["sat"].ToString())
                );

                hueList.Add(h);
            }

            return hueList;
        }
Пример #2
0
 private async Task requestUpdateHue(Hue hue)
 {
     await bridgeBaseUrl
         .AppendPathSegment("lights")
         .AppendPathSegment($"{hue.key}")
         .AppendPathSegment("state")
         .PutJsonAsync(new { on = hue.on, hue = hue.hue, sat = hue.sat, bri = hue.bri });
 }
Пример #3
0
 public async Task updateHue(Hue hue)
 {
     try
     {
         await requestUpdateHue(hue);
     }
     catch (Exception e)
     {
         Debug.WriteLine("Something went wrong: " + e.Message);
     }
 }
Пример #4
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     hue = e.Parameter as Hue;
 }