88from homeassistant .components .sensor import SensorEntity , SensorDeviceClass
99from homeassistant .const import EntityCategory
1010from homeassistant .helpers .entity import DeviceInfo
11- from homeassistant .helpers .entity_platform import EntityPlatform
1211
1312from custom_components .dmx import ArtPollReply
1413from custom_components .dmx .client import StyleCode , IndicatorState , BootProcess , FailsafeState , PortAddressProgrammingAuthority
1514
1615_LOGGER = logging .getLogger (__name__ )
1716
17+ def bind_index_str (artpoll_reply : ArtPollReply ):
18+ if artpoll_reply .bind_index == 0 :
19+ return ""
20+ return f" { artpoll_reply .bind_index } "
21+
1822
1923class ArtNetEntity :
2024 """Representation of an ArtNet entity."""
@@ -47,14 +51,14 @@ class ArtNetOnlineBinarySensor(ArtNetEntity, BinarySensorEntity):
4751
4852 def __init__ (self , art_poll_reply , device_info : DeviceInfo ):
4953 """Initialize the binary sensor."""
50- super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Online" , "online" , device_info )
54+ super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Online" , "online" , device_info )
5155 self ._attr_device_class = BinarySensorDeviceClass .CONNECTIVITY
56+ self .connected = True
5257
5358 @property
5459 def is_on (self ) -> bool :
5560 """Return true if the binary sensor is on."""
56- # TODO
57- return True
61+ return self .connected
5862
5963 @property
6064 def extra_state_attributes (self ) -> Dict [str , Any ]:
@@ -77,7 +81,7 @@ class ArtNetIndicatorStateSensor(ArtNetEntity, SensorEntity):
7781
7882 def __init__ (self , art_poll_reply , device_info : DeviceInfo ):
7983 """Initialize the sensor."""
80- super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Indicator" , "indicator" , device_info )
84+ super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Indicator" , "indicator" , device_info )
8185 self ._attr_device_class = SensorDeviceClass .ENUM
8286 self ._attr_icon = "mdi:lightbulb"
8387 self ._attr_options = [member .name for member in IndicatorState ]
@@ -98,7 +102,7 @@ class ArtNetBootProcessSensor(ArtNetEntity, SensorEntity):
98102
99103 def __init__ (self , art_poll_reply , device_info : DeviceInfo ):
100104 """Initialize the sensor."""
101- super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Boot Process" , "boot_process" , device_info )
105+ super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Boot Process" , "boot_process" , device_info )
102106 self ._attr_device_class = SensorDeviceClass .ENUM
103107 self ._attr_options = [member .name for member in BootProcess ]
104108 self ._attr_entity_category = EntityCategory .DIAGNOSTIC
@@ -118,7 +122,7 @@ class ArtNetRDMBinarySensor(ArtNetEntity, BinarySensorEntity):
118122
119123 def __init__ (self , art_poll_reply , device_info : DeviceInfo ):
120124 """Initialize the binary sensor."""
121- super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } RDM Support" , "rdm_support" , device_info )
125+ super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } RDM Support" , "rdm_support" , device_info )
122126 self ._attr_entity_category = EntityCategory .DIAGNOSTIC
123127
124128 @property
@@ -143,7 +147,7 @@ class ArtNetDHCPBinarySensor(ArtNetEntity, BinarySensorEntity):
143147
144148 def __init__ (self , art_poll_reply , device_info : DeviceInfo ):
145149 """Initialize the binary sensor."""
146- super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } DHCP" , "dhcp" , device_info )
150+ super ().__init__ (art_poll_reply , f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } DHCP" , "dhcp" , device_info )
147151 self ._attr_icon = "mdi:network"
148152 self ._attr_entity_category = EntityCategory .DIAGNOSTIC
149153
@@ -173,7 +177,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo, port_index):
173177 self .port = art_poll_reply .ports [port_index ]
174178 super ().__init__ (
175179 art_poll_reply ,
176- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Port { port_index + 1 } Input Active" ,
180+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Port { port_index + 1 } Input Active" ,
177181 f"port_{ port_index } _input_active" ,
178182 device_info
179183 )
@@ -220,7 +224,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo, port_index):
220224 self .port = art_poll_reply .ports [port_index ]
221225 super ().__init__ (
222226 art_poll_reply ,
223- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Port { port_index + 1 } Output Active" ,
227+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Port { port_index + 1 } Output Active" ,
224228 f"port_{ port_index } _output_active" ,
225229 device_info
226230 )
@@ -267,7 +271,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo, port_index):
267271 self .port = art_poll_reply .ports [port_index ]
268272 super ().__init__ (
269273 art_poll_reply ,
270- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Port { port_index + 1 } Merge Mode" ,
274+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Port { port_index + 1 } Merge Mode" ,
271275 f"port_{ port_index } _merge_mode" ,
272276 device_info
273277 )
@@ -308,7 +312,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo, port_index):
308312 self .port = art_poll_reply .ports [port_index ]
309313 super ().__init__ (
310314 art_poll_reply ,
311- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Port { port_index + 1 } sACN Mode" ,
315+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Port { port_index + 1 } sACN Mode" ,
312316 f"port_{ port_index } _sacn_mode" ,
313317 device_info
314318 )
@@ -343,7 +347,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo, port_index):
343347 self .port = art_poll_reply .ports [port_index ]
344348 super ().__init__ (
345349 art_poll_reply ,
346- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Port { port_index + 1 } RDM" ,
350+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Port { port_index + 1 } RDM" ,
347351 f"port_{ port_index } _rdm" ,
348352 device_info
349353 )
@@ -378,7 +382,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo, port_index):
378382 self .port = art_poll_reply .ports [port_index ]
379383 super ().__init__ (
380384 art_poll_reply ,
381- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Port { port_index + 1 } Output Mode" ,
385+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Port { port_index + 1 } Output Mode" ,
382386 f"port_{ port_index } _output_mode" ,
383387 device_info
384388 )
@@ -413,7 +417,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo, port_index, is_input
413417 direction = "Input" if is_input else "Output"
414418 super ().__init__ (
415419 art_poll_reply ,
416- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Port { port_index + 1 } { direction } Universe" ,
420+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Port { port_index + 1 } { direction } Universe" ,
417421 f"port_{ port_index } _{ direction .lower ()} _universe" ,
418422 device_info
419423 )
@@ -443,7 +447,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo):
443447 """Initialize the sensor."""
444448 super ().__init__ (
445449 art_poll_reply ,
446- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Failsafe State" ,
450+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Failsafe State" ,
447451 "failsafe_state" ,
448452 device_info
449453 )
@@ -468,7 +472,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo):
468472 """Initialize the sensor."""
469473 super ().__init__ (
470474 art_poll_reply ,
471- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } ACN Priority" ,
475+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } ACN Priority" ,
472476 "acn_priority" ,
473477 device_info
474478 )
@@ -491,7 +495,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo):
491495 """Initialize the sensor."""
492496 super ().__init__ (
493497 art_poll_reply ,
494- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Node Report" ,
498+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Node Report" ,
495499 "node_report" ,
496500 device_info
497501 )
@@ -514,7 +518,7 @@ def __init__(self, art_poll_reply, device_info: DeviceInfo):
514518 """Initialize the sensor."""
515519 super ().__init__ (
516520 art_poll_reply ,
517- f"{ art_poll_reply .short_name } { art_poll_reply . bind_index } Port Programming Authority" ,
521+ f"{ art_poll_reply .short_name } { bind_index_str ( art_poll_reply ) } Port Programming Authority" ,
518522 "port_programming_authority" ,
519523 device_info
520524 )
0 commit comments