11import logging
2+ from dataclasses import dataclass
23
34from homeassistant .components .binary_sensor import (
45 BinarySensorDeviceClass ,
1516
1617_LOGGER = logging .getLogger (__name__ )
1718
18- BINARY_SENSORS : tuple [BinarySensorEntityDescription , ...] = (
19- BinarySensorEntityDescription (
19+
20+ @dataclass
21+ class SpeedportBinarySensorEntityDescription (BinarySensorEntityDescription ):
22+ condition_key : str = ""
23+ value : str = ""
24+
25+
26+ BINARY_SENSORS : tuple [SpeedportBinarySensorEntityDescription , ...] = (
27+ SpeedportBinarySensorEntityDescription (
2028 key = "onlinestatus" ,
2129 name = "Connection" ,
2230 device_class = BinarySensorDeviceClass .CONNECTIVITY ,
31+ value = "online" ,
2332 ),
24- BinarySensorEntityDescription (
33+ SpeedportBinarySensorEntityDescription (
2534 key = "dsl_link_status" ,
2635 name = "DSL-Connection" ,
2736 device_class = BinarySensorDeviceClass .PLUG ,
37+ value = "online" ,
38+ ),
39+ SpeedportBinarySensorEntityDescription (
40+ key = "dualstack" ,
41+ name = "Dual Stack" ,
42+ value = "1" ,
43+ ),
44+ SpeedportBinarySensorEntityDescription (
45+ key = "dsl_tunnel" ,
46+ name = "DSL Tunnel" ,
47+ device_class = BinarySensorDeviceClass .CONNECTIVITY ,
48+ condition_key = "use_lte" ,
49+ value = "1" ,
50+ ),
51+ SpeedportBinarySensorEntityDescription (
52+ key = "lte_tunnel" ,
53+ name = "LTE Tunnel" ,
54+ device_class = BinarySensorDeviceClass .CONNECTIVITY ,
55+ condition_key = "use_lte" ,
56+ value = "1" ,
57+ ),
58+ SpeedportBinarySensorEntityDescription (
59+ key = "hybrid_tunnel" ,
60+ name = "Hybrid Tunnel" ,
61+ device_class = BinarySensorDeviceClass .CONNECTIVITY ,
62+ condition_key = "use_lte" ,
63+ value = "1" ,
2864 ),
2965)
3066
@@ -38,18 +74,23 @@ async def async_setup_entry(
3874 entities = [
3975 SpeedportBinarySensor (hass , speedport , description )
4076 for description in BINARY_SENSORS
77+ if not description .condition_key
78+ or speedport .get (description .condition_key ) == "1"
4179 ]
4280
4381 async_add_entities (entities )
4482
4583
4684class SpeedportBinarySensor (SpeedportEntity , BinarySensorEntity ):
47- entity_description : BinarySensorEntityDescription
85+ entity_description : SpeedportBinarySensorEntityDescription
4886
4987 @property
5088 def is_on (self ) -> bool | None :
5189 """Return true if the binary sensor is on."""
52- return self ._speedport .get (self .entity_description .key ) == "online"
90+ return (
91+ self ._speedport .get (self .entity_description .key )
92+ == self .entity_description .value
93+ )
5394
5495 def available (self ) -> bool :
5596 if self ._speedport .get (self .entity_description .key ) is None :
0 commit comments