private void ProcessUnitReceived(clsUnit unit, Topic command, string payload)
        {
            if (command == Topic.command && Enum.TryParse(payload, true, out UnitCommands cmd))
            {
                if (string.Compare(unit.ToState(), cmd.ToString()) != 0)
                {
                    log.Debug("SetUnit: {id} to {value}", unit.Number, cmd.ToString());
                    OmniLink.SendCommand(UnitMapping[cmd], 0, (ushort)unit.Number);
                }
            }
            else if (command == Topic.brightness_command && int.TryParse(payload, out int unitValue))
            {
                log.Debug("SetUnit: {id} to {value}%", unit.Number, payload);

                OmniLink.SendCommand(enuUnitCommand.Level, BitConverter.GetBytes(unitValue)[0], (ushort)unit.Number);

                // Force status change instead of waiting on controller to update
                // Home Assistant sends brightness immediately followed by ON,
                // which will cause light to go to 100% brightness
                unit.Status = (byte)(100 + unitValue);
            }
            else if (command == Topic.scene_command && char.TryParse(payload, out char scene))
            {
                log.Debug("SetUnit: {id} to {value}", unit.Number, payload);

                OmniLink.SendCommand(enuUnitCommand.Compose, (byte)(scene - 63), (ushort)unit.Number);
            }
        }
예제 #2
0
        private void ProcessUnitReceived(clsUnit unit, string command, string payload)
        {
            if (string.Compare(command, Topic.command.ToString()) == 0 && (payload == "ON" || payload == "OFF"))
            {
                if (unit.ToState() != payload)
                {
                    log.Debug("SetUnit: " + unit.Number + " to " + payload);

                    if (payload == "ON")
                    {
                        OmniLink.Controller.SendCommand(enuUnitCommand.On, 0, (ushort)unit.Number);
                    }
                    else
                    {
                        OmniLink.Controller.SendCommand(enuUnitCommand.Off, 0, (ushort)unit.Number);
                    }
                }
            }
            else if (string.Compare(command, Topic.brightness_command.ToString()) == 0 && Int32.TryParse(payload, out int unitValue))
            {
                log.Debug("SetUnit: " + unit.Number + " to " + payload + "%");

                OmniLink.Controller.SendCommand(enuUnitCommand.Level, BitConverter.GetBytes(unitValue)[0], (ushort)unit.Number);

                // Force status change instead of waiting on controller to update
                // Home Assistant sends brightness immediately followed by ON,
                // which will cause light to go to 100% brightness
                unit.Status = (byte)(100 + unitValue);
            }
        }
예제 #3
0
        private void PublishUnitState(clsUnit unit)
        {
            MqttClient.PublishAsync(unit.ToTopic(Topic.state), unit.ToState(), MqttQualityOfServiceLevel.AtMostOnce, true);

            if (unit.Number < 385)
            {
                MqttClient.PublishAsync(unit.ToTopic(Topic.brightness_state), unit.ToBrightnessState().ToString(), MqttQualityOfServiceLevel.AtMostOnce, true);
            }
        }
예제 #4
0
        private void PublishUnitState(clsUnit unit)
        {
            PublishAsync(unit.ToTopic(Topic.state), unit.ToState());

            if (unit.Number < 385)
            {
                PublishAsync(unit.ToTopic(Topic.brightness_state), unit.ToBrightnessState().ToString());
            }
        }