Make deep sleep esphome entities unavailable on unexpected disconnect (#95211)

pull/95074/head^2
J. Nick Koston 2023-06-26 07:21:45 -05:00 committed by GitHub
parent 5a98155700
commit 021a39a09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 6 deletions

View File

@ -425,14 +425,20 @@ async def async_setup_entry( # noqa: C901
_async_check_firmware_version(hass, device_info, entry_data.api_version)
_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."""
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:
disconnect_cb()
entry_data.disconnect_callbacks = []
entry_data.available = False
entry_data.expected_disconnect = expected_disconnect
# Mark state as stale so that we will always dispatch
# the next state update of that type when the device reconnects
entry_data.stale_state = {

View File

@ -259,7 +259,7 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
if self._device_info.has_deep_sleep:
# During deep sleep the ESP will not be connectable (by design)
# For these cases, show it as available
return True
return self._entry_data.expected_disconnect
return self._entry_data.available

View File

@ -94,6 +94,7 @@ class RuntimeEntryData:
info: dict[type[EntityInfo], dict[int, EntityInfo]] = field(default_factory=dict)
services: dict[int, UserService] = field(default_factory=dict)
available: bool = False
expected_disconnect: bool = False # Last disconnect was expected (e.g. deep sleep)
device_info: DeviceInfo | None = None
api_version: APIVersion = field(default_factory=APIVersion)
cleanup_callbacks: list[Callable[[], None]] = field(default_factory=list)

View File

@ -15,7 +15,7 @@
"iot_class": "local_push",
"loggers": ["aioesphomeapi", "noiseprotocol"],
"requirements": [
"aioesphomeapi==14.1.1",
"aioesphomeapi==15.0.0",
"bluetooth-data-tools==1.2.0",
"esphome-dashboard-api==1.2.3"
],

View File

@ -234,7 +234,7 @@ aioecowitt==2023.5.0
aioemonitor==1.0.5
# homeassistant.components.esphome
aioesphomeapi==14.1.1
aioesphomeapi==15.0.0
# homeassistant.components.flo
aioflo==2021.11.0

View File

@ -212,7 +212,7 @@ aioecowitt==2023.5.0
aioemonitor==1.0.5
# homeassistant.components.esphome
aioesphomeapi==14.1.1
aioesphomeapi==15.0.0
# homeassistant.components.flo
aioflo==2021.11.0