1 """Support for SLZB-06 binary sensors."""
3 from __future__
import annotations
5 from _collections_abc
import Callable
6 from dataclasses
import dataclass
8 from pysmlight
import Sensors
9 from pysmlight.const
import Events
as SmEvents
10 from pysmlight.sse
import MessageEvent
13 BinarySensorDeviceClass,
15 BinarySensorEntityDescription,
22 from .const
import SCAN_INTERNET_INTERVAL
23 from .coordinator
import SmDataUpdateCoordinator
24 from .entity
import SmEntity
26 SCAN_INTERVAL = SCAN_INTERNET_INTERVAL
29 @dataclass(frozen=True, kw_only=True)
31 """Class describing SMLIGHT binary sensor entities."""
33 value_fn: Callable[[Sensors], bool]
39 translation_key=
"ethernet",
40 value_fn=
lambda x: x.ethernet,
44 translation_key=
"vpn",
45 entity_registry_enabled_default=
False,
46 value_fn=
lambda x: x.vpn_status,
50 translation_key=
"wifi",
51 entity_registry_enabled_default=
False,
52 value_fn=
lambda x: x.wifi_connected,
60 async_add_entities: AddEntitiesCallback,
62 """Set up SMLIGHT sensor based on a config entry."""
63 coordinator = entry.runtime_data.data
69 for description
in SENSORS
77 """Representation of a slzb binary sensor."""
79 entity_description: SmBinarySensorEntityDescription
80 _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
81 _attr_entity_category = EntityCategory.DIAGNOSTIC
85 coordinator: SmDataUpdateCoordinator,
86 description: SmBinarySensorEntityDescription,
88 """Initialize slzb binary sensor."""
92 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.unique_id}_{description.key}"
96 """Return the state of the sensor."""
101 """Representation of the SLZB internet sensor."""
103 _attr_translation_key =
"internet"
104 _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
105 _attr_entity_category = EntityCategory.DIAGNOSTIC
109 coordinator: SmDataUpdateCoordinator,
111 """Initialize slzb binary sensor."""
113 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.unique_id}_{self._attr_translation_key}"
116 """Run when entity about to be added to hass."""
119 self.coordinator.client.sse.register_callback(
127 """Update internet state from event."""
133 """Poll entity for internet connected updates."""
137 """Update the sensor.
139 This is an async api, device will respond with EVENT_INET_STATE event.
141 await self.coordinator.client.get_param(
"inetState")
None __init__(self, SmDataUpdateCoordinator coordinator, SmBinarySensorEntityDescription description)
None internet_callback(self, MessageEvent event)
None __init__(self, SmDataUpdateCoordinator coordinator)
None async_added_to_hass(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)