Skip to content

Commit

Permalink
Merge pull request #31 from jbergler/master
Browse files Browse the repository at this point in the history
Expose fan via Homekit
  • Loading branch information
jbergler authored Mar 28, 2023
2 parents e7971da + ed6c592 commit 84b73bd
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions custom_components/intesisbox/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
HVAC_MODE_FAN_ONLY: 'mdi:fan',
}

FAN_MODE_I_TO_E = {
'AUTO': 'auto',
'1': 'low',
'2': 'medium',
'3': 'high',
}
FAN_MODE_E_TO_I = {v: k for k, v in FAN_MODE_I_TO_E.items()}

SWING_ON = 'SWING'
SWING_STOP = 'AUTO'
SWING_LIST_HORIZONTAL = 'Horizontal'
Expand Down Expand Up @@ -98,7 +106,7 @@ class IntesisBoxAC(ClimateEntity):

def __init__(self, controller, name = None, unique_id = None):
"""Initialize the thermostat."""
_LOGGER.debug('Added climate device with state')
_LOGGER.debug("Setting up climate device.")
self._controller = controller

self._deviceid = controller.device_mac_address
Expand All @@ -122,7 +130,7 @@ def __init__(self, controller, name = None, unique_id = None):
# Setup fan list
self._fan_list = [x.title() for x in self._controller.fan_speed_list]
if len(self._fan_list) < 1:
raise PlatformNotReady
raise PlatformNotReady("Controller hasn't finished initializing device")
self._fan_speed = None

# Setup operation list
Expand All @@ -148,6 +156,7 @@ def __init__(self, controller, name = None, unique_id = None):
if len(self._swing_list) > 2:
self._swing_list.append(SWING_LIST_BOTH)

_LOGGER.debug("Finished setting up climate entity!")
self._controller.add_update_callback(self.update_callback)

@property
Expand Down Expand Up @@ -192,7 +201,7 @@ def extra_state_attributes(self):

def set_temperature(self, **kwargs):
"""Set new target temperature."""
_LOGGER.debug("Intesisbox Set Temperature=%s")
_LOGGER.debug(f"set_temperature({kwargs!r})")

temperature = kwargs.get(ATTR_TEMPERATURE)
operation_mode = kwargs.get(ATTR_HVAC_MODE)
Expand All @@ -205,7 +214,7 @@ def set_temperature(self, **kwargs):

def set_hvac_mode(self, operation_mode):
"""Set operation mode."""
_LOGGER.debug("Intesisbox Set Mode=%s", operation_mode)
_LOGGER.debug(f"set_hvac_mode({operation_mode=})")
if operation_mode == HVAC_MODE_OFF:
self._controller.set_power_off()
self._power = False
Expand All @@ -229,7 +238,9 @@ def turn_off(self):

def set_fan_mode(self, fan_mode):
"""Set fan mode (from quiet, low, medium, high, auto)."""
self._controller.set_fan_speed(fan_mode.upper())
target = FAN_MODE_E_TO_I.get(fan_mode, fan_mode)
_LOGGER.debug(f"set_fan_mode({fan_mode=}) -> set_fan_speed(target={target.upper()})")
self._controller.set_fan_speed(target.upper())

def set_swing_mode(self, swing_mode):
"""Set the vertical vane."""
Expand Down Expand Up @@ -330,7 +341,7 @@ def hvac_modes(self):
@property
def fan_mode(self):
"""Return whether the fan is on."""
return self._fan_speed
return FAN_MODE_I_TO_E.get(self._fan_speed, self._fan_speed).lower()

@property
def swing_mode(self):
Expand All @@ -347,7 +358,11 @@ def swing_mode(self):
@property
def fan_modes(self):
"""List of available fan modes."""
return self._fan_list
return [
FAN_MODE_I_TO_E.get(mode.upper(), mode)
for mode
in self._fan_list
]

@property
def swing_modes(self):
Expand Down

0 comments on commit 84b73bd

Please sign in to comment.