mirror of
https://github.com/excaliburpartners/OmniLinkBridge
synced 2024-12-22 10:42:24 +00:00
- Utilize controller temperature format
This commit is contained in:
parent
177dda4c1a
commit
151384c5b6
|
@ -208,13 +208,13 @@ namespace OmniLinkBridge.MQTT
|
|||
return $"{Global.mqtt_prefix}/zone{zone.Number.ToString()}/{topic.ToString()}";
|
||||
}
|
||||
|
||||
public static Sensor ToConfigTemp(this clsZone zone)
|
||||
public static Sensor ToConfigTemp(this clsZone zone, enuTempFormat format)
|
||||
{
|
||||
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";
|
||||
ret.unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -379,13 +379,13 @@ namespace OmniLinkBridge.MQTT
|
|||
return $"{Global.mqtt_prefix}/thermostat{thermostat.Number.ToString()}/{topic.ToString()}";
|
||||
}
|
||||
|
||||
public static Sensor ToConfigTemp(this clsThermostat zone)
|
||||
public static Sensor ToConfigTemp(this clsThermostat zone, enuTempFormat format)
|
||||
{
|
||||
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";
|
||||
ret.unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -399,9 +399,16 @@ namespace OmniLinkBridge.MQTT
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static Climate ToConfig(this clsThermostat thermostat)
|
||||
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.name = Global.mqtt_discovery_name_prefix + thermostat.Name;
|
||||
ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature);
|
||||
|
||||
|
|
|
@ -208,18 +208,33 @@ namespace OmniLinkBridge.Modules
|
|||
{
|
||||
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 + ")");
|
||||
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.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 + ")");
|
||||
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.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))
|
||||
{
|
||||
// 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.Controller.SendCommand(enuUnitCommand.SetHumidifySetPt, BitConverter.GetBytes(level)[0], (ushort)thermostat.Number);
|
||||
|
@ -350,7 +365,7 @@ namespace OmniLinkBridge.Modules
|
|||
|
||||
if (zone.IsTemperatureZone())
|
||||
MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}temp/config",
|
||||
JsonConvert.SerializeObject(zone.ToConfigTemp()), MqttQualityOfServiceLevel.AtMostOnce, true);
|
||||
JsonConvert.SerializeObject(zone.ToConfigTemp(OmniLink.Controller.TempFormat)), MqttQualityOfServiceLevel.AtMostOnce, true);
|
||||
else if (zone.IsHumidityZone())
|
||||
MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}humidity/config",
|
||||
JsonConvert.SerializeObject(zone.ToConfigHumidity()), MqttQualityOfServiceLevel.AtMostOnce, true);
|
||||
|
@ -402,9 +417,9 @@ namespace OmniLinkBridge.Modules
|
|||
PublishThermostatState(thermostat);
|
||||
|
||||
MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i.ToString()}/config",
|
||||
JsonConvert.SerializeObject(thermostat.ToConfig()), MqttQualityOfServiceLevel.AtMostOnce, true);
|
||||
JsonConvert.SerializeObject(thermostat.ToConfig(OmniLink.Controller.TempFormat)), 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);
|
||||
JsonConvert.SerializeObject(thermostat.ToConfigTemp(OmniLink.Controller.TempFormat)), 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);
|
||||
}
|
||||
|
|
|
@ -335,6 +335,7 @@ namespace OmniLinkBridge.Modules
|
|||
{
|
||||
log.Debug("Retrieving named units");
|
||||
|
||||
await GetSystemFormats();
|
||||
await GetNamed(enuObjectType.Area);
|
||||
await GetNamed(enuObjectType.Zone);
|
||||
await GetNamed(enuObjectType.Thermostat);
|
||||
|
@ -343,13 +344,27 @@ namespace OmniLinkBridge.Modules
|
|||
await GetNamed(enuObjectType.Button);
|
||||
}
|
||||
|
||||
private async Task GetSystemFormats()
|
||||
{
|
||||
log.Debug("Waiting for system formats");
|
||||
|
||||
clsOL2MsgRequestSystemFormats MSG = new clsOL2MsgRequestSystemFormats(Controller.Connection);
|
||||
Controller.Connection.Send(MSG, HandleNamedPropertiesResponse);
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
nameWait.WaitOne(new TimeSpan(0, 0, 10));
|
||||
});
|
||||
}
|
||||
|
||||
private async Task GetNamed(enuObjectType type)
|
||||
{
|
||||
log.Debug("Waiting for named units " + type.ToString());
|
||||
|
||||
GetNextNamed(type, 0);
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
log.Debug("Waiting for named units " + type.ToString());
|
||||
nameWait.WaitOne(new TimeSpan(0, 0, 10));
|
||||
});
|
||||
}
|
||||
|
@ -379,8 +394,18 @@ namespace OmniLinkBridge.Modules
|
|||
case enuOmniLink2MessageType.EOD:
|
||||
nameWait.Set();
|
||||
break;
|
||||
case enuOmniLink2MessageType.Properties:
|
||||
case enuOmniLink2MessageType.SystemFormats:
|
||||
clsOL2MsgSystemFormats MSG2 = new clsOL2MsgSystemFormats(Controller.Connection, B);
|
||||
|
||||
Controller.DateFormat = MSG2.Date;
|
||||
Controller.TimeFormat = MSG2.Time;
|
||||
Controller.TempFormat = MSG2.Temp;
|
||||
|
||||
log.Debug("Temperature format: " + (Controller.TempFormat == enuTempFormat.Fahrenheit ? "Fahrenheit" : "Celsius"));
|
||||
|
||||
nameWait.Set();
|
||||
break;
|
||||
case enuOmniLink2MessageType.Properties:
|
||||
clsOL2MsgProperties MSG = new clsOL2MsgProperties(Controller.Connection, B);
|
||||
|
||||
switch (MSG.ObjectType)
|
||||
|
|
|
@ -43,7 +43,11 @@ namespace OmniLinkBridge.WebAPI
|
|||
ret.zonetype = zone.ZoneType;
|
||||
ret.name = zone.Name;
|
||||
ret.status = zone.StatusText();
|
||||
ret.temp = zone.TempText();
|
||||
|
||||
if (zone.IsTemperatureZone())
|
||||
ret.temp = zone.TempText();
|
||||
else if(zone.IsHumidityZone())
|
||||
ret.temp = zone.TempText();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -225,15 +225,31 @@ namespace OmniLinkBridge.WebAPI
|
|||
|
||||
public void SetThermostatCoolSetpoint(CommandContract unit)
|
||||
{
|
||||
int temp = ((double)unit.value).ToCelsius().ToOmniTemp();
|
||||
log.Debug("SetThermostatCoolSetpoint: " + unit.id + " to " + unit.value + "F (" + temp + ")");
|
||||
double tempHigh = unit.value;
|
||||
string tempUnit = "C";
|
||||
if (WebServiceModule.OmniLink.Controller.TempFormat == enuTempFormat.Fahrenheit)
|
||||
{
|
||||
tempHigh = tempHigh.ToCelsius();
|
||||
tempUnit = "F";
|
||||
}
|
||||
|
||||
int temp = tempHigh.ToOmniTemp();
|
||||
log.Debug("SetThermostatCoolSetpoint: " + unit.id + " to " + unit.value + tempUnit + "(" + temp + ")");
|
||||
WebServiceModule.OmniLink.Controller.SendCommand(enuUnitCommand.SetHighSetPt, BitConverter.GetBytes(temp)[0], unit.id);
|
||||
}
|
||||
|
||||
public void SetThermostatHeatSetpoint(CommandContract unit)
|
||||
{
|
||||
int temp = ((double)unit.value).ToCelsius().ToOmniTemp();
|
||||
log.Debug("SetThermostatCoolSetpoint: " + unit.id + " to " + unit.value + "F (" + temp + ")");
|
||||
double tempLoad = unit.value;
|
||||
string tempUnit = "C";
|
||||
if (WebServiceModule.OmniLink.Controller.TempFormat == enuTempFormat.Fahrenheit)
|
||||
{
|
||||
tempLoad = tempLoad.ToCelsius();
|
||||
tempUnit = "F";
|
||||
}
|
||||
|
||||
int temp = tempLoad.ToOmniTemp();
|
||||
log.Debug("SetThermostatHeatSetpoint: " + unit.id + " to " + unit.value + tempUnit + "(" + temp + ")");
|
||||
WebServiceModule.OmniLink.Controller.SendCommand(enuUnitCommand.SetLowSetPt, BitConverter.GetBytes(temp)[0], unit.id);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue