Skip to content

Commit

Permalink
Adds support for imperial units
Browse files Browse the repository at this point in the history
Ports over the changes from [this pull request in the original SmartIR repo](smartHomeHub#1103), made by @devbyaccident and @kevin-brown.
  • Loading branch information
TheAppleFreak authored May 22, 2024
1 parent 8a92888 commit 104b2aa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PRECISION_TENTHS,
PRECISION_HALVES,
PRECISION_WHOLE,
UnitOfTemperature
)
from homeassistant.core import HomeAssistant, Event, EventStateChangedData, callback
from homeassistant.helpers.event import async_track_state_change_event
Expand Down Expand Up @@ -139,6 +140,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 @@ -323,6 +328,12 @@ async def async_set_hvac_mode(self, hvac_mode):
await self.send_command(
hvac_mode, self._fan_mode, self._swing_mode, self._target_temperature
)

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."""
Expand Down Expand Up @@ -387,6 +398,9 @@ async def send_command(self, hvac_mode, fan_mode, swing_mode, temperature):
try:
target_temperature = "{0:g}".format(temperature)

if self._unit == UnitOfTemperature.FAHRENHEIT:
target_temperature = "{0:g}".format(self._fahrenheit_to_celsius(self._target_temperature))

if hvac_mode == HVACMode.OFF:
if (
self._last_on_operation == HVACMode.COOL
Expand Down

0 comments on commit 104b2aa

Please sign in to comment.