Example #1
0
        protected override IDeviceEvent CreateDeviceEvent()
        {
            var state = GetValue();

            if (state == true)
            {
                return(DeviceEvent.PoweredOn(Device, null));
            }

            if (state == false)
            {
                return(DeviceEvent.PoweredOff(Device, null));
            }

            return(DeviceEvent.PowerChanged(Device, null));
        }
Example #2
0
        protected void PowerChanged()
        {
            //TODO: improve this logic
            //TODO: read from event history in making powered on/off decision
            IDeviceEvent @event = null;
            IEventSource source = null; //TODO: fill this in

            if (IsConnected == true)
            {
                if (Type.Equals(DeviceType.BinarySensor))
                {
                    @event = DeviceEvent.BinarySensorValueChanged(this, source);
                }
                else if (Type.Equals(DeviceType.BinarySwitch))
                {
                    switch (BinarySwitch.Power)
                    {
                    case BinarySwitchPower.On:
                        @event = DeviceEvent.PoweredOn(this, source);
                        break;

                    case BinarySwitchPower.Off:
                        @event = DeviceEvent.PoweredOff(this, source);
                        break;
                    }
                }
            }
            else
            {
                @event = DeviceEvent.Lost(this, source);
            }

            if (@event == null)
            {
                @event = DeviceEvent.PowerChanged(this, source);
            }

            AddEvent(@event);
        }