Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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;
     //}
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public static string GetBriStringValue(this SetDeviceStateRequest request, Device device, bool isHex = false)
        {
            int val = request.GetBriValue(device);

            return(isHex ? val.ToString("x8") : val.ToString());
        }