diff --git a/custom_components/smartir/climate.py b/custom_components/smartir/climate.py index 0c21ea2a..3f6b43c7 100644 --- a/custom_components/smartir/climate.py +++ b/custom_components/smartir/climate.py @@ -13,7 +13,7 @@ SUPPORT_SWING_MODE, HVAC_MODES, ATTR_HVAC_MODE) from homeassistant.const import ( CONF_NAME, STATE_ON, STATE_OFF, STATE_UNKNOWN, STATE_UNAVAILABLE, ATTR_TEMPERATURE, - PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE) + PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE, UnitOfTemperature) from homeassistant.core import callback from homeassistant.helpers.event import async_track_state_change import homeassistant.helpers.config_validation as cv @@ -135,6 +135,10 @@ def __init__(self, hass, config, device_data): self._unit = hass.config.units.temperature_unit + if self._unit == UnitOfTemperature.FAHRENHEIT: + self._min_temperature = self._celsius_to_fahrenheit(self._min_temperature) + self._max_temperature = self._celsius_to_fahrenheit(self._max_temperature) + #Supported features self._support_flags = SUPPORT_FLAGS self._support_swing = False @@ -295,6 +299,12 @@ def extra_state_attributes(self): 'commands_encoding': self._commands_encoding } + def _celsius_to_fahrenheit(self, temperature): + return round(temperature * 9 / 5) + 32 + + def _fahrenheit_to_celsius(self, temperature): + return round((temperature - 32) * 5 / 9) + async def async_set_temperature(self, **kwargs): """Set new target temperatures.""" hvac_mode = kwargs.get(ATTR_HVAC_MODE) @@ -366,6 +376,9 @@ async def send_command(self): fan_mode = self._current_fan_mode swing_mode = self._current_swing_mode target_temperature = '{0:g}'.format(self._target_temperature) + + if self._unit == UnitOfTemperature.FAHRENHEIT: + target_temperature = '{0:g}'.format(self._fahrenheit_to_celsius(self._target_temperature)) if operation_mode.lower() == HVAC_MODE_OFF: await self._controller.send(self._commands['off'])