39
39
)
40
40
from homeassistant .core import callback
41
41
from homeassistant .exceptions import PlatformNotReady
42
- from homeassistant .helpers .event import async_track_state_change
42
+ from homeassistant .helpers .event import async_track_state_change_event
43
43
from homeassistant .util .dt import utcnow
44
44
45
45
_LOGGER = logging .getLogger (__name__ )
64
64
ClimateEntityFeature .TARGET_TEMPERATURE
65
65
| ClimateEntityFeature .FAN_MODE
66
66
| ClimateEntityFeature .SWING_MODE
67
+ | ClimateEntityFeature .TURN_OFF
68
+ | ClimateEntityFeature .TURN_ON
67
69
)
68
70
69
71
CONF_SENSOR = "target_sensor"
@@ -255,13 +257,15 @@ def __init__(
255
257
self ._target_temperature = None
256
258
257
259
if sensor_entity_id :
258
- async_track_state_change (hass , sensor_entity_id , self ._async_sensor_changed )
260
+ async_track_state_change_event (
261
+ hass , sensor_entity_id , self ._async_sensor_changed
262
+ )
259
263
sensor_state = hass .states .get (sensor_entity_id )
260
264
if sensor_state :
261
265
self ._async_update_temp (sensor_state )
262
266
263
267
if power_sensor_entity_id :
264
- async_track_state_change (
268
+ async_track_state_change_event (
265
269
hass , power_sensor_entity_id , self ._async_power_sensor_changed
266
270
)
267
271
sensor_state = hass .states .get (power_sensor_entity_id )
@@ -344,7 +348,7 @@ async def async_update(self):
344
348
from miio import DeviceException
345
349
346
350
try :
347
- state = await self .hass .async_add_job (self ._device .status )
351
+ state = await self .hass .async_add_executor_job (self ._device .status )
348
352
_LOGGER .debug ("Got new state: %s" , state )
349
353
350
354
self ._available = True
@@ -542,12 +546,12 @@ async def _send_configuration(self):
542
546
543
547
async def async_learn_command (self , slot , timeout ):
544
548
"""Learn a infrared command."""
545
- await self .hass .async_add_job (self ._device .learn , slot )
549
+ await self .hass .async_add_executor_job (self ._device .learn , slot )
546
550
547
551
_LOGGER .info ("Press the key you want Home Assistant to learn" )
548
552
start_time = utcnow ()
549
553
while (utcnow () - start_time ) < timedelta (seconds = timeout ):
550
- message = await self .hass .async_add_job (self ._device .learn_result )
554
+ message = await self .hass .async_add_executor_job (self ._device .learn_result )
551
555
# FIXME: Improve python-miio here?
552
556
message = message [0 ]
553
557
_LOGGER .debug ("Message received from device: '%s'" , message )
@@ -557,12 +561,12 @@ async def async_learn_command(self, slot, timeout):
557
561
self .hass .components .persistent_notification .async_create (
558
562
log_msg , title = "Xiaomi Miio Remote"
559
563
)
560
- await self .hass .async_add_job (self ._device .learn_stop , slot )
564
+ await self .hass .async_add_executor_job (self ._device .learn_stop , slot )
561
565
return
562
566
563
567
await asyncio .sleep (1 )
564
568
565
- await self .hass .async_add_job (self ._device .learn_stop , slot )
569
+ await self .hass .async_add_executor_job (self ._device .learn_stop , slot )
566
570
_LOGGER .error ("Timeout. No infrared command captured" )
567
571
self .hass .components .persistent_notification .async_create (
568
572
"Timeout. No infrared command captured" , title = "Xiaomi Miio Remote"
0 commit comments