From d02b78c634f6eb7198e42d40e0024abc6d216eb4 Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Sun, 7 Feb 2021 22:05:10 -0800 Subject: [PATCH] Revert "Convert ozw climate values to correct units (#45369)" (#46163) This reverts commit 1b6ee8301a5c076f93d0799b9f7fcb82cc6eb902. --- homeassistant/components/ozw/climate.py | 51 ++++--------------------- tests/components/ozw/test_climate.py | 20 ++++------ 2 files changed, 15 insertions(+), 56 deletions(-) diff --git a/homeassistant/components/ozw/climate.py b/homeassistant/components/ozw/climate.py index 67bbe5cdc4d..a74fd869f0f 100644 --- a/homeassistant/components/ozw/climate.py +++ b/homeassistant/components/ozw/climate.py @@ -28,7 +28,6 @@ from homeassistant.components.climate.const import ( from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.util.temperature import convert as convert_temperature from .const import DATA_UNSUBSCRIBE, DOMAIN from .entity import ZWaveDeviceEntity @@ -155,13 +154,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): ) -def convert_units(units): - """Return units as a farenheit or celsius constant.""" - if units == "F": - return TEMP_FAHRENHEIT - return TEMP_CELSIUS - - class ZWaveClimateEntity(ZWaveDeviceEntity, ClimateEntity): """Representation of a Z-Wave Climate device.""" @@ -207,18 +199,16 @@ class ZWaveClimateEntity(ZWaveDeviceEntity, ClimateEntity): @property def temperature_unit(self): """Return the unit of measurement.""" - return convert_units(self._current_mode_setpoint_values[0].units) + if self.values.temperature is not None and self.values.temperature.units == "F": + return TEMP_FAHRENHEIT + return TEMP_CELSIUS @property def current_temperature(self): """Return the current temperature.""" if not self.values.temperature: return None - return convert_temperature( - self.values.temperature.value, - convert_units(self._current_mode_setpoint_values[0].units), - self.temperature_unit, - ) + return self.values.temperature.value @property def hvac_action(self): @@ -246,29 +236,17 @@ class ZWaveClimateEntity(ZWaveDeviceEntity, ClimateEntity): @property def target_temperature(self): """Return the temperature we try to reach.""" - return convert_temperature( - self._current_mode_setpoint_values[0].value, - convert_units(self._current_mode_setpoint_values[0].units), - self.temperature_unit, - ) + return self._current_mode_setpoint_values[0].value @property def target_temperature_low(self) -> Optional[float]: """Return the lowbound target temperature we try to reach.""" - return convert_temperature( - self._current_mode_setpoint_values[0].value, - convert_units(self._current_mode_setpoint_values[0].units), - self.temperature_unit, - ) + return self._current_mode_setpoint_values[0].value @property def target_temperature_high(self) -> Optional[float]: """Return the highbound target temperature we try to reach.""" - return convert_temperature( - self._current_mode_setpoint_values[1].value, - convert_units(self._current_mode_setpoint_values[1].units), - self.temperature_unit, - ) + return self._current_mode_setpoint_values[1].value async def async_set_temperature(self, **kwargs): """Set new target temperature. @@ -284,29 +262,14 @@ class ZWaveClimateEntity(ZWaveDeviceEntity, ClimateEntity): setpoint = self._current_mode_setpoint_values[0] target_temp = kwargs.get(ATTR_TEMPERATURE) if setpoint is not None and target_temp is not None: - target_temp = convert_temperature( - target_temp, - self.temperature_unit, - convert_units(setpoint.units), - ) setpoint.send_value(target_temp) elif len(self._current_mode_setpoint_values) == 2: (setpoint_low, setpoint_high) = self._current_mode_setpoint_values target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW) target_temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH) if setpoint_low is not None and target_temp_low is not None: - target_temp_low = convert_temperature( - target_temp_low, - self.temperature_unit, - convert_units(setpoint_low.units), - ) setpoint_low.send_value(target_temp_low) if setpoint_high is not None and target_temp_high is not None: - target_temp_high = convert_temperature( - target_temp_high, - self.temperature_unit, - convert_units(setpoint_high.units), - ) setpoint_high.send_value(target_temp_high) async def async_set_fan_mode(self, fan_mode): diff --git a/tests/components/ozw/test_climate.py b/tests/components/ozw/test_climate.py index e251a93c115..3414e6c4832 100644 --- a/tests/components/ozw/test_climate.py +++ b/tests/components/ozw/test_climate.py @@ -16,8 +16,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF, ) -from homeassistant.components.ozw.climate import convert_units -from homeassistant.const import TEMP_FAHRENHEIT from .common import setup_ozw @@ -38,8 +36,8 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog): HVAC_MODE_HEAT_COOL, ] assert state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_IDLE - assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 73.5 - assert state.attributes[ATTR_TEMPERATURE] == 70.0 + assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 23.1 + assert state.attributes[ATTR_TEMPERATURE] == 21.1 assert state.attributes.get(ATTR_TARGET_TEMP_LOW) is None assert state.attributes.get(ATTR_TARGET_TEMP_HIGH) is None assert state.attributes[ATTR_FAN_MODE] == "Auto Low" @@ -56,7 +54,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog): msg = sent_messages[-1] assert msg["topic"] == "OpenZWave/1/command/setvalue/" # Celsius is converted to Fahrenheit here! - assert round(msg["payload"]["Value"], 2) == 26.1 + assert round(msg["payload"]["Value"], 2) == 78.98 assert msg["payload"]["ValueIDKey"] == 281475099443218 # Test hvac_mode with set_temperature @@ -74,7 +72,7 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog): msg = sent_messages[-1] assert msg["topic"] == "OpenZWave/1/command/setvalue/" # Celsius is converted to Fahrenheit here! - assert round(msg["payload"]["Value"], 2) == 24.1 + assert round(msg["payload"]["Value"], 2) == 75.38 assert msg["payload"]["ValueIDKey"] == 281475099443218 # Test set mode @@ -129,8 +127,8 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog): assert state is not None assert state.state == HVAC_MODE_HEAT_COOL assert state.attributes.get(ATTR_TEMPERATURE) is None - assert state.attributes[ATTR_TARGET_TEMP_LOW] == 70.0 - assert state.attributes[ATTR_TARGET_TEMP_HIGH] == 78.0 + assert state.attributes[ATTR_TARGET_TEMP_LOW] == 21.1 + assert state.attributes[ATTR_TARGET_TEMP_HIGH] == 25.6 # Test setting high/low temp on multiple setpoints await hass.services.async_call( @@ -146,11 +144,11 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog): assert len(sent_messages) == 7 # 2 messages ! msg = sent_messages[-2] # low setpoint assert msg["topic"] == "OpenZWave/1/command/setvalue/" - assert round(msg["payload"]["Value"], 2) == 20.0 + assert round(msg["payload"]["Value"], 2) == 68.0 assert msg["payload"]["ValueIDKey"] == 281475099443218 msg = sent_messages[-1] # high setpoint assert msg["topic"] == "OpenZWave/1/command/setvalue/" - assert round(msg["payload"]["Value"], 2) == 25.0 + assert round(msg["payload"]["Value"], 2) == 77.0 assert msg["payload"]["ValueIDKey"] == 562950076153874 # Test basic/single-setpoint thermostat (node 16 in dump) @@ -327,5 +325,3 @@ async def test_climate(hass, climate_data, sent_messages, climate_msg, caplog): ) assert len(sent_messages) == 12 assert "does not support setting a mode" in caplog.text - - assert convert_units("F") == TEMP_FAHRENHEIT