1 """Support for Freebox devices (Freebox v6 and Freebox mini 4K)."""
3 from __future__
import annotations
11 SensorEntityDescription,
21 from .const
import DOMAIN
22 from .entity
import FreeboxHomeEntity
23 from .router
import FreeboxRouter
25 _LOGGER = logging.getLogger(__name__)
27 CONNECTION_SENSORS: tuple[SensorEntityDescription, ...] = (
30 name=
"Freebox download speed",
31 device_class=SensorDeviceClass.DATA_RATE,
32 native_unit_of_measurement=UnitOfDataRate.KILOBYTES_PER_SECOND,
33 icon=
"mdi:download-network",
37 name=
"Freebox upload speed",
38 device_class=SensorDeviceClass.DATA_RATE,
39 native_unit_of_measurement=UnitOfDataRate.KILOBYTES_PER_SECOND,
40 icon=
"mdi:upload-network",
44 CALL_SENSORS: tuple[SensorEntityDescription, ...] = (
47 name=
"Freebox missed calls",
48 icon=
"mdi:phone-missed",
52 DISK_PARTITION_SENSORS: tuple[SensorEntityDescription, ...] = (
54 key=
"partition_free_space",
56 native_unit_of_measurement=PERCENTAGE,
63 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
65 """Set up the sensors."""
66 router: FreeboxRouter = hass.data[DOMAIN][entry.unique_id]
67 entities: list[SensorEntity] = []
70 "%s - %s - %s temperature sensors",
73 len(router.sensors_temperature),
80 name=f
"Freebox {sensor_name}",
81 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
82 device_class=SensorDeviceClass.TEMPERATURE,
85 for sensor_name
in router.sensors_temperature
89 [
FreeboxSensor(router, description)
for description
in CONNECTION_SENSORS]
95 _LOGGER.debug(
"%s - %s - %s disk(s)", router.name, router.mac, len(router.disks))
98 for disk
in router.disks.values()
99 for partition
in disk[
"partitions"].values()
100 for description
in DISK_PARTITION_SENSORS
103 for node
in router.home_devices.values():
104 for endpoint
in node[
"show_endpoints"]:
106 endpoint[
"name"] ==
"battery"
107 and endpoint[
"ep_type"] ==
"signal"
108 and endpoint.get(
"value")
is not None
117 """Representation of a Freebox sensor."""
119 _attr_should_poll =
False
122 self, router: FreeboxRouter, description: SensorEntityDescription
124 """Initialize a Freebox sensor."""
132 """Update the Freebox sensor."""
146 """Register state update callback."""
151 self.
_router_router.signal_sensor_update,
158 """Representation of a Freebox call sensor."""
161 self, router: FreeboxRouter, description: SensorEntityDescription
163 """Initialize a Freebox call sensor."""
164 super().
__init__(router, description)
169 """Update the Freebox call sensor."""
171 if self.
_router_router.call_list:
172 for call
in self.
_router_router.call_list:
182 """Return device specific state attributes."""
184 dt_util.utc_from_timestamp(call[
"datetime"]).isoformat(): call[
"name"]
190 """Representation of a Freebox disk sensor."""
194 router: FreeboxRouter,
195 disk: dict[str, Any],
196 partition: dict[str, Any],
197 description: SensorEntityDescription,
199 """Initialize a Freebox disk sensor."""
200 super().
__init__(router, description)
203 self.
_attr_name_attr_name = f
"{partition['label']} {description.name}"
205 f
"{router.mac} {description.key} {disk['id']} {partition['id']}"
209 identifiers={(DOMAIN, disk[
"id"])},
211 name=f
"Disk {disk['id']}",
212 sw_version=disk[
"firmware"],
221 """Update the Freebox disk sensor."""
223 disk: dict[str, Any] = self.
_router_router.disks[self.
_disk_id_disk_id]
224 partition: dict[str, Any] = disk[
"partitions"][self.
_partition_id_partition_id]
225 if partition.get(
"total_bytes"):
226 value = round(partition[
"free_bytes"] * 100 / partition[
"total_bytes"], 2)
231 """Representation of a Freebox battery sensor."""
233 _attr_device_class = SensorDeviceClass.BATTERY
234 _attr_native_unit_of_measurement = PERCENTAGE
238 """Return the current state of the device."""
239 return self.
get_valueget_value(
"signal",
"battery")
def get_value(self, str ep_type, str name)
dict[str, Any] extra_state_attributes(self)
None async_update_state(self)
None __init__(self, FreeboxRouter router, SensorEntityDescription description)
None __init__(self, FreeboxRouter router, dict[str, Any] disk, dict[str, Any] partition, SensorEntityDescription description)
None async_update_state(self)
None async_update_state(self)
None async_on_demand_update(self)
None async_added_to_hass(self)
None __init__(self, FreeboxRouter router, SensorEntityDescription description)
native_unit_of_measurement
str|None native_unit_of_measurement(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)