public async Task <bool> HandleRequest(Device device, SetDeviceStateRequest request) { try { var resp = await client.GetAsync(request.On?device.OnUrl : device.OffUrl); resp.EnsureSuccessStatusCode(); } catch (Exception ex) { Console.WriteLine(ex); } return(false); }
public static void SetValueFromBri(this SetDeviceStateRequest request, Device device) { //switch (device.DeviceType) { //case DeviceType.Switch: // //TODO: set dim // return; //case DeviceType.Thermostat: // var temp = request.GetBriValue (device); // request.Value = temp; // return; //} }
public static int GetBriValue(this SetDeviceStateRequest request, Device device) { int val = request.Bri; //switch (device.ConversionType) { //case BriConversionType.Byte: // val = request.Bri; // break; //case BriConversionType.Percent: // val = (int)Math.Round ((request.Bri / 255d) * 100); // break; //case BriConversionType.Math: // throw new NotSupportedException (); //} throw new NotSupportedException(); return(val); }
public async Task <bool> SetDeviceState(Device device, SetDeviceStateRequest state) { var events = SetDeviceEvent?.GetInvocationList().ToList(); //Let the last subscription get first dibs events?.Reverse(); var handled = false; var args = new SetDeviceArgs { Device = device, Request = state, }; if (events != null) { foreach (var e in events) { try { handled = await Task.Run(() => (e as SetDeviceStateHandler)?.Invoke (this, args) ?? false); if (handled) { return(args.Success); } } catch (Exception ex) { Console.WriteLine(ex); } } } var handlerList = GetHandlerList(device.Service ?? WebRequestHandler.Identifier); for (var i = handlerList.Count - 1; i >= 0; i--) { var handler = handlerList [i]; handled = await handler.HandleRequest(device, state); if (handled) { return(true); } } return(false); }
public static string GetBriStringValue(this SetDeviceStateRequest request, Device device, bool isHex = false) { int val = request.GetBriValue(device); return(isHex ? val.ToString("x8") : val.ToString()); }