1 """Support for TPLink Omada device firmware updates."""
3 from __future__
import annotations
5 from datetime
import timedelta
6 from typing
import Any, NamedTuple
8 from tplink_omada_client
import OmadaSiteClient
9 from tplink_omada_client.devices
import OmadaFirmwareUpdate, OmadaListDevice
10 from tplink_omada_client.exceptions
import OmadaClientException, RequestFailed
21 from .
import OmadaConfigEntry
22 from .coordinator
import POLL_DEVICES, OmadaCoordinator, OmadaDevicesCoordinator
23 from .entity
import OmadaDeviceEntity
25 POLL_DELAY_UPGRADE = 60
29 """Firmware update information for Omada SDN devices."""
31 device: OmadaListDevice
32 firmware: OmadaFirmwareUpdate |
None
36 """Coordinator for getting details about available firmware updates for Omada devices."""
41 config_entry: OmadaConfigEntry,
42 omada_client: OmadaSiteClient,
43 devices_coordinator: OmadaDevicesCoordinator,
45 """Initialize my coordinator."""
46 super().
__init__(hass, omada_client,
"Firmware Updates", poll_delay=
None)
51 config_entry.async_on_unload(
63 else await self.
omada_clientomada_client.get_firmware_details(d),
72 if any(u.device.fw_download
for u
in updates)
78 async
def poll_update(self) -> dict[str, FirmwareUpdateStatus]:
79 """Poll the state of Omada Devices firmware update availability."""
84 """Handle updated data from the devices coordinator."""
93 config_entry: OmadaConfigEntry,
94 async_add_entities: AddEntitiesCallback,
96 """Set up switches."""
97 controller = config_entry.runtime_data
99 devices = controller.devices_coordinator.data
102 hass, config_entry, controller.omada_client, controller.devices_coordinator
108 await coordinator.async_request_refresh()
112 OmadaDeviceEntity[OmadaFirmwareUpdateCoordinator],
115 """Firmware update status for Omada SDN devices."""
117 _attr_supported_features = (
118 UpdateEntityFeature.INSTALL
119 | UpdateEntityFeature.PROGRESS
120 | UpdateEntityFeature.RELEASE_NOTES
122 _attr_device_class = UpdateDeviceClass.FIRMWARE
126 coordinator: OmadaFirmwareUpdateCoordinator,
127 device: OmadaListDevice,
129 """Initialize the update entity."""
130 super().
__init__(coordinator, device)
138 """Get the release notes for the latest update."""
139 status = self.coordinator.data[self.
_mac_mac]
141 return status.firmware.release_notes
145 self, version: str |
None, backup: bool, **kwargs: Any
147 """Install a firmware update."""
149 await self.
_omada_client_omada_client.start_firmware_upgrade(
150 self.coordinator.data[self.
_mac_mac].device
152 except RequestFailed
as ex:
154 except OmadaClientException
as ex:
156 "Unable to send Firmware update request. Check the controller is online."
163 """Handle updated data from the coordinator."""
164 status = self.coordinator.data[self.
_mac_mac]
166 if status.firmware
and status.device.need_upgrade:
None __init__(self, OmadaFirmwareUpdateCoordinator coordinator, OmadaListDevice device)
str|None release_notes(self)
None async_install(self, str|None version, bool backup, **Any kwargs)
None _handle_coordinator_update(self)
list[FirmwareUpdateStatus] _get_firmware_updates(self)
dict[str, FirmwareUpdateStatus] poll_update(self)
None __init__(self, HomeAssistant hass, OmadaConfigEntry config_entry, OmadaSiteClient omada_client, OmadaDevicesCoordinator devices_coordinator)
None _handle_devices_update(self)
None async_write_ha_state(self)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, OmadaConfigEntry config_entry, AddEntitiesCallback async_add_entities)