- Utilize controller temperature format

This commit is contained in:
Ryan Wagoner 2019-10-27 20:19:44 -04:00
parent 177dda4c1a
commit 151384c5b6
5 changed files with 86 additions and 19 deletions

View file

@ -208,13 +208,13 @@ namespace OmniLinkBridge.MQTT
return $"{Global.mqtt_prefix}/zone{zone.Number.ToString()}/{topic.ToString()}"; 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(); Sensor ret = new Sensor();
ret.name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Temp"; ret.name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Temp";
ret.device_class = Sensor.DeviceClass.temperature; ret.device_class = Sensor.DeviceClass.temperature;
ret.state_topic = zone.ToTopic(Topic.current_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; return ret;
} }
@ -379,13 +379,13 @@ namespace OmniLinkBridge.MQTT
return $"{Global.mqtt_prefix}/thermostat{thermostat.Number.ToString()}/{topic.ToString()}"; 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(); Sensor ret = new Sensor();
ret.name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Temp"; ret.name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Temp";
ret.device_class = Sensor.DeviceClass.temperature; ret.device_class = Sensor.DeviceClass.temperature;
ret.state_topic = zone.ToTopic(Topic.current_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; return ret;
} }
@ -399,9 +399,16 @@ namespace OmniLinkBridge.MQTT
return ret; return ret;
} }
public static Climate ToConfig(this clsThermostat thermostat) public static Climate ToConfig(this clsThermostat thermostat, enuTempFormat format)
{ {
Climate ret = new Climate(); 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.name = Global.mqtt_discovery_name_prefix + thermostat.Name;
ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature); ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature);

View file

@ -208,18 +208,33 @@ namespace OmniLinkBridge.Modules
{ {
if (string.Compare(command, Topic.temperature_heat_command.ToString()) == 0 && double.TryParse(payload, out double tempLow)) if (string.Compare(command, Topic.temperature_heat_command.ToString()) == 0 && double.TryParse(payload, out double tempLow))
{ {
int temp = tempLow.ToCelsius().ToOmniTemp(); string tempUnit = "C";
log.Debug("SetThermostatHeatSetpoint: " + thermostat.Number + " to " + payload + "F (" + temp + ")"); 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); 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)) else if (string.Compare(command, Topic.temperature_cool_command.ToString()) == 0 && double.TryParse(payload, out double tempHigh))
{ {
int temp = tempHigh.ToCelsius().ToOmniTemp(); string tempUnit = "C";
log.Debug("SetThermostatCoolSetpoint: " + thermostat.Number + " to " + payload + "F (" + temp + ")"); 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); 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)) 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(); int level = humidify.ToCelsius().ToOmniTemp();
log.Debug("SetThermostatHumidifySetpoint: " + thermostat.Number + " to " + payload + "% (" + level + ")"); log.Debug("SetThermostatHumidifySetpoint: " + thermostat.Number + " to " + payload + "% (" + level + ")");
OmniLink.Controller.SendCommand(enuUnitCommand.SetHumidifySetPt, BitConverter.GetBytes(level)[0], (ushort)thermostat.Number); OmniLink.Controller.SendCommand(enuUnitCommand.SetHumidifySetPt, BitConverter.GetBytes(level)[0], (ushort)thermostat.Number);
@ -350,7 +365,7 @@ namespace OmniLinkBridge.Modules
if (zone.IsTemperatureZone()) if (zone.IsTemperatureZone())
MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}temp/config", 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()) else if (zone.IsHumidityZone())
MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}humidity/config", MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}humidity/config",
JsonConvert.SerializeObject(zone.ToConfigHumidity()), MqttQualityOfServiceLevel.AtMostOnce, true); JsonConvert.SerializeObject(zone.ToConfigHumidity()), MqttQualityOfServiceLevel.AtMostOnce, true);
@ -402,9 +417,9 @@ namespace OmniLinkBridge.Modules
PublishThermostatState(thermostat); PublishThermostatState(thermostat);
MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i.ToString()}/config", 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", 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", MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i.ToString()}humidity/config",
JsonConvert.SerializeObject(thermostat.ToConfigHumidity()), MqttQualityOfServiceLevel.AtMostOnce, true); JsonConvert.SerializeObject(thermostat.ToConfigHumidity()), MqttQualityOfServiceLevel.AtMostOnce, true);
} }

View file

@ -335,6 +335,7 @@ namespace OmniLinkBridge.Modules
{ {
log.Debug("Retrieving named units"); log.Debug("Retrieving named units");
await GetSystemFormats();
await GetNamed(enuObjectType.Area); await GetNamed(enuObjectType.Area);
await GetNamed(enuObjectType.Zone); await GetNamed(enuObjectType.Zone);
await GetNamed(enuObjectType.Thermostat); await GetNamed(enuObjectType.Thermostat);
@ -343,13 +344,27 @@ namespace OmniLinkBridge.Modules
await GetNamed(enuObjectType.Button); 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) private async Task GetNamed(enuObjectType type)
{ {
log.Debug("Waiting for named units " + type.ToString());
GetNextNamed(type, 0); GetNextNamed(type, 0);
await Task.Run(() => await Task.Run(() =>
{ {
log.Debug("Waiting for named units " + type.ToString());
nameWait.WaitOne(new TimeSpan(0, 0, 10)); nameWait.WaitOne(new TimeSpan(0, 0, 10));
}); });
} }
@ -379,8 +394,18 @@ namespace OmniLinkBridge.Modules
case enuOmniLink2MessageType.EOD: case enuOmniLink2MessageType.EOD:
nameWait.Set(); nameWait.Set();
break; 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); clsOL2MsgProperties MSG = new clsOL2MsgProperties(Controller.Connection, B);
switch (MSG.ObjectType) switch (MSG.ObjectType)

View file

@ -43,6 +43,10 @@ namespace OmniLinkBridge.WebAPI
ret.zonetype = zone.ZoneType; ret.zonetype = zone.ZoneType;
ret.name = zone.Name; ret.name = zone.Name;
ret.status = zone.StatusText(); ret.status = zone.StatusText();
if (zone.IsTemperatureZone())
ret.temp = zone.TempText();
else if(zone.IsHumidityZone())
ret.temp = zone.TempText(); ret.temp = zone.TempText();
return ret; return ret;

View file

@ -225,15 +225,31 @@ namespace OmniLinkBridge.WebAPI
public void SetThermostatCoolSetpoint(CommandContract unit) public void SetThermostatCoolSetpoint(CommandContract unit)
{ {
int temp = ((double)unit.value).ToCelsius().ToOmniTemp(); double tempHigh = unit.value;
log.Debug("SetThermostatCoolSetpoint: " + unit.id + " to " + unit.value + "F (" + temp + ")"); 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); WebServiceModule.OmniLink.Controller.SendCommand(enuUnitCommand.SetHighSetPt, BitConverter.GetBytes(temp)[0], unit.id);
} }
public void SetThermostatHeatSetpoint(CommandContract unit) public void SetThermostatHeatSetpoint(CommandContract unit)
{ {
int temp = ((double)unit.value).ToCelsius().ToOmniTemp(); double tempLoad = unit.value;
log.Debug("SetThermostatCoolSetpoint: " + unit.id + " to " + unit.value + "F (" + temp + ")"); 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); WebServiceModule.OmniLink.Controller.SendCommand(enuUnitCommand.SetLowSetPt, BitConverter.GetBytes(temp)[0], unit.id);
} }