Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/homekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ async def async_stop(self, *args):
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):
Expand Down
31 changes: 17 additions & 14 deletions homeassistant/components/homekit/accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ async def run_handler(self):
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
Expand All @@ -179,7 +181,7 @@ async def run_handler(self):
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)
Expand All @@ -191,7 +193,7 @@ async def run_handler(self):
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)
Expand All @@ -201,8 +203,9 @@ async def run_handler(self):
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:
Expand All @@ -220,28 +223,28 @@ def update_state_callback(self, entity_id=None, old_state=None, new_state=None):
):
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
)

Expand Down