コード例 #1
0
        public static Climate ToConfig(this clsThermostat thermostat, enuTempFormat format)
        {
            Climate ret = new Climate();

            if (format == enuTempFormat.Celsius)
            {
                ret.min_temp = "7";
                ret.max_temp = "35";
            }

            ret.unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number.ToString()}";
            ret.name      = Global.mqtt_discovery_name_prefix + thermostat.Name;
            ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature);

            ret.temperature_low_state_topic   = thermostat.ToTopic(Topic.temperature_heat_state);
            ret.temperature_low_command_topic = thermostat.ToTopic(Topic.temperature_heat_command);

            ret.temperature_high_state_topic   = thermostat.ToTopic(Topic.temperature_cool_state);
            ret.temperature_high_command_topic = thermostat.ToTopic(Topic.temperature_cool_command);

            ret.mode_state_topic   = thermostat.ToTopic(Topic.mode_state);
            ret.mode_command_topic = thermostat.ToTopic(Topic.mode_command);

            ret.fan_mode_state_topic   = thermostat.ToTopic(Topic.fan_mode_state);
            ret.fan_mode_command_topic = thermostat.ToTopic(Topic.fan_mode_command);

            ret.hold_state_topic   = thermostat.ToTopic(Topic.hold_state);
            ret.hold_command_topic = thermostat.ToTopic(Topic.hold_command);
            return(ret);
        }
コード例 #2
0
ファイル: MQTTModule.cs プロジェクト: rcjacoby/OmniLinkBridge
        private void PublishThermostats()
        {
            log.Debug("Publishing {type}", "thermostats");

            for (ushort i = 1; i <= OmniLink.Controller.Thermostats.Count; i++)
            {
                clsThermostat thermostat = OmniLink.Controller.Thermostats[i];

                if (thermostat.DefaultProperties == true)
                {
                    PublishAsync(thermostat.ToTopic(Topic.name), null);
                    PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i}/config", null);
                    PublishAsync($"{Global.mqtt_discovery_prefix}/number/{Global.mqtt_prefix}/thermostat{i}humidify/config", null);
                    PublishAsync($"{Global.mqtt_discovery_prefix}/number/{Global.mqtt_prefix}/thermostat{i}dehumidify/config", null);
                    PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}temp/config", null);
                    PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}humidity/config", null);
                    continue;
                }

                PublishThermostatState(thermostat);

                PublishAsync(thermostat.ToTopic(Topic.name), thermostat.Name);
                PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i}/config",
                             JsonConvert.SerializeObject(thermostat.ToConfig(OmniLink.Controller.TempFormat)));
                PublishAsync($"{Global.mqtt_discovery_prefix}/number/{Global.mqtt_prefix}/thermostat{i}humidify/config",
                             JsonConvert.SerializeObject(thermostat.ToConfigHumidify()));
                PublishAsync($"{Global.mqtt_discovery_prefix}/number/{Global.mqtt_prefix}/thermostat{i}dehumidify/config",
                             JsonConvert.SerializeObject(thermostat.ToConfigDehumidify()));
                PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}temp/config",
                             JsonConvert.SerializeObject(thermostat.ToConfigTemp(OmniLink.Controller.TempFormat)));
                PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}humidity/config",
                             JsonConvert.SerializeObject(thermostat.ToConfigHumidity()));
            }
        }
コード例 #3
0
        private void PublishThermostats()
        {
            log.Debug("Publishing thermostats");

            for (ushort i = 1; i < OmniLink.Controller.Thermostats.Count; i++)
            {
                clsThermostat thermostat = OmniLink.Controller.Thermostats[i];

                if (thermostat.DefaultProperties == true)
                {
                    MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i.ToString()}/config", null, MqttQualityOfServiceLevel.AtMostOnce, true);
                    MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i.ToString()}temp/config", null, MqttQualityOfServiceLevel.AtMostOnce, true);
                    MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i.ToString()}humidity/config", null, MqttQualityOfServiceLevel.AtMostOnce, true);
                    continue;
                }

                PublishThermostatState(thermostat);

                MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i.ToString()}/config",
                                        JsonConvert.SerializeObject(thermostat.ToConfig()), MqttQualityOfServiceLevel.AtMostOnce, true);
                MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i.ToString()}temp/config",
                                        JsonConvert.SerializeObject(thermostat.ToConfigTemp()), MqttQualityOfServiceLevel.AtMostOnce, true);
                MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i.ToString()}humidity/config",
                                        JsonConvert.SerializeObject(thermostat.ToConfigHumidity()), MqttQualityOfServiceLevel.AtMostOnce, true);
            }
        }
コード例 #4
0
        private void ProcessThermostatReceived(clsThermostat thermostat, Topic command, string payload)
        {
            if (command == Topic.temperature_heat_command && double.TryParse(payload, out double tempLow))
            {
                string tempUnit = "C";
                if (OmniLink.Controller.TempFormat == enuTempFormat.Fahrenheit)
                {
                    tempLow  = tempLow.ToCelsius();
                    tempUnit = "F";
                }

                int temp = tempLow.ToOmniTemp();
                log.Debug("SetThermostatHeatSetpoint: " + thermostat.Number + " to " + payload + tempUnit + "(" + temp + ")");
                OmniLink.SendCommand(enuUnitCommand.SetLowSetPt, BitConverter.GetBytes(temp)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.temperature_cool_command && double.TryParse(payload, out double tempHigh))
            {
                string tempUnit = "C";
                if (OmniLink.Controller.TempFormat == enuTempFormat.Fahrenheit)
                {
                    tempHigh = tempHigh.ToCelsius();
                    tempUnit = "F";
                }

                int temp = tempHigh.ToOmniTemp();
                log.Debug("SetThermostatCoolSetpoint: " + thermostat.Number + " to " + payload + tempUnit + "(" + temp + ")");
                OmniLink.SendCommand(enuUnitCommand.SetHighSetPt, BitConverter.GetBytes(temp)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.humidify_command && double.TryParse(payload, out double humidify))
            {
                // Humidity is reported where Fahrenheit temperatures 0-100 correspond to 0-100% relative humidity
                int level = humidify.ToCelsius().ToOmniTemp();
                log.Debug("SetThermostatHumidifySetpoint: " + thermostat.Number + " to " + payload + "% (" + level + ")");
                OmniLink.SendCommand(enuUnitCommand.SetHumidifySetPt, BitConverter.GetBytes(level)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.dehumidify_command && double.TryParse(payload, out double dehumidify))
            {
                int level = dehumidify.ToCelsius().ToOmniTemp();
                log.Debug("SetThermostatDehumidifySetpoint: " + thermostat.Number + " to " + payload + "% (" + level + ")");
                OmniLink.SendCommand(enuUnitCommand.SetDeHumidifySetPt, BitConverter.GetBytes(level)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.mode_command && Enum.TryParse(payload, true, out enuThermostatMode mode))
            {
                log.Debug("SetThermostatMode: " + thermostat.Number + " to " + payload);
                OmniLink.SendCommand(enuUnitCommand.Mode, BitConverter.GetBytes((int)mode)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.fan_mode_command && Enum.TryParse(payload, true, out enuThermostatFanMode fanMode))
            {
                log.Debug("SetThermostatFanMode: " + thermostat.Number + " to " + payload);
                OmniLink.SendCommand(enuUnitCommand.Fan, BitConverter.GetBytes((int)fanMode)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.hold_command && Enum.TryParse(payload, true, out enuThermostatHoldMode holdMode))
            {
                log.Debug("SetThermostatHold: " + thermostat.Number + " to " + payload);
                OmniLink.SendCommand(enuUnitCommand.Hold, BitConverter.GetBytes((int)holdMode)[0], (ushort)thermostat.Number);
            }
        }
コード例 #5
0
        public static Sensor ToConfigHumidity(this clsThermostat zone)
        {
            Sensor ret = new Sensor();

            ret.name                = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Humidity";
            ret.device_class        = Sensor.DeviceClass.humidity;
            ret.state_topic         = zone.ToTopic(Topic.current_humidity);
            ret.unit_of_measurement = "%";
            return(ret);
        }
コード例 #6
0
        public static Sensor ToConfigTemp(this clsThermostat zone)
        {
            Sensor ret = new Sensor();

            ret.name                = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Temp";
            ret.device_class        = Sensor.DeviceClass.temperature;
            ret.state_topic         = zone.ToTopic(Topic.current_temperature);
            ret.unit_of_measurement = "°F";
            return(ret);
        }
コード例 #7
0
        public static Sensor ToConfigHumidity(this clsThermostat thermostat)
        {
            Sensor ret = new Sensor();

            ret.unique_id           = $"{Global.mqtt_prefix}thermostat{thermostat.Number.ToString()}humidity";
            ret.name                = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Humidity";
            ret.device_class        = Sensor.DeviceClass.humidity;
            ret.state_topic         = thermostat.ToTopic(Topic.current_humidity);
            ret.unit_of_measurement = "%";
            return(ret);
        }
コード例 #8
0
        public static Sensor ToConfigTemp(this clsThermostat thermostat, enuTempFormat format)
        {
            Sensor ret = new Sensor();

            ret.unique_id           = $"{Global.mqtt_prefix}thermostat{thermostat.Number.ToString()}temp";
            ret.name                = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Temp";
            ret.device_class        = Sensor.DeviceClass.temperature;
            ret.state_topic         = thermostat.ToTopic(Topic.current_temperature);
            ret.unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C");
            return(ret);
        }
コード例 #9
0
ファイル: HAIService.cs プロジェクト: mikec85/HAILogger
        public ThermostatContract GetThermostat(ushort id)
        {
            Event.WriteVerbose("WebService", "GetThermostat: " + id);

            WebOperationContext ctx = WebOperationContext.Current;

            ctx.OutgoingResponse.Headers.Add("type", "thermostat");

            clsThermostat unit = WebService.HAC.Thermostats[id];

            return(Helper.ConvertThermostat(id, unit));
        }
コード例 #10
0
 private void PublishThermostatState(clsThermostat thermostat)
 {
     PublishAsync(thermostat.ToTopic(Topic.current_operation), thermostat.ToOperationState());
     PublishAsync(thermostat.ToTopic(Topic.current_temperature), thermostat.TempText());
     PublishAsync(thermostat.ToTopic(Topic.current_humidity), thermostat.HumidityText());
     PublishAsync(thermostat.ToTopic(Topic.temperature_heat_state), thermostat.HeatSetpointText());
     PublishAsync(thermostat.ToTopic(Topic.temperature_cool_state), thermostat.CoolSetpointText());
     PublishAsync(thermostat.ToTopic(Topic.humidify_state), thermostat.HumidifySetpointText());
     PublishAsync(thermostat.ToTopic(Topic.dehumidify_state), thermostat.DehumidifySetpointText());
     PublishAsync(thermostat.ToTopic(Topic.mode_state), thermostat.ModeText().ToLower());
     PublishAsync(thermostat.ToTopic(Topic.fan_mode_state), thermostat.FanModeText().ToLower());
     PublishAsync(thermostat.ToTopic(Topic.hold_state), thermostat.HoldStatusText().ToLower());
 }
コード例 #11
0
 private void PublishThermostatState(clsThermostat thermostat)
 {
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.current_operation), thermostat.ToOperationState(), MqttQualityOfServiceLevel.AtMostOnce, true);
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.current_temperature), thermostat.TempText(), MqttQualityOfServiceLevel.AtMostOnce, true);
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.current_humidity), thermostat.HumidityText(), MqttQualityOfServiceLevel.AtMostOnce, true);
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.temperature_heat_state), thermostat.HeatSetpointText(), MqttQualityOfServiceLevel.AtMostOnce, true);
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.temperature_cool_state), thermostat.CoolSetpointText(), MqttQualityOfServiceLevel.AtMostOnce, true);
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.humidify_state), thermostat.HumidifySetpointText(), MqttQualityOfServiceLevel.AtMostOnce, true);
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.dehumidify_state), thermostat.DehumidifySetpointText(), MqttQualityOfServiceLevel.AtMostOnce, true);
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.mode_state), thermostat.ModeText().ToLower(), MqttQualityOfServiceLevel.AtMostOnce, true);
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.fan_mode_state), thermostat.FanModeText().ToLower(), MqttQualityOfServiceLevel.AtMostOnce, true);
     MqttClient.PublishAsync(thermostat.ToTopic(Topic.hold_state), thermostat.HoldStatusText().ToLower(), MqttQualityOfServiceLevel.AtMostOnce, true);
 }
コード例 #12
0
        public static string ToOperationState(this clsThermostat thermostat)
        {
            string status = thermostat.HorC_StatusText();

            if (status.Contains("COOLING"))
            {
                return("cool");
            }
            else if (status.Contains("HEATING"))
            {
                return("heat");
            }
            else
            {
                return("idle");
            }
        }
コード例 #13
0
 private void ProcessThermostatReceived(clsThermostat thermostat, string command, string payload)
 {
     if (string.Compare(command, Topic.temperature_heat_command.ToString()) == 0 && double.TryParse(payload, out double tempLow))
     {
         int temp = tempLow.ToCelsius().ToOmniTemp();
         log.Debug("SetThermostatHeatSetpoint: " + thermostat.Number + " to " + payload + "F (" + temp + ")");
         OmniLink.Controller.SendCommand(enuUnitCommand.SetLowSetPt, BitConverter.GetBytes(temp)[0], (ushort)thermostat.Number);
     }
     else if (string.Compare(command, Topic.temperature_cool_command.ToString()) == 0 && double.TryParse(payload, out double tempHigh))
     {
         int temp = tempHigh.ToCelsius().ToOmniTemp();
         log.Debug("SetThermostatCoolSetpoint: " + thermostat.Number + " to " + payload + "F (" + temp + ")");
         OmniLink.Controller.SendCommand(enuUnitCommand.SetHighSetPt, BitConverter.GetBytes(temp)[0], (ushort)thermostat.Number);
     }
     else if (string.Compare(command, Topic.humidify_command.ToString()) == 0 && double.TryParse(payload, out double humidify))
     {
         int level = humidify.ToCelsius().ToOmniTemp();
         log.Debug("SetThermostatHumidifySetpoint: " + thermostat.Number + " to " + payload + "% (" + level + ")");
         OmniLink.Controller.SendCommand(enuUnitCommand.SetHumidifySetPt, BitConverter.GetBytes(level)[0], (ushort)thermostat.Number);
     }
     else if (string.Compare(command, Topic.dehumidify_command.ToString()) == 0 && double.TryParse(payload, out double dehumidify))
     {
         int level = dehumidify.ToCelsius().ToOmniTemp();
         log.Debug("SetThermostatDehumidifySetpoint: " + thermostat.Number + " to " + payload + "% (" + level + ")");
         OmniLink.Controller.SendCommand(enuUnitCommand.SetDeHumidifySetPt, BitConverter.GetBytes(level)[0], (ushort)thermostat.Number);
     }
     else if (string.Compare(command, Topic.mode_command.ToString()) == 0 && Enum.TryParse(payload, true, out enuThermostatMode mode))
     {
         log.Debug("SetThermostatMode: " + thermostat.Number + " to " + payload);
         OmniLink.Controller.SendCommand(enuUnitCommand.Mode, BitConverter.GetBytes((int)mode)[0], (ushort)thermostat.Number);
     }
     else if (string.Compare(command, Topic.fan_mode_command.ToString()) == 0 && Enum.TryParse(payload, true, out enuThermostatFanMode fanMode))
     {
         log.Debug("SetThermostatFanMode: " + thermostat.Number + " to " + payload);
         OmniLink.Controller.SendCommand(enuUnitCommand.Fan, BitConverter.GetBytes((int)fanMode)[0], (ushort)thermostat.Number);
     }
     else if (string.Compare(command, Topic.hold_command.ToString()) == 0 && Enum.TryParse(payload, true, out enuThermostatHoldMode holdMode))
     {
         log.Debug("SetThermostatHold: " + thermostat.Number + " to " + payload);
         OmniLink.Controller.SendCommand(enuUnitCommand.Hold, BitConverter.GetBytes((int)holdMode)[0], (ushort)thermostat.Number);
     }
 }
コード例 #14
0
ファイル: HAIService.cs プロジェクト: mikec85/HAILogger
        public List <NameContract> ListThermostats()
        {
            Event.WriteVerbose("WebService", "ListThermostats");

            List <NameContract> names = new List <NameContract>();

            for (ushort i = 1; i < WebService.HAC.Thermostats.Count; i++)
            {
                clsThermostat unit = WebService.HAC.Thermostats[i];

                if (unit.DefaultProperties == false)
                {
                    names.Add(new NameContract()
                    {
                        id = i, name = unit.Name
                    });
                }
            }
            return(names);
        }
コード例 #15
0
        public List <NameContract> ListThermostats()
        {
            log.Debug("ListThermostats");

            List <NameContract> names = new List <NameContract>();

            for (ushort i = 1; i < WebServiceModule.OmniLink.Controller.Thermostats.Count; i++)
            {
                clsThermostat unit = WebServiceModule.OmniLink.Controller.Thermostats[i];

                if (unit.DefaultProperties == false)
                {
                    names.Add(new NameContract()
                    {
                        id = i, name = unit.Name
                    });
                }
            }
            return(names);
        }
コード例 #16
0
        public static ThermostatContract ToContract(this clsThermostat unit)
        {
            ThermostatContract ret = new ThermostatContract();

            ret.id   = (ushort)unit.Number;
            ret.name = unit.Name;

            ushort temp, heat, cool, humidity;

            ushort.TryParse(unit.TempText(), out temp);
            ushort.TryParse(unit.HeatSetpointText(), out heat);
            ushort.TryParse(unit.CoolSetpointText(), out cool);
            ushort.TryParse(unit.HumidityText(), out humidity);

            ret.temp         = temp;
            ret.humidity     = humidity;
            ret.heatsetpoint = heat;
            ret.coolsetpoint = cool;
            ret.mode         = unit.Mode;
            ret.fanmode      = unit.FanMode;
            ret.hold         = unit.HoldStatus;

            string status = unit.HorC_StatusText();

            if (status.Contains("COOLING"))
            {
                ret.status = "COOLING";
            }
            else if (status.Contains("HEATING"))
            {
                ret.status = "HEATING";
            }
            else
            {
                ret.status = "OFF";
            }

            return(ret);
        }
コード例 #17
0
        public static Climate ToConfig(this clsThermostat thermostat)
        {
            Climate ret = new Climate();

            ret.name = Global.mqtt_discovery_name_prefix + thermostat.Name;
            ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature);

            ret.temperature_low_state_topic   = thermostat.ToTopic(Topic.temperature_heat_state);
            ret.temperature_low_command_topic = thermostat.ToTopic(Topic.temperature_heat_command);

            ret.temperature_high_state_topic   = thermostat.ToTopic(Topic.temperature_cool_state);
            ret.temperature_high_command_topic = thermostat.ToTopic(Topic.temperature_cool_command);

            ret.mode_state_topic   = thermostat.ToTopic(Topic.mode_state);
            ret.mode_command_topic = thermostat.ToTopic(Topic.mode_command);

            ret.fan_mode_state_topic   = thermostat.ToTopic(Topic.fan_mode_state);
            ret.fan_mode_command_topic = thermostat.ToTopic(Topic.fan_mode_command);

            ret.hold_state_topic   = thermostat.ToTopic(Topic.hold_state);
            ret.hold_command_topic = thermostat.ToTopic(Topic.hold_command);
            return(ret);
        }
コード例 #18
0
        private void ProcessThermostatReceived(clsThermostat thermostat, Topic command, string payload)
        {
            if (command == Topic.temperature_heat_command && double.TryParse(payload, out double tempLow))
            {
                string tempUnit = "C";
                if (OmniLink.Controller.TempFormat == enuTempFormat.Fahrenheit)
                {
                    tempLow  = tempLow.ToCelsius();
                    tempUnit = "F";
                }

                int temp = tempLow.ToOmniTemp();
                log.Debug("SetThermostatHeatSetpoint: {id} to {value}{temperatureUnit} ({temp})",
                          thermostat.Number, payload, tempUnit, temp);
                OmniLink.SendCommand(enuUnitCommand.SetLowSetPt, BitConverter.GetBytes(temp)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.temperature_cool_command && double.TryParse(payload, out double tempHigh))
            {
                string tempUnit = "C";
                if (OmniLink.Controller.TempFormat == enuTempFormat.Fahrenheit)
                {
                    tempHigh = tempHigh.ToCelsius();
                    tempUnit = "F";
                }

                int temp = tempHigh.ToOmniTemp();
                log.Debug("SetThermostatCoolSetpoint: {id} to {value}{temperatureUnit} ({temp})",
                          thermostat.Number, payload, tempUnit, temp);
                OmniLink.SendCommand(enuUnitCommand.SetHighSetPt, BitConverter.GetBytes(temp)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.humidify_command && double.TryParse(payload, out double humidify))
            {
                // Humidity is reported where Fahrenheit temperatures 0-100 correspond to 0-100% relative humidity
                int level = humidify.ToCelsius().ToOmniTemp();
                log.Debug("SetThermostatHumidifySetpoint: {id} to {value}% ({level})", thermostat.Number, payload, level);
                OmniLink.SendCommand(enuUnitCommand.SetHumidifySetPt, BitConverter.GetBytes(level)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.dehumidify_command && double.TryParse(payload, out double dehumidify))
            {
                int level = dehumidify.ToCelsius().ToOmniTemp();
                log.Debug("SetThermostatDehumidifySetpoint: {id} to {value}% ({level})", thermostat.Number, payload, level);
                OmniLink.SendCommand(enuUnitCommand.SetDeHumidifySetPt, BitConverter.GetBytes(level)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.mode_command && Enum.TryParse(payload, true, out enuThermostatMode mode))
            {
                if (thermostat.Type == enuThermostatType.AutoHeatCool ||
                    (thermostat.Type == enuThermostatType.HeatCool && mode != enuThermostatMode.Auto) ||
                    (thermostat.Type == enuThermostatType.CoolOnly &&
                     (mode == enuThermostatMode.Off || mode == enuThermostatMode.Cool)) ||
                    (thermostat.Type == enuThermostatType.HeatOnly &&
                     (mode == enuThermostatMode.Off || mode == enuThermostatMode.Heat || mode == enuThermostatMode.E_Heat)) ||
                    mode == enuThermostatMode.Off)
                {
                    log.Debug("SetThermostatMode: {id} to {value}", thermostat.Number, payload);
                    OmniLink.SendCommand(enuUnitCommand.Mode, BitConverter.GetBytes((int)mode)[0], (ushort)thermostat.Number);
                }
            }
            else if (command == Topic.fan_mode_command && Enum.TryParse(payload, true, out enuThermostatFanMode fanMode))
            {
                log.Debug("SetThermostatFanMode: {id} to {value}", thermostat.Number, payload);
                OmniLink.SendCommand(enuUnitCommand.Fan, BitConverter.GetBytes((int)fanMode)[0], (ushort)thermostat.Number);
            }
            else if (command == Topic.hold_command && Enum.TryParse(payload, true, out enuThermostatHoldMode holdMode))
            {
                log.Debug("SetThermostatHold: {id} to {value}", thermostat.Number, payload);
                OmniLink.SendCommand(enuUnitCommand.Hold, BitConverter.GetBytes((int)holdMode)[0], (ushort)thermostat.Number);
            }
        }
コード例 #19
0
 public static string ToTopic(this clsThermostat thermostat, Topic topic)
 {
     return($"{Global.mqtt_prefix}/thermostat{thermostat.Number.ToString()}/{topic.ToString()}");
 }