Home Assistant Unofficial Reference 2024.12.1
update.py
Go to the documentation of this file.
1 """Support for AVM FRITZ!Box update platform."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 import logging
7 from typing import Any
8 
10  UpdateEntity,
11  UpdateEntityDescription,
12  UpdateEntityFeature,
13 )
14 from homeassistant.config_entries import ConfigEntry
15 from homeassistant.const import EntityCategory
16 from homeassistant.core import HomeAssistant
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 
19 from .const import DOMAIN
20 from .coordinator import AvmWrapper
21 from .entity import FritzBoxBaseCoordinatorEntity, FritzEntityDescription
22 
23 _LOGGER = logging.getLogger(__name__)
24 
25 
26 @dataclass(frozen=True, kw_only=True)
28  """Describes Fritz update entity."""
29 
30 
32  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
33 ) -> None:
34  """Set up AVM FRITZ!Box update entities."""
35  _LOGGER.debug("Setting up AVM FRITZ!Box update entities")
36  avm_wrapper: AvmWrapper = hass.data[DOMAIN][entry.entry_id]
37 
38  entities = [FritzBoxUpdateEntity(avm_wrapper, entry.title)]
39 
40  async_add_entities(entities)
41 
42 
44  """Mixin for update entity specific attributes."""
45 
46  _attr_entity_category = EntityCategory.CONFIG
47  _attr_supported_features = UpdateEntityFeature.INSTALL
48  _attr_title = "FRITZ!OS"
49  entity_description: FritzUpdateEntityDescription
50 
51  def __init__(
52  self,
53  avm_wrapper: AvmWrapper,
54  device_friendly_name: str,
55  ) -> None:
56  """Init FRITZ!Box connectivity class."""
57  description = FritzUpdateEntityDescription(
58  key="update", name="FRITZ!OS", value_fn=None
59  )
60  super().__init__(avm_wrapper, device_friendly_name, description)
61 
62  @property
63  def installed_version(self) -> str | None:
64  """Version currently in use."""
65  return self.coordinator.current_firmware
66 
67  @property
68  def latest_version(self) -> str | None:
69  """Latest version available for install."""
70  if self.coordinator.update_available:
71  return self.coordinator.latest_firmware
72  return self.coordinator.current_firmware
73 
74  @property
75  def release_url(self) -> str | None:
76  """URL to the full release notes of the latest version available."""
77  return self.coordinator.release_url
78 
79  async def async_install(
80  self, version: str | None, backup: bool, **kwargs: Any
81  ) -> None:
82  """Install an update."""
83  await self.coordinator.async_trigger_firmware_update()
None async_install(self, str|None version, bool backup, **Any kwargs)
Definition: update.py:81
None __init__(self, AvmWrapper avm_wrapper, str device_friendly_name)
Definition: update.py:55
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: update.py:33