1 """Representation of ZHA updates."""
3 from __future__
import annotations
9 from zha.exceptions
import ZHAException
10 from zigpy.application
import ControllerApplication
25 DataUpdateCoordinator,
28 from .entity
import ZHAEntity
29 from .helpers
import (
32 async_add_entities
as zha_async_add_entities,
37 _LOGGER = logging.getLogger(__name__)
39 OTA_MESSAGE_BATTERY_POWERED = (
40 "Battery powered devices can sometimes take multiple hours to update and you may"
41 " need to wake the device for the update to begin."
44 ZHA_DOCS_NETWORK_RELIABILITY =
"https://www.home-assistant.io/integrations/zha/#zigbee-interference-avoidance-and-network-rangecoverage-optimization"
45 OTA_MESSAGE_RELIABILITY = (
46 "If you are having issues updating a specific device, make sure that you've"
47 f
" eliminated [common environmental issues]({ZHA_DOCS_NETWORK_RELIABILITY}) that"
48 " could be affecting network reliability. OTA updates require a reliable network."
54 config_entry: ConfigEntry,
55 async_add_entities: AddEntitiesCallback,
57 """Set up the Zigbee Home Automation update from config entry."""
59 if zha_data.update_coordinator
is None:
63 entities_to_create = zha_data.platforms[Platform.UPDATE]
69 zha_async_add_entities,
71 ZHAFirmwareUpdateEntity,
75 config_entry.async_on_unload(unsub)
79 """Firmware update coordinator that broadcasts updates network-wide."""
82 self, hass: HomeAssistant, controller_application: ControllerApplication
84 """Initialize the coordinator."""
88 name=
"ZHA firmware update coordinator",
94 """Fetch the latest firmware update data."""
100 ZHAEntity, CoordinatorEntity[ZHAFirmwareUpdateCoordinator], UpdateEntity
102 """Representation of a ZHA firmware update entity."""
104 _attr_device_class = UpdateDeviceClass.FIRMWARE
105 _attr_supported_features = (
106 UpdateEntityFeature.INSTALL
107 | UpdateEntityFeature.PROGRESS
108 | UpdateEntityFeature.SPECIFIC_VERSION
109 | UpdateEntityFeature.RELEASE_NOTES
111 _attr_display_precision = 2
113 def __init__(self, entity_data: EntityData, **kwargs: Any) ->
None:
114 """Initialize the ZHA siren."""
115 zha_data =
get_zha_data(entity_data.device_proxy.gateway_proxy.hass)
116 assert zha_data.update_coordinator
is not None
118 super().
__init__(entity_data, coordinator=zha_data.update_coordinator, **kwargs)
119 CoordinatorEntity.__init__(self, zha_data.update_coordinator)
123 """Version installed and in use."""
124 return self.entity_data.entity.installed_version
128 """Update installation progress.
130 Should return a boolean (True if in progress, False if not).
132 return self.entity_data.entity.in_progress
136 """Update installation progress.
138 Needs UpdateEntityFeature.PROGRESS flag to be set for it to be used.
140 Can either return a number to indicate the progress from 0 to 100% or None.
142 return self.entity_data.entity.update_percentage
146 """Latest version available for install."""
147 return self.entity_data.entity.latest_version
151 """Summary of the release notes or changelog.
153 This is not suitable for long changelogs, but merely suitable
154 for a short excerpt update description of max 255 characters.
156 return self.entity_data.entity.release_summary
159 """Return full release notes.
161 This is suitable for a long changelog that does not fit in the release_summary
162 property. The returned string can contain markdown.
165 if self.entity_data.device_proxy.device.is_mains_powered:
167 "<ha-alert alert-type='info'>"
168 f
"{OTA_MESSAGE_RELIABILITY}"
173 "<ha-alert alert-type='info'>"
174 f
"{OTA_MESSAGE_BATTERY_POWERED} {OTA_MESSAGE_RELIABILITY}"
178 return f
"{header}\n\n{self.entity_data.entity.release_notes or ''}"
182 """URL to the full release notes of the latest version available."""
183 return self.entity_data.entity.release_url
188 self, version: str |
None, backup: bool, **kwargs: Any
190 """Install an update."""
192 await self.entity_data.entity.async_install(version=version)
193 except ZHAException
as exc:
199 """Update the entity."""
200 await CoordinatorEntity.async_update(self)
None __init__(self, HomeAssistant hass, ControllerApplication controller_application)
None async_update_data(self)
str|None release_summary(self)
str|None release_url(self)
str|None latest_version(self)
None async_install(self, str|None version, bool backup, **Any kwargs)
None __init__(self, EntityData entity_data, **Any kwargs)
int|float|None update_percentage(self)
str|None async_release_notes(self)
bool|int|None in_progress(self)
None async_write_ha_state(self)
Gateway get_zha_gateway(HomeAssistant hass)
HAZHAData get_zha_data(HomeAssistant hass)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)