1 """Update platform for Supervisor."""
3 from __future__
import annotations
7 from aiohasupervisor
import SupervisorError
8 from aiohasupervisor.models
import (
9 HomeAssistantUpdateOptions,
13 from awesomeversion
import AwesomeVersion, AwesomeVersionStrategy
17 UpdateEntityDescription,
41 HassioSupervisorEntity,
46 key=ATTR_VERSION_LATEST,
52 config_entry: ConfigEntry,
53 async_add_entities: AddEntitiesCallback,
55 """Set up Supervisor update based on a config entry."""
56 coordinator = hass.data[ADDONS_COORDINATOR]
60 coordinator=coordinator,
61 entity_description=ENTITY_DESCRIPTION,
64 coordinator=coordinator,
65 entity_description=ENTITY_DESCRIPTION,
72 coordinator=coordinator,
73 entity_description=ENTITY_DESCRIPTION,
75 for addon
in coordinator.data[DATA_KEY_ADDONS].values()
78 if coordinator.is_hass_os:
81 coordinator=coordinator,
82 entity_description=ENTITY_DESCRIPTION,
90 """Update entity to handle updates for the Supervisor add-ons."""
92 _attr_supported_features = (
93 UpdateEntityFeature.INSTALL
94 | UpdateEntityFeature.BACKUP
95 | UpdateEntityFeature.RELEASE_NOTES
100 """Return the add-on data."""
101 return self.coordinator.data[DATA_KEY_ADDONS][self.
_addon_slug_addon_slug]
105 """Return true if auto-update is enabled for the add-on."""
106 return self.
_addon_data_addon_data[ATTR_AUTO_UPDATE]
110 """Return the title of the update."""
115 """Latest version available for install."""
116 return self.
_addon_data_addon_data[ATTR_VERSION_LATEST]
120 """Version installed and in use."""
125 """Release summary for the add-on."""
130 """Return the icon of the add-on if any."""
134 return f
"/api/hassio/addons/{self._addon_slug}/icon"
138 """Strip the release notes to contain the needed sections."""
139 if (notes := self.
_addon_data_addon_data[ATTR_CHANGELOG])
is None:
143 f
"# {self.latest_version}" in notes
144 and f
"# {self.installed_version}" in notes
147 new_notes = notes.split(f
"# {self.installed_version}")[0]
148 if f
"# {self.latest_version}" in new_notes:
156 """Return the release notes for the update."""
161 version: str |
None =
None,
162 backup: bool =
False,
165 """Install an update."""
167 await self.coordinator.supervisor_client.store.update_addon(
168 self.
_addon_slug_addon_slug, StoreAddonUpdate(backup=backup)
170 except SupervisorError
as err:
177 """Update entity to handle updates for the Home Assistant Operating System."""
179 _attr_supported_features = (
180 UpdateEntityFeature.INSTALL | UpdateEntityFeature.SPECIFIC_VERSION
182 _attr_title =
"Home Assistant Operating System"
186 """Return the latest version."""
187 return self.coordinator.data[DATA_KEY_OS][ATTR_VERSION_LATEST]
191 """Return the installed version."""
192 return self.coordinator.data[DATA_KEY_OS][ATTR_VERSION]
196 """Return the icon of the entity."""
197 return "https://brands.home-assistant.io/homeassistant/icon.png"
201 """URL to the full release notes of the latest version available."""
203 if version.dev
or version.strategy == AwesomeVersionStrategy.UNKNOWN:
204 return "https://github.com/home-assistant/operating-system/commits/dev"
206 f
"https://github.com/home-assistant/operating-system/releases/tag/{version}"
210 self, version: str |
None, backup: bool, **kwargs: Any
212 """Install an update."""
214 await self.coordinator.supervisor_client.os.update(
215 OSUpdate(version=version)
217 except SupervisorError
as err:
219 f
"Error updating Home Assistant Operating System: {err}"
224 """Update entity to handle updates for the Home Assistant Supervisor."""
226 _attr_supported_features = UpdateEntityFeature.INSTALL
227 _attr_title =
"Home Assistant Supervisor"
231 """Return the latest version."""
232 return self.coordinator.data[DATA_KEY_SUPERVISOR][ATTR_VERSION_LATEST]
236 """Return the installed version."""
237 return self.coordinator.data[DATA_KEY_SUPERVISOR][ATTR_VERSION]
241 """Return true if auto-update is enabled for supervisor."""
242 return self.coordinator.data[DATA_KEY_SUPERVISOR][ATTR_AUTO_UPDATE]
246 """URL to the full release notes of the latest version available."""
248 if version.dev
or version.strategy == AwesomeVersionStrategy.UNKNOWN:
249 return "https://github.com/home-assistant/supervisor/commits/main"
250 return f
"https://github.com/home-assistant/supervisor/releases/tag/{version}"
254 """Return the icon of the entity."""
255 return "https://brands.home-assistant.io/hassio/icon.png"
258 self, version: str |
None, backup: bool, **kwargs: Any
260 """Install an update."""
262 await self.coordinator.supervisor_client.supervisor.update()
263 except SupervisorError
as err:
265 f
"Error updating Home Assistant Supervisor: {err}"
270 """Update entity to handle updates for Home Assistant Core."""
272 _attr_supported_features = (
273 UpdateEntityFeature.INSTALL
274 | UpdateEntityFeature.SPECIFIC_VERSION
275 | UpdateEntityFeature.BACKUP
277 _attr_title =
"Home Assistant Core"
281 """Return the latest version."""
282 return self.coordinator.data[DATA_KEY_CORE][ATTR_VERSION_LATEST]
286 """Return the installed version."""
287 return self.coordinator.data[DATA_KEY_CORE][ATTR_VERSION]
291 """Return the icon of the entity."""
292 return "https://brands.home-assistant.io/homeassistant/icon.png"
296 """URL to the full release notes of the latest version available."""
299 return "https://github.com/home-assistant/core/commits/dev"
300 return f
"https://{'rc' if version.beta else 'www'}.home-assistant.io/latest-release-notes/"
303 self, version: str |
None, backup: bool, **kwargs: Any
305 """Install an update."""
307 await self.coordinator.supervisor_client.homeassistant.update(
308 HomeAssistantUpdateOptions(version=version, backup=backup)
310 except SupervisorError
as err:
312 f
"Error updating Home Assistant Core: {err}"
None force_info_update_supervisor(self)
str|None release_summary(self)
None async_install(self, str|None version=None, bool backup=False, **Any kwargs)
str|None _strip_release_notes(self)
str|None latest_version(self)
str|None async_release_notes(self)
str|None entity_picture(self)
str|None entity_picture(self)
str|None release_url(self)
None async_install(self, str|None version, bool backup, **Any kwargs)
None async_install(self, str|None version, bool backup, **Any kwargs)
str|None release_url(self)
str|None entity_picture(self)
str|None release_url(self)
str|None entity_picture(self)
None async_install(self, str|None version, bool backup, **Any kwargs)
str|None latest_version(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)