ESPHome update: Store reference to runtime data, not one of its values (#86762)

Store reference to runtime data, not one of its values
This commit is contained in:
Paulus Schoutsen 2023-01-26 21:45:42 -05:00 committed by GitHub
parent e738924780
commit 687184138c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,15 +72,13 @@ class ESPHomeUpdateEntity(CoordinatorEntity[ESPHomeDashboard], UpdateEntity):
_attr_title = "ESPHome" _attr_title = "ESPHome"
_attr_name = "Firmware" _attr_name = "Firmware"
_device_info: ESPHomeDeviceInfo
def __init__( def __init__(
self, entry_data: RuntimeEntryData, coordinator: ESPHomeDashboard self, entry_data: RuntimeEntryData, coordinator: ESPHomeDashboard
) -> None: ) -> None:
"""Initialize the update entity.""" """Initialize the update entity."""
super().__init__(coordinator=coordinator) super().__init__(coordinator=coordinator)
assert entry_data.device_info is not None assert entry_data.device_info is not None
self._device_info = entry_data.device_info self._entry_data = entry_data
self._attr_unique_id = entry_data.device_info.mac_address self._attr_unique_id = entry_data.device_info.mac_address
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
connections={ connections={
@ -88,6 +86,12 @@ class ESPHomeUpdateEntity(CoordinatorEntity[ESPHomeDashboard], UpdateEntity):
} }
) )
@property
def _device_info(self) -> ESPHomeDeviceInfo:
"""Return the device info."""
assert self._entry_data.device_info is not None
return self._entry_data.device_info
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Return if update is available.""" """Return if update is available."""