Skip to content

Commit

Permalink
Adds power_sensor_restore_state
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilis-panos committed Jan 6, 2021
1 parent 3f18a6e commit 38a1cbf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 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.13.2'
VERSION = '1.14.0'
MANIFEST_URL = (
"https://raw.githubusercontent.com/"
"smartHomeHub/SmartIR/{}/"
Expand Down
12 changes: 9 additions & 3 deletions custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CONF_TEMPERATURE_SENSOR = 'temperature_sensor'
CONF_HUMIDITY_SENSOR = 'humidity_sensor'
CONF_POWER_SENSOR = 'power_sensor'
CONF_POWER_SENSOR_RESTORE_STATE = 'power_sensor_restore_state'

SUPPORT_FLAGS = (
SUPPORT_TARGET_TEMPERATURE |
Expand All @@ -44,7 +45,8 @@
vol.Required(CONF_CONTROLLER_DATA): cv.string,
vol.Optional(CONF_TEMPERATURE_SENSOR): cv.entity_id,
vol.Optional(CONF_HUMIDITY_SENSOR): cv.entity_id,
vol.Optional(CONF_POWER_SENSOR): cv.entity_id
vol.Optional(CONF_POWER_SENSOR): cv.entity_id,
vol.Optional(CONF_POWER_SENSOR_RESTORE_STATE, default=False): cv.boolean
})

async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
Expand Down Expand Up @@ -97,6 +99,7 @@ def __init__(self, hass, config, device_data):
self._temperature_sensor = config.get(CONF_TEMPERATURE_SENSOR)
self._humidity_sensor = config.get(CONF_HUMIDITY_SENSOR)
self._power_sensor = config.get(CONF_POWER_SENSOR)
self._power_sensor_restore_state = config.get(CONF_POWER_SENSOR_RESTORE_STATE)

self._manufacturer = device_data['manufacturer']
self._supported_models = device_data['supportedModels']
Expand Down Expand Up @@ -180,8 +183,6 @@ def name(self):
@property
def state(self):
"""Return the current state."""
if self._on_by_remote:
return STATE_ON
if self.hvac_mode != HVAC_MODE_OFF:
return self.hvac_mode
return HVAC_MODE_OFF
Expand Down Expand Up @@ -363,6 +364,11 @@ async def _async_power_sensor_changed(self, entity_id, old_state, new_state):

if new_state.state == STATE_ON and self._hvac_mode == HVAC_MODE_OFF:
self._on_by_remote = True
if self._power_sensor_restore_state == True and self._last_on_operation is not None:
self._hvac_mode = self._last_on_operation
else:
self._hvac_mode = STATE_ON

await self.async_update_ha_state()

if new_state.state == HVAC_MODE_OFF:
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.5.0"],
"homeassistant": "0.115.0",
"updater": {
"version": "1.13.2",
"releaseNotes": "-- Fixes Broadlink commands sequence #481",
"version": "1.14.0",
"releaseNotes": "-- Adds power_sensor_restore_state",
"files": [
"__init__.py",
"climate.py",
Expand Down

0 comments on commit 38a1cbf

Please sign in to comment.