Convert ozw climate values to correct units (#45369)

* Convert ozw climate values to correct units

* Remove debugger logging

* Fix black code formatting

* Remove extra spaces

* Add method descriptions and change to use setpoint

* Fix build and respond to comments

* Remove self from convert_units call

* Move method to top

* Move method outside class

* Add blank lines

* Fix test to use farenheit

* Update another value to farenheit

* Change to celsius

* Another test fix

* test fix

* Fix a value

* missed one

* Add unit test for convert_units

* fix unit test import

* Add new line to end of test file

* fix convert units import

* Reorder imports

* Grab const from different import

Co-authored-by: Trevor <tboyce021@gmail.com>
This commit is contained in:
Christopher Gozdziewski 2021-02-04 01:32:43 -06:00 committed by GitHub
parent 14d914e300
commit 1b6ee8301a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 15 deletions

View file

@ -28,6 +28,7 @@ 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
@ -154,6 +155,13 @@ 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."""
@ -199,16 +207,18 @@ class ZWaveClimateEntity(ZWaveDeviceEntity, ClimateEntity):
@property
def temperature_unit(self):
"""Return the unit of measurement."""
if self.values.temperature is not None and self.values.temperature.units == "F":
return TEMP_FAHRENHEIT
return TEMP_CELSIUS
return convert_units(self._current_mode_setpoint_values[0].units)
@property
def current_temperature(self):
"""Return the current temperature."""
if not self.values.temperature:
return None
return self.values.temperature.value
return convert_temperature(
self.values.temperature.value,
convert_units(self._current_mode_setpoint_values[0].units),
self.temperature_unit,
)
@property
def hvac_action(self):
@ -236,17 +246,29 @@ class ZWaveClimateEntity(ZWaveDeviceEntity, ClimateEntity):
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
return self._current_mode_setpoint_values[0].value
return convert_temperature(
self._current_mode_setpoint_values[0].value,
convert_units(self._current_mode_setpoint_values[0].units),
self.temperature_unit,
)
@property
def target_temperature_low(self) -> Optional[float]:
"""Return the lowbound target temperature we try to reach."""
return self._current_mode_setpoint_values[0].value
return convert_temperature(
self._current_mode_setpoint_values[0].value,
convert_units(self._current_mode_setpoint_values[0].units),
self.temperature_unit,
)
@property
def target_temperature_high(self) -> Optional[float]:
"""Return the highbound target temperature we try to reach."""
return self._current_mode_setpoint_values[1].value
return convert_temperature(
self._current_mode_setpoint_values[1].value,
convert_units(self._current_mode_setpoint_values[1].units),
self.temperature_unit,
)
async def async_set_temperature(self, **kwargs):
"""Set new target temperature.
@ -262,14 +284,29 @@ 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):