Skip to content

Commit

Permalink
Fix self.async_update_ha_state() #1071
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilis-panos committed Sep 24, 2023
1 parent fad9e79 commit b0b4bc8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 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.17.7'
VERSION = '1.17.8'
MANIFEST_URL = (
"https://raw.githubusercontent.com/"
"smartHomeHub/SmartIR/{}/"
Expand Down
16 changes: 8 additions & 8 deletions custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ async def async_set_temperature(self, **kwargs):
if not self._hvac_mode.lower() == HVAC_MODE_OFF:
await self.send_command()

await self.async_update_ha_state()
self.async_write_ha_state()

async def async_set_hvac_mode(self, hvac_mode):
"""Set operation mode."""
Expand All @@ -329,23 +329,23 @@ async def async_set_hvac_mode(self, hvac_mode):
self._last_on_operation = hvac_mode

await self.send_command()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_set_fan_mode(self, fan_mode):
"""Set fan mode."""
self._current_fan_mode = fan_mode

if not self._hvac_mode.lower() == HVAC_MODE_OFF:
await self.send_command()
await self.async_update_ha_state()
self.async_write_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()
self.async_write_ha_state()

async def async_turn_off(self):
"""Turn off."""
Expand Down Expand Up @@ -391,15 +391,15 @@ async def _async_temp_sensor_changed(self, entity_id, old_state, new_state):
return

self._async_update_temp(new_state)
await self.async_update_ha_state()
self.async_write_ha_state()

async def _async_humidity_sensor_changed(self, entity_id, old_state, new_state):
"""Handle humidity sensor changes."""
if new_state is None:
return

self._async_update_humidity(new_state)
await self.async_update_ha_state()
self.async_write_ha_state()

async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
"""Handle power sensor changes."""
Expand All @@ -416,13 +416,13 @@ async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
else:
self._hvac_mode = STATE_ON

await self.async_update_ha_state()
self.async_write_ha_state()

if new_state.state == STATE_OFF:
self._on_by_remote = False
if self._hvac_mode != HVAC_MODE_OFF:
self._hvac_mode = HVAC_MODE_OFF
await self.async_update_ha_state()
self.async_write_ha_state()

@callback
def _async_update_temp(self, state):
Expand Down
12 changes: 6 additions & 6 deletions custom_components/smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
FanEntity, PLATFORM_SCHEMA,
DIRECTION_REVERSE, DIRECTION_FORWARD,
SUPPORT_SET_SPEED, SUPPORT_DIRECTION, SUPPORT_OSCILLATE,
ATTR_OSCILLATING )
ATTR_OSCILLATING)
from homeassistant.const import (
CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN)
from homeassistant.core import callback
Expand Down Expand Up @@ -228,14 +228,14 @@ async def async_set_percentage(self, percentage: int):
self._last_on_speed = self._speed

await self.send_command()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_oscillate(self, oscillating: bool) -> None:
"""Set oscillation of the fan."""
self._oscillating = oscillating

await self.send_command()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_set_direction(self, direction: str):
"""Set the direction of the fan"""
Expand All @@ -244,7 +244,7 @@ async def async_set_direction(self, direction: str):
if not self._speed.lower() == SPEED_OFF:
await self.send_command()

await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_on(self, percentage: int = None, **kwargs):
"""Turn on the fan."""
Expand Down Expand Up @@ -288,10 +288,10 @@ async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
if new_state.state == STATE_ON and self._speed == SPEED_OFF:
self._on_by_remote = True
self._speed = None
await self.async_update_ha_state()
self.async_write_ha_state()

if new_state.state == STATE_OFF:
self._on_by_remote = False
if self._speed != SPEED_OFF:
self._speed = SPEED_OFF
await self.async_update_ha_state()
self.async_write_ha_state()
8 changes: 4 additions & 4 deletions custom_components/smartir/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"dependencies": [],
"codeowners": ["@smartHomeHub"],
"requirements": ["aiofiles>=0.6.0"],
"homeassistant": "2022.4.0",
"version": "1.17.7",
"homeassistant": "2023.6.0",
"version": "1.17.8",
"updater": {
"version": "1.17.7",
"releaseNotes": "-- Fixes #1025",
"version": "1.17.8",
"releaseNotes": "-- Fix self.async_update_ha_state() #1071",
"files": [
"__init__.py",
"climate.py",
Expand Down
18 changes: 9 additions & 9 deletions custom_components/smartir/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,46 +225,46 @@ async def async_turn_off(self):
if self._power_sensor is None:
self._state = STATE_OFF
self._source = None
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_on(self):
"""Turn the media player off."""
await self.send_command(self._commands['on'])

if self._power_sensor is None:
self._state = STATE_ON
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_media_previous_track(self):
"""Send previous track command."""
await self.send_command(self._commands['previousChannel'])
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_media_next_track(self):
"""Send next track command."""
await self.send_command(self._commands['nextChannel'])
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_volume_down(self):
"""Turn volume down for media player."""
await self.send_command(self._commands['volumeDown'])
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_volume_up(self):
"""Turn volume up for media player."""
await self.send_command(self._commands['volumeUp'])
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_mute_volume(self, mute):
"""Mute the volume."""
await self.send_command(self._commands['mute'])
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_select_source(self, source):
"""Select channel from source."""
self._source = source
await self.send_command(self._commands['sources'][source])
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_play_media(self, media_type, media_id, **kwargs):
"""Support channel change through play_media service."""
Expand All @@ -281,7 +281,7 @@ async def async_play_media(self, media_type, media_id, **kwargs):
self._source = "Channel {}".format(media_id)
for digit in media_id:
await self.send_command(self._commands['sources']["Channel {}".format(digit)])
await self.async_update_ha_state()
self.async_write_ha_state()

async def send_command(self, command):
async with self._temp_lock:
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "SmartIR",
"homeassistant": "0.115.0",
"homeassistant": "2023.6.0",
"persistent_directory": "codes"
}

0 comments on commit b0b4bc8

Please sign in to comment.