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; }
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 }); }
public async Task updateHue(Hue hue) { try { await requestUpdateHue(hue); } catch (Exception e) { Debug.WriteLine("Something went wrong: " + e.Message); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { hue = e.Parameter as Hue; }