1 """Platform for binary sensor integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from devolo_plc_api.plcnet_api
import LogicalNetwork
11 BinarySensorDeviceClass,
13 BinarySensorEntityDescription,
19 from .
import DevoloHomeNetworkConfigEntry
20 from .const
import CONNECTED_PLC_DEVICES, CONNECTED_TO_ROUTER
21 from .coordinator
import DevoloDataUpdateCoordinator
22 from .entity
import DevoloCoordinatorEntity
28 """Check, if device is attached to the router."""
30 device.attached_to_router
31 for device
in entity.coordinator.data.devices
32 if device.mac_address == entity.device.mac
36 @dataclass(frozen=True, kw_only=True)
38 """Describes devolo sensor entity."""
40 value_func: Callable[[DevoloBinarySensorEntity], bool]
43 SENSOR_TYPES: dict[str, DevoloBinarySensorEntityDescription] = {
45 key=CONNECTED_TO_ROUTER,
46 device_class=BinarySensorDeviceClass.PLUG,
47 entity_category=EntityCategory.DIAGNOSTIC,
48 entity_registry_enabled_default=
False,
49 value_func=_is_connected_to_router,
56 entry: DevoloHomeNetworkConfigEntry,
57 async_add_entities: AddEntitiesCallback,
59 """Get all devices and sensors and setup them via config entry."""
60 coordinators = entry.runtime_data.coordinators
62 entities: list[BinarySensorEntity] = []
66 coordinators[CONNECTED_PLC_DEVICES],
67 SENSOR_TYPES[CONNECTED_TO_ROUTER],
74 DevoloCoordinatorEntity[LogicalNetwork], BinarySensorEntity
76 """Representation of a devolo binary sensor."""
80 entry: DevoloHomeNetworkConfigEntry,
81 coordinator: DevoloDataUpdateCoordinator[LogicalNetwork],
82 description: DevoloBinarySensorEntityDescription,
84 """Initialize entity."""
85 self.entity_description: DevoloBinarySensorEntityDescription = description
90 """State of the binary sensor."""
91 return self.entity_description.
value_func(self)
None __init__(self, DevoloHomeNetworkConfigEntry entry, DevoloDataUpdateCoordinator[LogicalNetwork] coordinator, DevoloBinarySensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, DevoloHomeNetworkConfigEntry entry, AddEntitiesCallback async_add_entities)
bool _is_connected_to_router(DevoloBinarySensorEntity entity)