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
17 changes: 14 additions & 3 deletions homeassistant/components/esphome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ async def async_added_to_hass(self) -> None:
}
self._remove_callbacks.append(
async_dispatcher_connect(
self.hass, DISPATCHER_UPDATE_ENTITY.format(**kwargs), self._on_update
self.hass,
DISPATCHER_UPDATE_ENTITY.format(**kwargs),
self._on_state_update,
)
)

Expand All @@ -493,14 +495,23 @@ async def async_added_to_hass(self) -> None:
async_dispatcher_connect(
self.hass,
DISPATCHER_ON_DEVICE_UPDATE.format(**kwargs),
self.async_schedule_update_ha_state,
self._on_device_update,
)
)

async def _on_update(self) -> None:
async def _on_state_update(self) -> None:
Comment thread
pvizeli marked this conversation as resolved.
"""Update the entity state when state or static info changed."""
self.async_schedule_update_ha_state()

async def _on_device_update(self) -> None:
"""Update the entity state when device info has changed."""
if self._entry_data.available:
# Don't update the HA state yet when the device comes online.
# Only update the HA state when the full state arrives
# through the next entity state packet.
return
self.async_schedule_update_ha_state()

async def async_will_remove_from_hass(self) -> None:
"""Unregister callbacks."""
for remove_callback in self._remove_callbacks:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/esphome/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def _static_info(self) -> CameraInfo:
def _state(self) -> Optional[CameraState]:
return super()._state

async def _on_update(self) -> None:
async def _on_state_update(self) -> None:
"""Notify listeners of new image when update arrives."""
await super()._on_update()
await super()._on_state_update()
async with self._image_cond:
self._image_cond.notify_all()

Expand Down