private void HandleEvent(AbstractSwitchEvent switchEvent)
        {
            Guard.DebugAssertArgumentNotNull(switchEvent, nameof(switchEvent));

            if (!_switchController.CanHandleSwitch(switchEvent.SwitchId))
            {
                _log.Debug("Switch not supported: {SwitchId}", switchEvent.SwitchId);
                return;
            }

            if (switchEvent is TurnOnEvent)
            {
                _switchController.TurnOn(switchEvent.SwitchId);
                _log.Information("Switch turned on: {SwitchId}", switchEvent.SwitchId);
            }
            else if (switchEvent is TurnOffEvent)
            {
                _switchController.TurnOff(switchEvent.SwitchId);
                _log.Information("Switch turned off: {SwitchId}", switchEvent.SwitchId);
            }
            else if (switchEvent is SetPowerEvent setPower)
            {
                _switchController.SetPower(switchEvent.SwitchId, setPower.Power);
                _log.Information("Adjusted switch power: {SwitchId}, {Power:G}", setPower.SwitchId, setPower.Power);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
        public void Test_WhenUnknownSwitch_ThenDoNothing(AbstractSwitchEvent @event)
        {
            var switchControllerMock = new Mock <ISwitchController>(MockBehavior.Strict);

            switchControllerMock.Setup(cntr => cntr.CanHandleSwitch(It.IsAny <SwitchId>())).Returns(false);
            var eventsSourceMock = new Mock <IEventSource>(MockBehavior.Strict);

            eventsSourceMock.Setup(e => e.ReceiveEvents <AbstractSwitchEvent>()).Returns(Observable.Repeat(@event, 1));

            var handler = new SwitchEventsProcessor(switchControllerMock.Object, eventsSourceMock.Object, Mock.Of <ILogger>());

            handler.Run(CancellationToken.None);

            switchControllerMock.Verify(sc => sc.CanHandleSwitch(@event.SwitchId), Times.Once);
            switchControllerMock.Verify(sc => sc.SetPower(It.IsAny <SwitchId>(), It.IsAny <double>()), Times.Never);
            switchControllerMock.Verify(sc => sc.TurnOff(It.IsAny <SwitchId>()), Times.Never);
            switchControllerMock.Verify(sc => sc.TurnOn(It.IsAny <SwitchId>()), Times.Never);
        }
        protected override bool GetValueFromEvent(AbstractSwitchEvent e)
        {
            if (e.SwitchId != Id)
            {
                return(Value);
            }

            if (e is TurnOffEvent)
            {
                return(false);
            }

            if (e is TurnOnEvent)
            {
                return(true);
            }

            if (e is SetPowerEvent powerEvent)
            {
                return(powerEvent.Power >= 0.5);
            }

            throw new ArgumentOutOfRangeException(nameof(e));
        }
        protected override double GetValueFromEvent(AbstractSwitchEvent e)
        {
            if (e.SwitchId != Id)
            {
                return(Value);
            }

            if (e is TurnOffEvent)
            {
                return(SetPowerEvent.MinPower);
            }

            if (e is TurnOnEvent)
            {
                return(SetPowerEvent.MaxPower);
            }

            if (e is SetPowerEvent powerEvent)
            {
                return(powerEvent.Power);
            }

            throw new ArgumentOutOfRangeException(nameof(e));
        }