瀏覽代碼

Fix self.async_update_ha_state() #1071

Vassilis Panos 3 年之前
父節點
當前提交
b0b4bc8ab8

+ 1 - 1
custom_components/smartir/__init__.py

@@ -19,7 +19,7 @@ from homeassistant.helpers.typing import ConfigType
 _LOGGER = logging.getLogger(__name__)
 _LOGGER = logging.getLogger(__name__)
 
 
 DOMAIN = 'smartir'
 DOMAIN = 'smartir'
-VERSION = '1.17.7'
+VERSION = '1.17.8'
 MANIFEST_URL = (
 MANIFEST_URL = (
     "https://raw.githubusercontent.com/"
     "https://raw.githubusercontent.com/"
     "smartHomeHub/SmartIR/{}/"
     "smartHomeHub/SmartIR/{}/"

+ 8 - 8
custom_components/smartir/climate.py

@@ -319,7 +319,7 @@ class SmartIRClimate(ClimateEntity, RestoreEntity):
         if not self._hvac_mode.lower() == HVAC_MODE_OFF:
         if not self._hvac_mode.lower() == HVAC_MODE_OFF:
             await self.send_command()
             await self.send_command()
 
 
-        await self.async_update_ha_state()
+        self.async_write_ha_state()
 
 
     async def async_set_hvac_mode(self, hvac_mode):
     async def async_set_hvac_mode(self, hvac_mode):
         """Set operation mode."""
         """Set operation mode."""
@@ -329,7 +329,7 @@ class SmartIRClimate(ClimateEntity, RestoreEntity):
             self._last_on_operation = hvac_mode
             self._last_on_operation = hvac_mode
 
 
         await self.send_command()
         await self.send_command()
-        await self.async_update_ha_state()
+        self.async_write_ha_state()
 
 
     async def async_set_fan_mode(self, fan_mode):
     async def async_set_fan_mode(self, fan_mode):
         """Set fan mode."""
         """Set fan mode."""
@@ -337,7 +337,7 @@ class SmartIRClimate(ClimateEntity, RestoreEntity):
         
         
         if not self._hvac_mode.lower() == HVAC_MODE_OFF:
         if not self._hvac_mode.lower() == HVAC_MODE_OFF:
             await self.send_command()      
             await self.send_command()      
-        await self.async_update_ha_state()
+        self.async_write_ha_state()
 
 
     async def async_set_swing_mode(self, swing_mode):
     async def async_set_swing_mode(self, swing_mode):
         """Set swing mode."""
         """Set swing mode."""
@@ -345,7 +345,7 @@ class SmartIRClimate(ClimateEntity, RestoreEntity):
 
 
         if not self._hvac_mode.lower() == HVAC_MODE_OFF:
         if not self._hvac_mode.lower() == HVAC_MODE_OFF:
             await self.send_command()
             await self.send_command()
-        await self.async_update_ha_state()
+        self.async_write_ha_state()
 
 
     async def async_turn_off(self):
     async def async_turn_off(self):
         """Turn off."""
         """Turn off."""
@@ -391,7 +391,7 @@ class SmartIRClimate(ClimateEntity, RestoreEntity):
             return
             return
 
 
         self._async_update_temp(new_state)
         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):
     async def _async_humidity_sensor_changed(self, entity_id, old_state, new_state):
         """Handle humidity sensor changes."""
         """Handle humidity sensor changes."""
@@ -399,7 +399,7 @@ class SmartIRClimate(ClimateEntity, RestoreEntity):
             return
             return
 
 
         self._async_update_humidity(new_state)
         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):
     async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
         """Handle power sensor changes."""
         """Handle power sensor changes."""
@@ -416,13 +416,13 @@ class SmartIRClimate(ClimateEntity, RestoreEntity):
             else:
             else:
                 self._hvac_mode = STATE_ON
                 self._hvac_mode = STATE_ON
 
 
-            await self.async_update_ha_state()
+            self.async_write_ha_state()
 
 
         if new_state.state == STATE_OFF:
         if new_state.state == STATE_OFF:
             self._on_by_remote = False
             self._on_by_remote = False
             if self._hvac_mode != HVAC_MODE_OFF:
             if self._hvac_mode != HVAC_MODE_OFF:
                 self._hvac_mode = HVAC_MODE_OFF
                 self._hvac_mode = HVAC_MODE_OFF
-            await self.async_update_ha_state()
+            self.async_write_ha_state()
 
 
     @callback
     @callback
     def _async_update_temp(self, state):
     def _async_update_temp(self, state):

+ 6 - 6
custom_components/smartir/fan.py

@@ -9,7 +9,7 @@ from homeassistant.components.fan import (
     FanEntity, PLATFORM_SCHEMA,
     FanEntity, PLATFORM_SCHEMA,
     DIRECTION_REVERSE, DIRECTION_FORWARD,
     DIRECTION_REVERSE, DIRECTION_FORWARD,
     SUPPORT_SET_SPEED, SUPPORT_DIRECTION, SUPPORT_OSCILLATE, 
     SUPPORT_SET_SPEED, SUPPORT_DIRECTION, SUPPORT_OSCILLATE, 
-    ATTR_OSCILLATING )
+    ATTR_OSCILLATING)
 from homeassistant.const import (
 from homeassistant.const import (
     CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN)
     CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN)
 from homeassistant.core import callback
 from homeassistant.core import callback
@@ -228,14 +228,14 @@ class SmartIRFan(FanEntity, RestoreEntity):
             self._last_on_speed = self._speed
             self._last_on_speed = self._speed
 
 
         await self.send_command()
         await self.send_command()
-        await self.async_update_ha_state()
+        self.async_write_ha_state()
 
 
     async def async_oscillate(self, oscillating: bool) -> None:
     async def async_oscillate(self, oscillating: bool) -> None:
         """Set oscillation of the fan."""
         """Set oscillation of the fan."""
         self._oscillating = oscillating
         self._oscillating = oscillating
 
 
         await self.send_command()
         await self.send_command()
-        await self.async_update_ha_state()
+        self.async_write_ha_state()
 
 
     async def async_set_direction(self, direction: str):
     async def async_set_direction(self, direction: str):
         """Set the direction of the fan"""
         """Set the direction of the fan"""
@@ -244,7 +244,7 @@ class SmartIRFan(FanEntity, RestoreEntity):
         if not self._speed.lower() == SPEED_OFF:
         if not self._speed.lower() == SPEED_OFF:
             await self.send_command()
             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):
     async def async_turn_on(self, percentage: int = None, **kwargs):
         """Turn on the fan."""
         """Turn on the fan."""
@@ -288,10 +288,10 @@ class SmartIRFan(FanEntity, RestoreEntity):
         if new_state.state == STATE_ON and self._speed == SPEED_OFF:
         if new_state.state == STATE_ON and self._speed == SPEED_OFF:
             self._on_by_remote = True
             self._on_by_remote = True
             self._speed = None
             self._speed = None
-            await self.async_update_ha_state()
+            self.async_write_ha_state()
 
 
         if new_state.state == STATE_OFF:
         if new_state.state == STATE_OFF:
             self._on_by_remote = False
             self._on_by_remote = False
             if self._speed != SPEED_OFF:
             if self._speed != SPEED_OFF:
                 self._speed = SPEED_OFF
                 self._speed = SPEED_OFF
-            await self.async_update_ha_state()
+            self.async_write_ha_state()

+ 4 - 4
custom_components/smartir/manifest.json

@@ -5,11 +5,11 @@
   "dependencies": [],
   "dependencies": [],
   "codeowners": ["@smartHomeHub"],
   "codeowners": ["@smartHomeHub"],
   "requirements": ["aiofiles>=0.6.0"],
   "requirements": ["aiofiles>=0.6.0"],
-  "homeassistant": "2022.4.0",
-  "version": "1.17.7",
+  "homeassistant": "2023.6.0",
+  "version": "1.17.8",
   "updater": {
   "updater": {
-    "version": "1.17.7",
-    "releaseNotes": "-- Fixes #1025",
+    "version": "1.17.8",
+    "releaseNotes": "-- Fix self.async_update_ha_state() #1071",
     "files": [
     "files": [
       "__init__.py",
       "__init__.py",
       "climate.py",
       "climate.py",

+ 9 - 9
custom_components/smartir/media_player.py

@@ -225,7 +225,7 @@ class SmartIRMediaPlayer(MediaPlayerEntity, RestoreEntity):
         if self._power_sensor is None:
         if self._power_sensor is None:
             self._state = STATE_OFF
             self._state = STATE_OFF
             self._source = None
             self._source = None
-            await self.async_update_ha_state()
+            self.async_write_ha_state()
 
 
     async def async_turn_on(self):
     async def async_turn_on(self):
         """Turn the media player off."""
         """Turn the media player off."""
@@ -233,38 +233,38 @@ class SmartIRMediaPlayer(MediaPlayerEntity, RestoreEntity):
 
 
         if self._power_sensor is None:
         if self._power_sensor is None:
             self._state = STATE_ON
             self._state = STATE_ON
-            await self.async_update_ha_state()
+            self.async_write_ha_state()
 
 
     async def async_media_previous_track(self):
     async def async_media_previous_track(self):
         """Send previous track command."""
         """Send previous track command."""
         await self.send_command(self._commands['previousChannel'])
         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):
     async def async_media_next_track(self):
         """Send next track command."""
         """Send next track command."""
         await self.send_command(self._commands['nextChannel'])
         await self.send_command(self._commands['nextChannel'])
-        await self.async_update_ha_state()
+        self.async_write_ha_state()
 
 
     async def async_volume_down(self):
     async def async_volume_down(self):
         """Turn volume down for media player."""
         """Turn volume down for media player."""
         await self.send_command(self._commands['volumeDown'])
         await self.send_command(self._commands['volumeDown'])
-        await self.async_update_ha_state()
+        self.async_write_ha_state()
 
 
     async def async_volume_up(self):
     async def async_volume_up(self):
         """Turn volume up for media player."""
         """Turn volume up for media player."""
         await self.send_command(self._commands['volumeUp'])
         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):
     async def async_mute_volume(self, mute):
         """Mute the volume."""
         """Mute the volume."""
         await self.send_command(self._commands['mute'])
         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):
     async def async_select_source(self, source):
         """Select channel from source."""
         """Select channel from source."""
         self._source = source
         self._source = source
         await self.send_command(self._commands['sources'][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):
     async def async_play_media(self, media_type, media_id, **kwargs):
         """Support channel change through play_media service."""
         """Support channel change through play_media service."""
@@ -281,7 +281,7 @@ class SmartIRMediaPlayer(MediaPlayerEntity, RestoreEntity):
         self._source = "Channel {}".format(media_id)
         self._source = "Channel {}".format(media_id)
         for digit in media_id:
         for digit in media_id:
             await self.send_command(self._commands['sources']["Channel {}".format(digit)])
             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 def send_command(self, command):
         async with self._temp_lock:
         async with self._temp_lock:

+ 1 - 1
hacs.json

@@ -1,5 +1,5 @@
 {
 {
   "name": "SmartIR",
   "name": "SmartIR",
-  "homeassistant": "0.115.0",
+  "homeassistant": "2023.6.0",
   "persistent_directory": "codes"
   "persistent_directory": "codes"
 }
 }