Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Fahrenheit temperatures #1326

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'])
Expand Down