diff --git a/homeassistant/components/esphome/__init__.py b/homeassistant/components/esphome/__init__.py index bc06aba94ead87c1739f565ed2a51ee3a4d83c24..dd4ac699089922675efc809ac2b6330139a2f75b 100644 --- a/homeassistant/components/esphome/__init__.py +++ b/homeassistant/components/esphome/__init__.py @@ -479,7 +479,9 @@ class EsphomeEntity(Entity): } 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, ) ) @@ -493,14 +495,23 @@ class EsphomeEntity(Entity): 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: """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: diff --git a/homeassistant/components/esphome/camera.py b/homeassistant/components/esphome/camera.py index cc2e0cede2361a820d407dda6ee1a46ec5511d3b..c3615c4726d408fe3b59e10a5c44df4be4a70182 100644 --- a/homeassistant/components/esphome/camera.py +++ b/homeassistant/components/esphome/camera.py @@ -47,9 +47,9 @@ class EsphomeCamera(Camera, EsphomeEntity): 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()