mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Migrate esphome to use shorthand available attr (#121827)
This commit is contained in:
parent
adb88f0165
commit
df8c949884
@ -190,13 +190,13 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self._entry_data = entry_data
|
self._entry_data = entry_data
|
||||||
|
assert entry_data.device_info is not None
|
||||||
|
device_info = entry_data.device_info
|
||||||
|
self._device_info = device_info
|
||||||
self._on_entry_data_changed()
|
self._on_entry_data_changed()
|
||||||
self._key = entity_info.key
|
self._key = entity_info.key
|
||||||
self._state_type = state_type
|
self._state_type = state_type
|
||||||
self._on_static_info_update(entity_info)
|
self._on_static_info_update(entity_info)
|
||||||
assert entry_data.device_info is not None
|
|
||||||
device_info = entry_data.device_info
|
|
||||||
self._device_info = device_info
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, device_info.mac_address)}
|
connections={(dr.CONNECTION_NETWORK_MAC, device_info.mac_address)}
|
||||||
)
|
)
|
||||||
@ -288,6 +288,12 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
|
|||||||
entry_data = self._entry_data
|
entry_data = self._entry_data
|
||||||
self._api_version = entry_data.api_version
|
self._api_version = entry_data.api_version
|
||||||
self._client = entry_data.client
|
self._client = entry_data.client
|
||||||
|
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
|
||||||
|
self._attr_available = entry_data.expected_disconnect
|
||||||
|
else:
|
||||||
|
self._attr_available = entry_data.available
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _on_device_update(self) -> None:
|
def _on_device_update(self) -> None:
|
||||||
@ -300,16 +306,6 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
|
|||||||
# through the next entity state packet.
|
# through the next entity state packet.
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self) -> bool:
|
|
||||||
"""Return if the entity is available."""
|
|
||||||
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 self._entry_data.expected_disconnect
|
|
||||||
|
|
||||||
return self._entry_data.available
|
|
||||||
|
|
||||||
|
|
||||||
class EsphomeAssistEntity(Entity):
|
class EsphomeAssistEntity(Entity):
|
||||||
"""Define a base entity for Assist Pipeline entities."""
|
"""Define a base entity for Assist Pipeline entities."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user