Beispiel #1
0
        protected async Task Handle(TurnOffCommand message)
        {
            var cmd = GetControlCommand("AAAAAQAAAAEAAAAvAw==");
            await MessageBroker.QueryService <SonyControlQuery, string>(cmd);

            _powerState = await UpdateState(PowerState.StateName, _powerState, false);
        }
Beispiel #2
0
        protected async Task Handle(TurnOffCommand message)
        {
            var cmd = GetCommand("KEY_POWEROFF");
            await MessageBroker.SendToService(cmd).ConfigureAwait(false);

            _powerState = await UpdateState(PowerState.StateName, _powerState, false).ConfigureAwait(false);
        }
Beispiel #3
0
        protected void Handle(TurnOffCommand command)
        {
            var pin     = command.AsInt(MessageProperties.PinNumber);
            var reverse = command.AsBool(MessageProperties.ReversePinLevel);

            _gpioDevice.Write(pin, reverse);
        }
Beispiel #4
0
        protected async Task Handle(TurnOffCommand message)
        {
            var cmd    = GetKodiCommand("Application.Quit");
            var result = await MessageBroker.QueryService <KodiCommand, JsonRpcResponse>(cmd).ConfigureAwait(false);

            _powerState = await UpdateState(PowerState.StateName, _powerState, false).ConfigureAwait(false);
        }
Beispiel #5
0
        private void OnMessageReceived(object sender, DeviceMessageReceivedEventArgs e)
        {
            try
            {
                IComponent component = null;
                if (e.Message.Topic == "garden_controller/$PATCH/socket.pavillion")
                {
                    component = _area.GetComponent(Garden.SocketPavillion);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.rear_area")
                {
                    component = _area.GetComponent(Garden.LampRearArea);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.roof")
                {
                    component = _area.GetComponent(Garden.SpotlightRoof);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.tap")
                {
                    component = _area.GetComponent(Garden.LampTap);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.garage")
                {
                    component = _area.GetComponent(Garden.LampGarage);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.terrace")
                {
                    component = _area.GetComponent(Garden.LampTerrace);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.parking_lot")
                {
                    component = _area.GetComponent(Garden.LampParkingLot);
                }

                if (component == null)
                {
                    return;
                }

                var status = Encoding.UTF8.GetString(e.Message.Payload ?? new byte[0]);

                ICommand command = new TurnOffCommand();

                if (status == "on")
                {
                    command = new TurnOnCommand();
                }
                else if (status == "toggle")
                {
                    command = new TogglePowerStateCommand();
                }

                component.ExecuteCommand(command);
            }
            catch (Exception exception)
            {
                Log.Default.Error(exception, "Errow while patching state.");
            }
        }
Beispiel #6
0
        protected async Task TurnOff(TurnOffCommand message)
        {
            byte[] package = PreparePackage(message, nameof(RemoteSocketCommand.TurnOff), out var dipswitchCode);
            var    cmd     = I2cCommand.Create(_I2cAddress, package);
            await MessageBroker.SendToService(cmd);

            await UpdateState(dipswitchCode);
        }
        protected async Task Handle(TurnOffCommand turnOnCommand)
        {
            if (_PowerLevel == 0)
            {
                return;
            }

            await ChangePowerState();
        }
Beispiel #8
0
        /* Classe de test  */
        static void Main(string[] args)
        {
            Light   lamp       = new Light();
            Command switchUp   = new TurnOnCommand(lamp);
            Command switchDown = new TurnOffCommand(lamp);

            Switch s = new Switch(switchUp, switchDown);

            s.flipUp();
            s.flipDown();
        }
Beispiel #9
0
        protected async Task Handle(TurnOffCommand message)
        {
            var cmd = new ComputerCommand
            {
                Address = _hostname,
                Service = "Power",
                Message = new PowerPost {
                    State = 0
                }                                     //Hibernate
            };
            await MessageBroker.SendToService(cmd).ConfigureAwait(false);

            _powerState = await UpdateState(PowerState.StateName, _powerState, false).ConfigureAwait(false);
        }
Beispiel #10
0
        protected async Task Handle(TurnOffCommand message)
        {
            var control = new DenonControlQuery
            {
                Command    = "PowerStandby",
                Api        = "formiPhoneAppPower",
                ReturnNode = "Power",
                Address    = _hostName,
                Zone       = _zone.ToString()
            };

            if (await MessageBroker.QueryServiceWithVerify <DenonControlQuery, string, object>(control, "OFF").ConfigureAwait(false))
            {
                _powerState = await UpdateState(PowerState.StateName, _powerState, false).ConfigureAwait(false);
            }
        }
Beispiel #11
0
        public override Task RunTask(int taskId)
        {
            Command cmd = null;

            switch (taskId)
            {
            case 0:
                cmd = new TurnOnCommand();
                break;

            case 1:
                cmd = new TurnOffCommand();

                break;

            case 2:
                cmd = new TurnOnCommand();

                ConsoleEx.WriteTitleLine("State Time:");
                var time = ConsoleEx.ReadNumber();
                cmd.SetProperty(MessageProperties.StateTime, time);

                break;

            case 3:
                ConsoleEx.WriteTitleLine("Enter dimmer level [0-100]:");
                var level = ConsoleEx.ReadNumber();
                cmd = new SetPowerLevelCommand();
                ((SetPowerLevelCommand)cmd).PowerLevel = level;
                break;

            case 4:
                ConsoleEx.WriteTitleLine("Adjust Power Level [0-100]:");
                var delta = ConsoleEx.ReadNumber();
                cmd = new AdjustPowerLevelCommand();
                ((AdjustPowerLevelCommand)cmd).Delta = delta;
                break;
            }

            MessageBroker.Send(cmd, Uid);

            return(Task.CompletedTask);
        }
Beispiel #12
0
        public override Task RunTask(int taskId)
        {
            if (!pinNumber.HasValue)
            {
                ConsoleEx.WriteWarning("Write PIN number:");
                pinNumber = int.Parse(Console.ReadLine());
            }

            Command cmd = null;

            switch (taskId)
            {
            case 0:
                cmd = new TurnOnCommand();
                break;

            case 1:
                cmd = new TurnOffCommand();
                break;

            case 2:
                cmd          = new RefreshCommand();
                cmd.LogLevel = nameof(Microsoft.Extensions.Logging.LogLevel.Information);
                break;

            case 3:
                cmd = new SwitchPowerStateCommand();
                break;
            }

            if (pinNumber.HasValue && pinNumber.Value < 10)
            {
                cmd.SetProperty(MessageProperties.PinNumber, pinNumber.Value);
            }

            MessageBroker.Send(cmd, Uid);

            return(Task.CompletedTask);
        }
 public virtual void TurnOffHandler(TurnOffCommand command)
 {
     this.TurnOff(command.Sender as PlayerViewModel);
 }
 public virtual void ExecuteTurnOff(TurnOffCommand command)
 {
     command.Sender = Player;
     Player.TurnOff.OnNext(command);
 }
        public override async Task RunTask(int taskId)
        {
            if (!pinNumber.HasValue)
            {
                ConsoleEx.WriteWarning("Write PIN number:");
                pinNumber = int.Parse(Console.ReadLine());
            }

            Command cmd = null;

            switch (taskId)
            {
            case 0:
                cmd = new TurnOnCommand();
                break;

            case 1:
                cmd = new TurnOffCommand();
                break;

            case 2:
                cmd          = new RefreshCommand();
                cmd.LogLevel = nameof(Microsoft.Extensions.Logging.LogLevel.Information);
                break;

            case 3:
                cmd = new SwitchPowerStateCommand();
                break;

            case 4:
                var inputUid           = "HSPE16InputOnly_2";
                var properyChangeEvent = PropertyChangedEvent.Create(inputUid, PowerState.StateName, false, true, new Dictionary <string, string>()
                {
                    [MessageProperties.PinNumber] = 0.ToString()
                });

                await MessageBroker.Publish(properyChangeEvent, inputUid);

                return;

            case 5:
                var inputUid2           = "HSPE16InputOnly_2";
                var properyChangeEvent2 = PropertyChangedEvent.Create(inputUid2, PowerState.StateName, true, false, new Dictionary <string, string>()
                {
                    [MessageProperties.PinNumber] = 0.ToString()
                });

                await MessageBroker.Publish(properyChangeEvent2, inputUid2);

                return;
            }

            if (pinNumber.HasValue && pinNumber.Value < 10)
            {
                cmd.SetProperty(MessageProperties.PinNumber, pinNumber.Value);
            }

            MessageBroker.Send(cmd, Uid);

            //return Task.CompletedTask;
        }
Beispiel #16
0
        protected Task Handle(TurnOffCommand message)
        {
            int pinNumber = ValidatePin(message);

            return(SetPortState(pinNumber, false));
        }
Beispiel #17
0
        private void TurnOff()
        {
            TurnOffCommand cmd = new TurnOffCommand(SelectedConsumer);

            cmd.Execute();
        }
Beispiel #18
0
        private void InitializeStateMachine(StateMachine stateMachine, IArea garden)
        {
            var turnOffCommand = new TurnOffCommand();
            var turnOnCommand  = new TurnOnCommand();

            stateMachine.ResetStateId = StateMachineStateExtensions.OffStateId;

            stateMachine.AddOffState()
            .WithCommand(garden.GetComponent(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("Te")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("G")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("W")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("D")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("Ti")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOnCommand);

            stateMachine.AddState("G+W")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("Te+G+W")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddOnState()
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOnCommand);
        }