1 """AVM FRITZ!Tools entities."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
9 from fritzconnection.lib.fritzstatus
import FritzStatus
16 from .const
import DEFAULT_DEVICE_NAME, DOMAIN
17 from .coordinator
import AvmWrapper, FritzDevice
21 """Entity base class for a device connected to a FRITZ!Box device."""
23 def __init__(self, avm_wrapper: AvmWrapper, device: FritzDevice) ->
None:
24 """Initialize a FRITZ!Box device."""
27 self._mac: str = device.mac_address
28 self._name: str = device.hostname
or DEFAULT_DEVICE_NAME
32 """Return device name."""
37 """Return the primary ip address of the device."""
39 return self.
_avm_wrapper_avm_wrapper.devices[self._mac].ip_address
44 """Return the mac address of the device."""
49 """Return hostname of the device."""
51 return self.
_avm_wrapper_avm_wrapper.devices[self._mac].hostname
56 raise NotImplementedError
61 self.async_write_ha_state()
65 """Fritz host entity base class."""
67 def __init__(self, avm_wrapper: AvmWrapper, device_name: str) ->
None:
68 """Init device info class."""
74 """Return the mac address of the main device."""
79 """Return the device information."""
81 configuration_url=f
"http://{self._avm_wrapper.host}",
82 connections={(dr.CONNECTION_NETWORK_MAC, self.
mac_addressmac_address)},
83 identifiers={(DOMAIN, self.
_avm_wrapper_avm_wrapper.unique_id)},
87 sw_version=self.
_avm_wrapper_avm_wrapper.current_firmware,
91 @dataclass(frozen=True, kw_only=True)
93 """Fritz entity base description."""
95 value_fn: Callable[[FritzStatus, Any], Any] |
None
99 """Fritz host coordinator entity base class."""
101 entity_description: FritzEntityDescription
102 _attr_has_entity_name =
True
106 avm_wrapper: AvmWrapper,
108 description: FritzEntityDescription,
110 """Init device info class."""
117 """When entity is added to hass."""
120 self.async_on_remove(
128 """Return the device information."""
130 configuration_url=f
"http://{self.coordinator.host}",
131 connections={(dr.CONNECTION_NETWORK_MAC, self.coordinator.mac)},
132 identifiers={(DOMAIN, self.coordinator.unique_id)},
134 model=self.coordinator.model,
136 sw_version=self.coordinator.current_firmware,
None __init__(self, AvmWrapper avm_wrapper, str device_name, FritzEntityDescription description)
DeviceInfo device_info(self)
None async_added_to_hass(self)
None __init__(self, AvmWrapper avm_wrapper, str device_name)
DeviceInfo device_info(self)
None __init__(self, AvmWrapper avm_wrapper, FritzDevice device)
str|None ip_address(self)
None async_on_demand_update(self)
None async_process_update(self)