1 """Platform for update integration."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
9 from devolo_plc_api.device
import Device
10 from devolo_plc_api.device_api
import UpdateFirmwareCheck
11 from devolo_plc_api.exceptions.device
import DevicePasswordProtected, DeviceUnavailable
16 UpdateEntityDescription,
24 from .
import DevoloHomeNetworkConfigEntry
25 from .const
import DOMAIN, REGULAR_FIRMWARE
26 from .coordinator
import DevoloDataUpdateCoordinator
27 from .entity
import DevoloCoordinatorEntity
32 @dataclass(frozen=True, kw_only=True)
34 """Describes devolo update entity."""
36 latest_version: Callable[[UpdateFirmwareCheck], str]
37 update_func: Callable[[Device], Awaitable[bool]]
40 UPDATE_TYPES: dict[str, DevoloUpdateEntityDescription] = {
43 device_class=UpdateDeviceClass.FIRMWARE,
44 entity_category=EntityCategory.CONFIG,
45 latest_version=
lambda data: data.new_firmware_version.split(
"_")[0],
46 update_func=
lambda device: device.device.async_start_firmware_update(),
53 entry: DevoloHomeNetworkConfigEntry,
54 async_add_entities: AddEntitiesCallback,
56 """Get all devices and sensors and setup them via config entry."""
57 coordinators = entry.runtime_data.coordinators
63 coordinators[REGULAR_FIRMWARE],
64 UPDATE_TYPES[REGULAR_FIRMWARE],
71 """Representation of a devolo update."""
73 _attr_supported_features = (
74 UpdateEntityFeature.INSTALL | UpdateEntityFeature.PROGRESS
77 entity_description: DevoloUpdateEntityDescription
81 entry: DevoloHomeNetworkConfigEntry,
82 coordinator: DevoloDataUpdateCoordinator,
83 description: DevoloUpdateEntityDescription,
85 """Initialize entity."""
92 """Version currently in use."""
93 return self.device.firmware_version
97 """Latest version available for install."""
101 return latest_version
102 return self.device.firmware_version
106 """Update installation in progress."""
110 self, version: str |
None, backup: bool, **kwargs: Any
112 """Turn the entity on."""
116 except DevicePasswordProtected
as ex:
117 self.entry.async_start_reauth(self.
hasshass)
119 translation_domain=DOMAIN,
120 translation_key=
"password_protected",
121 translation_placeholders={
"title": self.entry.title},
123 except DeviceUnavailable
as ex:
125 translation_domain=DOMAIN,
126 translation_key=
"no_response",
127 translation_placeholders={
"title": self.entry.title},
None __init__(self, DevoloHomeNetworkConfigEntry entry, DevoloDataUpdateCoordinator coordinator, DevoloUpdateEntityDescription description)
str installed_version(self)
None async_install(self, str|None version, bool backup, **Any kwargs)
str|None installed_version(self)
None async_setup_entry(HomeAssistant hass, DevoloHomeNetworkConfigEntry entry, AddEntitiesCallback async_add_entities)