1 """Support for Freebox devices (Freebox v6 and Freebox mini 4K)."""
3 from __future__
import annotations
9 BinarySensorDeviceClass,
11 BinarySensorEntityDescription,
19 from .const
import DOMAIN, FreeboxHomeCategory
20 from .entity
import FreeboxHomeEntity
21 from .router
import FreeboxRouter
23 _LOGGER = logging.getLogger(__name__)
26 RAID_SENSORS: tuple[BinarySensorEntityDescription, ...] = (
30 device_class=BinarySensorDeviceClass.PROBLEM,
31 entity_category=EntityCategory.DIAGNOSTIC,
37 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
39 """Set up binary sensors."""
40 router: FreeboxRouter = hass.data[DOMAIN][entry.unique_id]
42 _LOGGER.debug(
"%s - %s - %s raid(s)", router.name, router.mac, len(router.raids))
44 binary_entities: list[BinarySensorEntity] = [
46 for raid
in router.raids.values()
47 for description
in RAID_SENSORS
50 for node
in router.home_devices.values():
51 if node[
"category"] == FreeboxHomeCategory.PIR:
53 elif node[
"category"] == FreeboxHomeCategory.DWS:
56 binary_entities.extend(
58 for endpoint
in node[
"show_endpoints"]
60 endpoint[
"name"] ==
"cover"
61 and endpoint[
"ep_type"] ==
"signal"
62 and endpoint.get(
"value")
is not None
70 """Representation of a Freebox binary sensor."""
72 _sensor_name =
"trigger"
77 router: FreeboxRouter,
79 sub_node: dict[str, Any] |
None =
None,
81 """Initialize a Freebox binary sensor."""
82 super().
__init__(hass, router, node, sub_node)
89 """Update name & state."""
93 await FreeboxHomeEntity.async_update_signal(self)
96 """Edit state depending on sensor name."""
105 """Representation of a Freebox motion binary sensor."""
107 _attr_device_class = BinarySensorDeviceClass.MOTION
111 """Representation of a Freebox door opener binary sensor."""
113 _attr_device_class = BinarySensorDeviceClass.DOOR
117 """Representation of a cover Freebox plastic removal cover binary sensor (for some sensors: motion detector, door opener detector...)."""
119 _attr_device_class = BinarySensorDeviceClass.SAFETY
120 _attr_entity_category = EntityCategory.DIAGNOSTIC
121 _attr_entity_registry_enabled_default =
False
123 _sensor_name =
"cover"
126 self, hass: HomeAssistant, router: FreeboxRouter, node: dict[str, Any]
128 """Initialize a cover for another device."""
132 node[
"type"][
"endpoints"],
136 super().
__init__(hass, router, node, cover_node)
140 """Representation of a Freebox raid sensor."""
142 _attr_should_poll =
False
143 _attr_has_entity_name =
True
147 router: FreeboxRouter,
148 raid: dict[str, Any],
149 description: BinarySensorEntityDescription,
151 """Initialize a Freebox raid degraded sensor."""
156 self.
_attr_name_attr_name = f
"Raid array {raid['id']} {description.name}"
158 f
"{router.mac} {description.key} {raid['name']} {raid['id']}"
163 """Update the Freebox Raid sensor."""
168 """Return true if degraded."""
169 return self.
_raid_raid[
"degraded"]
178 """Register state update callback."""
183 self.
_router_router.signal_sensor_update,
None __init__(self, HomeAssistant hass, FreeboxRouter router, dict[str, Any] node)
bool|None _edit_state(self, bool|None state)
None __init__(self, HomeAssistant hass, FreeboxRouter router, dict[str, Any] node, dict[str, Any]|None sub_node=None)
None async_update_signal(self)
None async_added_to_hass(self)
None async_on_demand_update(self)
None async_update_state(self)
None __init__(self, FreeboxRouter router, dict[str, Any] raid, BinarySensorEntityDescription description)
def get_value(self, str ep_type, str name)
Any|None get_home_endpoint_value(self, Any command_id)
int|None get_command_id(self, nodes, str ep_type, str name)
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)