Skip to content

Commit

Permalink
Adds support for swing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilis-panos committed Jan 27, 2021
1 parent e43393c commit a305d03
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion custom_components/smartir/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
_LOGGER = logging.getLogger(__name__)

DOMAIN = 'smartir'
VERSION = '1.15.1'
VERSION = '1.16.0'
MANIFEST_URL = (
"https://raw.githubusercontent.com/"
"smartHomeHub/SmartIR/{}/"
Expand Down
42 changes: 38 additions & 4 deletions custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL,
HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, HVAC_MODE_AUTO,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE,
HVAC_MODES, ATTR_HVAC_MODE)
SUPPORT_SWING_MODE, HVAC_MODES, ATTR_HVAC_MODE)
from homeassistant.const import (
CONF_NAME, STATE_ON, STATE_OFF, STATE_UNKNOWN, ATTR_TEMPERATURE,
PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE)
Expand Down Expand Up @@ -45,7 +45,7 @@
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_DEVICE_CODE): cv.positive_int,
vol.Required(CONF_CONTROLLER_DATA): cv.string,
vol.Optional(CONF_DELAY, default=DEFAULT_DELAY): cv.string,
vol.Optional(CONF_DELAY, default=DEFAULT_DELAY): cv.positive_float,
vol.Optional(CONF_TEMPERATURE_SENSOR): cv.entity_id,
vol.Optional(CONF_HUMIDITY_SENSOR): cv.entity_id,
vol.Optional(CONF_POWER_SENSOR): cv.entity_id,
Expand Down Expand Up @@ -117,18 +117,28 @@ def __init__(self, hass, config, device_data):

self._operation_modes = [HVAC_MODE_OFF] + valid_hvac_modes
self._fan_modes = device_data['fanModes']
self._swing_modes = device_data.get('swingModes')
self._commands = device_data['commands']

self._target_temperature = self._min_temperature
self._hvac_mode = HVAC_MODE_OFF
self._current_fan_mode = self._fan_modes[0]
self._current_swing_mode = None
self._last_on_operation = None

self._current_temperature = None
self._current_humidity = None

self._unit = hass.config.units.temperature_unit

#Supported features
self._support_flags = SUPPORT_FLAGS
self._support_swing = False

if self._swing_modes:
self._support_flags = self._support_flags | SUPPORT_SWING_MODE
self._current_swing_mode = self._swing_modes[0]
self._support_swing = True

self._temp_lock = asyncio.Lock()
self._on_by_remote = False
Expand All @@ -150,6 +160,7 @@ async def async_added_to_hass(self):
if last_state is not None:
self._hvac_mode = last_state.state
self._current_fan_mode = last_state.attributes['fan_mode']
self._current_swing_mode = last_state.attributes.get('swing_mode')
self._target_temperature = last_state.attributes['temperature']

if 'last_on_operation' in last_state.attributes:
Expand Down Expand Up @@ -242,6 +253,16 @@ def fan_mode(self):
"""Return the fan setting."""
return self._current_fan_mode

@property
def swing_modes(self):
"""Return the swing modes currently supported for this device."""
return self._swing_modes

@property
def swing_mode(self):
"""Return the current swing mode."""
return self._current_swing_mode

@property
def current_temperature(self):
"""Return the current temperature."""
Expand Down Expand Up @@ -313,6 +334,14 @@ async def async_set_fan_mode(self, fan_mode):
await self.send_command()
await self.async_update_ha_state()

async def async_set_swing_mode(self, swing_mode):
"""Set swing mode."""
self._current_swing_mode = swing_mode

if not self._hvac_mode.lower() == HVAC_MODE_OFF:
await self.send_command()
await self.async_update_ha_state()

async def async_turn_off(self):
"""Turn off."""
await self.async_set_hvac_mode(HVAC_MODE_OFF)
Expand All @@ -330,6 +359,7 @@ async def send_command(self):
self._on_by_remote = False
operation_mode = self._hvac_mode
fan_mode = self._current_fan_mode
swing_mode = self._current_swing_mode
target_temperature = '{0:g}'.format(self._target_temperature)

if operation_mode.lower() == HVAC_MODE_OFF:
Expand All @@ -340,8 +370,12 @@ async def send_command(self):
await self._controller.send(self._commands['on'])
await asyncio.sleep(self._delay)

await self._controller.send(
self._commands[operation_mode][fan_mode][target_temperature])
if self._support_swing == True:
await self._controller.send(
self._commands[operation_mode][fan_mode][swing_mode][target_temperature])
else:
await self._controller.send(
self._commands[operation_mode][fan_mode][target_temperature])

except Exception as e:
_LOGGER.exception(e)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/smartir/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"requirements": ["aiofiles==0.6.0"],
"homeassistant": "0.115.0",
"updater": {
"version": "1.15.1",
"releaseNotes": "-- Adds adjustable delay between commands for Broadlink controller",
"version": "1.16.0",
"releaseNotes": "-- Adds support for swing mode",
"files": [
"__init__.py",
"climate.py",
Expand Down

0 comments on commit a305d03

Please sign in to comment.