mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Make deep sleep esphome entities unavailable on unexpected disconnect (#95211)
This commit is contained in:
parent
5a98155700
commit
021a39a09c
@ -425,14 +425,20 @@ async def async_setup_entry( # noqa: C901
|
|||||||
_async_check_firmware_version(hass, device_info, entry_data.api_version)
|
_async_check_firmware_version(hass, device_info, entry_data.api_version)
|
||||||
_async_check_using_api_password(hass, device_info, bool(password))
|
_async_check_using_api_password(hass, device_info, bool(password))
|
||||||
|
|
||||||
async def on_disconnect() -> None:
|
async def on_disconnect(expected_disconnect: bool) -> None:
|
||||||
"""Run disconnect callbacks on API disconnect."""
|
"""Run disconnect callbacks on API disconnect."""
|
||||||
name = entry_data.device_info.name if entry_data.device_info else host
|
name = entry_data.device_info.name if entry_data.device_info else host
|
||||||
_LOGGER.debug("%s: %s disconnected, running disconnected callbacks", name, host)
|
_LOGGER.debug(
|
||||||
|
"%s: %s disconnected (expected=%s), running disconnected callbacks",
|
||||||
|
name,
|
||||||
|
host,
|
||||||
|
expected_disconnect,
|
||||||
|
)
|
||||||
for disconnect_cb in entry_data.disconnect_callbacks:
|
for disconnect_cb in entry_data.disconnect_callbacks:
|
||||||
disconnect_cb()
|
disconnect_cb()
|
||||||
entry_data.disconnect_callbacks = []
|
entry_data.disconnect_callbacks = []
|
||||||
entry_data.available = False
|
entry_data.available = False
|
||||||
|
entry_data.expected_disconnect = expected_disconnect
|
||||||
# Mark state as stale so that we will always dispatch
|
# Mark state as stale so that we will always dispatch
|
||||||
# the next state update of that type when the device reconnects
|
# the next state update of that type when the device reconnects
|
||||||
entry_data.stale_state = {
|
entry_data.stale_state = {
|
||||||
|
@ -259,7 +259,7 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
|
|||||||
if self._device_info.has_deep_sleep:
|
if self._device_info.has_deep_sleep:
|
||||||
# During deep sleep the ESP will not be connectable (by design)
|
# During deep sleep the ESP will not be connectable (by design)
|
||||||
# For these cases, show it as available
|
# For these cases, show it as available
|
||||||
return True
|
return self._entry_data.expected_disconnect
|
||||||
|
|
||||||
return self._entry_data.available
|
return self._entry_data.available
|
||||||
|
|
||||||
|
@ -94,6 +94,7 @@ class RuntimeEntryData:
|
|||||||
info: dict[type[EntityInfo], dict[int, EntityInfo]] = field(default_factory=dict)
|
info: dict[type[EntityInfo], dict[int, EntityInfo]] = field(default_factory=dict)
|
||||||
services: dict[int, UserService] = field(default_factory=dict)
|
services: dict[int, UserService] = field(default_factory=dict)
|
||||||
available: bool = False
|
available: bool = False
|
||||||
|
expected_disconnect: bool = False # Last disconnect was expected (e.g. deep sleep)
|
||||||
device_info: DeviceInfo | None = None
|
device_info: DeviceInfo | None = None
|
||||||
api_version: APIVersion = field(default_factory=APIVersion)
|
api_version: APIVersion = field(default_factory=APIVersion)
|
||||||
cleanup_callbacks: list[Callable[[], None]] = field(default_factory=list)
|
cleanup_callbacks: list[Callable[[], None]] = field(default_factory=list)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"loggers": ["aioesphomeapi", "noiseprotocol"],
|
"loggers": ["aioesphomeapi", "noiseprotocol"],
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"aioesphomeapi==14.1.1",
|
"aioesphomeapi==15.0.0",
|
||||||
"bluetooth-data-tools==1.2.0",
|
"bluetooth-data-tools==1.2.0",
|
||||||
"esphome-dashboard-api==1.2.3"
|
"esphome-dashboard-api==1.2.3"
|
||||||
],
|
],
|
||||||
|
@ -234,7 +234,7 @@ aioecowitt==2023.5.0
|
|||||||
aioemonitor==1.0.5
|
aioemonitor==1.0.5
|
||||||
|
|
||||||
# homeassistant.components.esphome
|
# homeassistant.components.esphome
|
||||||
aioesphomeapi==14.1.1
|
aioesphomeapi==15.0.0
|
||||||
|
|
||||||
# homeassistant.components.flo
|
# homeassistant.components.flo
|
||||||
aioflo==2021.11.0
|
aioflo==2021.11.0
|
||||||
|
@ -212,7 +212,7 @@ aioecowitt==2023.5.0
|
|||||||
aioemonitor==1.0.5
|
aioemonitor==1.0.5
|
||||||
|
|
||||||
# homeassistant.components.esphome
|
# homeassistant.components.esphome
|
||||||
aioesphomeapi==14.1.1
|
aioesphomeapi==15.0.0
|
||||||
|
|
||||||
# homeassistant.components.flo
|
# homeassistant.components.flo
|
||||||
aioflo==2021.11.0
|
aioflo==2021.11.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user