From 39afb1e6d32f1cb72054d36395f066a5209fabfd Mon Sep 17 00:00:00 2001 From: panctronic <26213122+panctronic@users.noreply.github.com> Date: Wed, 8 Jan 2020 17:21:55 -0800 Subject: [PATCH] Add temperature units to MQTT Climate Modifies the MQTT climate component to support auto-discovered MQTT Climate devices configuring which temperature unit they use. This allows a HVAC unit that internally operates in Celsius to work with a HA installation with a Fahrenheit unit configuration. --- homeassistant/components/mqtt/climate.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/mqtt/climate.py b/homeassistant/components/mqtt/climate.py index 91a36a310cbd98..6ce9c03286f7fb 100644 --- a/homeassistant/components/mqtt/climate.py +++ b/homeassistant/components/mqtt/climate.py @@ -37,6 +37,7 @@ ATTR_TEMPERATURE, CONF_DEVICE, CONF_NAME, + CONF_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, PRECISION_HALVES, PRECISION_TENTHS, @@ -294,7 +295,6 @@ def __init__(self, hass, config, config_entry, discovery_hash): self._target_temp_high = None self._target_temp_low = None self._topic = None - self._unit_of_measurement = hass.config.units.temperature_unit self._value_templates = None self._setup_from_config(config) @@ -570,8 +570,11 @@ def unique_id(self): @property def temperature_unit(self): - """Return the unit of measurement.""" - return self._unit_of_measurement + """Return the unit this state is expressed in.""" + mqtt_measure = self._config.get(CONF_UNIT_OF_MEASUREMENT) + if not mqtt_measure: + mqtt_measure = self.hass.config.units.temperature_unit + return mqtt_measure @property def current_temperature(self):