diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 479e1e4dab9..c77ec36ccf3 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -494,7 +494,7 @@ class HomeKit: self.status = STATUS_STOPPED _LOGGER.debug("Driver stop") - self.hass.async_add_executor_job(self.driver.stop) + self.hass.add_job(self.driver.stop) @callback def _async_configure_linked_battery_sensors(self, ent_reg, device_lookup, state): diff --git a/homeassistant/components/homekit/accessories.py b/homeassistant/components/homekit/accessories.py index ab3d1ae8507..c3b42f0b6dc 100644 --- a/homeassistant/components/homekit/accessories.py +++ b/homeassistant/components/homekit/accessories.py @@ -165,8 +165,10 @@ class HomeAccessory(Accessory): Run inside the Home Assistant event loop. """ state = self.hass.states.get(self.entity_id) - self.hass.async_add_job(self.update_state_callback, None, None, state) - async_track_state_change(self.hass, self.entity_id, self.update_state_callback) + await self.async_update_state_callback(None, None, state) + async_track_state_change( + self.hass, self.entity_id, self.async_update_state_callback + ) battery_charging_state = None battery_state = None @@ -179,7 +181,7 @@ class HomeAccessory(Accessory): ATTR_BATTERY_CHARGING ) async_track_state_change( - self.hass, self.linked_battery_sensor, self.update_linked_battery + self.hass, self.linked_battery_sensor, self.async_update_linked_battery ) else: battery_state = state.attributes.get(ATTR_BATTERY_LEVEL) @@ -191,7 +193,7 @@ class HomeAccessory(Accessory): async_track_state_change( self.hass, self.linked_battery_charging_sensor, - self.update_linked_battery_charging, + self.async_update_linked_battery_charging, ) elif battery_charging_state is None: battery_charging_state = state.attributes.get(ATTR_BATTERY_CHARGING) @@ -201,8 +203,9 @@ class HomeAccessory(Accessory): self.update_battery, battery_state, battery_charging_state ) - @ha_callback - def update_state_callback(self, entity_id=None, old_state=None, new_state=None): + async def async_update_state_callback( + self, entity_id=None, old_state=None, new_state=None + ): """Handle state change listener callback.""" _LOGGER.debug("New_state: %s", new_state) if new_state is None: @@ -220,28 +223,28 @@ class HomeAccessory(Accessory): ): battery_charging_state = new_state.attributes.get(ATTR_BATTERY_CHARGING) if battery_state is not None or battery_charging_state is not None: - self.hass.async_add_executor_job( + await self.hass.async_add_executor_job( self.update_battery, battery_state, battery_charging_state ) - self.hass.async_add_executor_job(self.update_state, new_state) + await self.hass.async_add_executor_job(self.update_state, new_state) - @ha_callback - def update_linked_battery(self, entity_id=None, old_state=None, new_state=None): + async def async_update_linked_battery( + self, entity_id=None, old_state=None, new_state=None + ): """Handle linked battery sensor state change listener callback.""" if self.linked_battery_charging_sensor: battery_charging_state = None else: battery_charging_state = new_state.attributes.get(ATTR_BATTERY_CHARGING) - self.hass.async_add_executor_job( + await self.hass.async_add_executor_job( self.update_battery, new_state.state, battery_charging_state, ) - @ha_callback - def update_linked_battery_charging( + async def async_update_linked_battery_charging( self, entity_id=None, old_state=None, new_state=None ): """Handle linked battery charging sensor state change listener callback.""" - self.hass.async_add_executor_job( + await self.hass.async_add_executor_job( self.update_battery, None, new_state.state == STATE_ON )