Skip to content

Commit 878df57

Browse files
Implements new async_track_state_change_event
1 parent 3cfa202 commit 878df57

File tree

5 files changed

+41
-26
lines changed

5 files changed

+41
-26
lines changed

custom_components/smartir/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_LOGGER = logging.getLogger(__name__)
2020

2121
DOMAIN = 'smartir'
22-
VERSION = '1.18.0'
22+
VERSION = '1.18.1'
2323
MANIFEST_URL = (
2424
"https://raw.githubusercontent.com/"
2525
"smartHomeHub/SmartIR/{}/"

custom_components/smartir/climate.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from homeassistant.const import (
1313
CONF_NAME, STATE_ON, STATE_OFF, STATE_UNKNOWN, STATE_UNAVAILABLE, ATTR_TEMPERATURE,
1414
PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE)
15-
from homeassistant.core import callback
16-
from homeassistant.helpers.event import async_track_state_change
15+
from homeassistant.core import Event, EventStateChangedData, callback
16+
from homeassistant.helpers.event import async_track_state_change, async_track_state_change_event
1717
import homeassistant.helpers.config_validation as cv
1818
from homeassistant.helpers.restore_state import RestoreEntity
1919
from . import COMPONENT_ABS_DIR, Helper
@@ -173,24 +173,24 @@ async def async_added_to_hass(self):
173173
self._last_on_operation = last_state.attributes['last_on_operation']
174174

175175
if self._temperature_sensor:
176-
async_track_state_change(self.hass, self._temperature_sensor,
177-
self._async_temp_sensor_changed)
176+
async_track_state_change_event(self.hass, self._temperature_sensor,
177+
self._async_temp_sensor_changed)
178178

179179
temp_sensor_state = self.hass.states.get(self._temperature_sensor)
180180
if temp_sensor_state and temp_sensor_state.state != STATE_UNKNOWN:
181181
self._async_update_temp(temp_sensor_state)
182182

183183
if self._humidity_sensor:
184-
async_track_state_change(self.hass, self._humidity_sensor,
185-
self._async_humidity_sensor_changed)
184+
async_track_state_change_event(self.hass, self._humidity_sensor,
185+
self._async_humidity_sensor_changed)
186186

187187
humidity_sensor_state = self.hass.states.get(self._humidity_sensor)
188188
if humidity_sensor_state and humidity_sensor_state.state != STATE_UNKNOWN:
189189
self._async_update_humidity(humidity_sensor_state)
190190

191191
if self._power_sensor:
192-
async_track_state_change(self.hass, self._power_sensor,
193-
self._async_power_sensor_changed)
192+
async_track_state_change_event(self.hass, self._power_sensor,
193+
self._async_power_sensor_changed)
194194

195195
@property
196196
def unique_id(self):
@@ -385,25 +385,35 @@ async def send_command(self):
385385

386386
except Exception as e:
387387
_LOGGER.exception(e)
388-
389-
async def _async_temp_sensor_changed(self, entity_id, old_state, new_state):
388+
389+
@callback
390+
async def _async_temp_sensor_changed(self, event: Event[EventStateChangedData]) -> None:
390391
"""Handle temperature sensor changes."""
392+
new_state = event.data["new_state"]
393+
391394
if new_state is None:
392395
return
393396

394397
self._async_update_temp(new_state)
395398
self.async_write_ha_state()
396399

397-
async def _async_humidity_sensor_changed(self, entity_id, old_state, new_state):
400+
@callback
401+
async def _async_humidity_sensor_changed(self, event: Event[EventStateChangedData]) -> None:
398402
"""Handle humidity sensor changes."""
403+
new_state = event.data["new_state"]
404+
399405
if new_state is None:
400406
return
401407

402408
self._async_update_humidity(new_state)
403409
self.async_write_ha_state()
404-
405-
async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
406-
"""Handle power sensor changes."""
410+
411+
@callback
412+
async def _async_power_sensor_changed(self, event: Event[EventStateChangedData]) -> None:
413+
entity_id = event.data["entity_id"]
414+
old_state = event.data["old_state"]
415+
new_state = event.data["new_state"]
416+
407417
if new_state is None:
408418
return
409419

@@ -441,4 +451,4 @@ def _async_update_humidity(self, state):
441451
if state.state != STATE_UNKNOWN and state.state != STATE_UNAVAILABLE:
442452
self._current_humidity = float(state.state)
443453
except ValueError as ex:
444-
_LOGGER.error("Unable to update from humidity sensor: %s", ex)
454+
_LOGGER.error("Unable to update from humidity sensor: %s", ex)

custom_components/smartir/fan.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
PLATFORM_SCHEMA, DIRECTION_REVERSE, DIRECTION_FORWARD)
1212
from homeassistant.const import (
1313
CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN)
14-
from homeassistant.core import callback
15-
from homeassistant.helpers.event import async_track_state_change
14+
from homeassistant.core import Event, EventStateChangedData, callback
15+
from homeassistant.helpers.event import async_track_state_change, async_track_state_change_event
1616
import homeassistant.helpers.config_validation as cv
1717
from homeassistant.helpers.restore_state import RestoreEntity
1818
from homeassistant.util.percentage import (
@@ -155,8 +155,8 @@ async def async_added_to_hass(self):
155155
self._last_on_speed = last_state.attributes['last_on_speed']
156156

157157
if self._power_sensor:
158-
async_track_state_change(self.hass, self._power_sensor,
159-
self._async_power_sensor_changed)
158+
async_track_state_change_event(self.hass, self._power_sensor,
159+
self._async_power_sensor_changed)
160160

161161
@property
162162
def unique_id(self):
@@ -282,8 +282,13 @@ async def send_command(self):
282282
except Exception as e:
283283
_LOGGER.exception(e)
284284

285-
async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
285+
@callback
286+
async def _async_power_sensor_changed(self, event: Event[EventStateChangedData]) -> None:
286287
"""Handle power sensor changes."""
288+
entity_id = event.data["entity_id"]
289+
old_state = event.data["old_state"]
290+
new_state = event.data["new_state"]
291+
287292
if new_state is None:
288293
return
289294

custom_components/smartir/manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"dependencies": [],
66
"codeowners": ["@smartHomeHub"],
77
"requirements": ["aiofiles>=0.6.0"],
8-
"homeassistant": "2024.10.0",
9-
"version": "1.18.0",
8+
"homeassistant": "2025.5.0",
9+
"version": "1.18.1",
1010
"updater": {
11-
"version": "1.18.0",
12-
"releaseNotes": "-- Adds support for light devices",
11+
"version": "1.18.1",
12+
"releaseNotes": "-- Implements new async_track_state_change_event",
1313
"files": [
1414
"__init__.py",
1515
"climate.py",

hacs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "SmartIR",
3-
"homeassistant": "2025.1.0",
3+
"homeassistant": "2025.5.0",
44
"persistent_directory": "codes"
55
}

0 commit comments

Comments
 (0)