@@ -302,8 +302,10 @@ async def run_handler(self):
302302 Run inside the Home Assistant event loop.
303303 """
304304 state = self .hass .states .get (self .entity_id )
305- self .hass .async_add_executor_job (self .update_state_callback , None , None , state )
306- async_track_state_change (self .hass , self .entity_id , self .update_state_callback )
305+ await self .async_update_state_callback (None , None , state )
306+ async_track_state_change (
307+ self .hass , self .entity_id , self .async_update_state_callback
308+ )
307309
308310 battery_charging_state = None
309311 battery_state = None
@@ -316,7 +318,7 @@ async def run_handler(self):
316318 ATTR_BATTERY_CHARGING
317319 )
318320 async_track_state_change (
319- self .hass , self .linked_battery_sensor , self .update_linked_battery
321+ self .hass , self .linked_battery_sensor , self .async_update_linked_battery
320322 )
321323 else :
322324 battery_state = state .attributes .get (ATTR_BATTERY_LEVEL )
@@ -328,7 +330,7 @@ async def run_handler(self):
328330 async_track_state_change (
329331 self .hass ,
330332 self .linked_battery_charging_sensor ,
331- self .update_linked_battery_charging ,
333+ self .async_update_linked_battery_charging ,
332334 )
333335 elif battery_charging_state is None :
334336 battery_charging_state = state .attributes .get (ATTR_BATTERY_CHARGING )
@@ -338,8 +340,9 @@ async def run_handler(self):
338340 self .update_battery , battery_state , battery_charging_state
339341 )
340342
341- @ha_callback
342- def update_state_callback (self , entity_id = None , old_state = None , new_state = None ):
343+ async def async_update_state_callback (
344+ self , entity_id = None , old_state = None , new_state = None
345+ ):
343346 """Handle state change listener callback."""
344347 _LOGGER .debug ("New_state: %s" , new_state )
345348 if new_state is None :
@@ -357,28 +360,28 @@ def update_state_callback(self, entity_id=None, old_state=None, new_state=None):
357360 ):
358361 battery_charging_state = new_state .attributes .get (ATTR_BATTERY_CHARGING )
359362 if battery_state is not None or battery_charging_state is not None :
360- self .hass .async_add_executor_job (
363+ await self .hass .async_add_executor_job (
361364 self .update_battery , battery_state , battery_charging_state
362365 )
363- self .hass .async_add_executor_job (self .update_state , new_state )
366+ await self .hass .async_add_executor_job (self .update_state , new_state )
364367
365- @ha_callback
366- def update_linked_battery (self , entity_id = None , old_state = None , new_state = None ):
368+ async def async_update_linked_battery (
369+ self , entity_id = None , old_state = None , new_state = None
370+ ):
367371 """Handle linked battery sensor state change listener callback."""
368372 if self .linked_battery_charging_sensor :
369373 battery_charging_state = None
370374 else :
371375 battery_charging_state = new_state .attributes .get (ATTR_BATTERY_CHARGING )
372- self .hass .async_add_executor_job (
376+ await self .hass .async_add_executor_job (
373377 self .update_battery , new_state .state , battery_charging_state ,
374378 )
375379
376- @ha_callback
377- def update_linked_battery_charging (
380+ async def async_update_linked_battery_charging (
378381 self , entity_id = None , old_state = None , new_state = None
379382 ):
380383 """Handle linked battery charging sensor state change listener callback."""
381- self .hass .async_add_executor_job (
384+ await self .hass .async_add_executor_job (
382385 self .update_battery , None , new_state .state == STATE_ON
383386 )
384387
0 commit comments