@@ -22,37 +22,38 @@ async def async_setup_entry(hass, entry, async_add_entities):
22
22
coordinator = hass .data [DOMAIN ][entry .entry_id ]["coordinator" ]
23
23
24
24
thermometers = await sector_hub .get_thermometers ()
25
- description = SensorEntityDescription (
26
- unit_of_measurement = TEMP_CELSIUS ,
27
- state_class = STATE_CLASS_MEASUREMENT ,
28
- device_class = DEVICE_CLASS_TEMPERATURE ,
29
- )
30
25
31
26
tempsensors = []
32
27
for sensor in thermometers :
33
28
name = await sector_hub .get_name (sensor , "temp" )
34
29
_LOGGER .debug ("Sector: Fetched Label %s for serial %s" , name , sensor )
30
+ description = SensorEntityDescription (
31
+ key = sensor ,
32
+ name = name ,
33
+ unit_of_measurement = TEMP_CELSIUS ,
34
+ state_class = STATE_CLASS_MEASUREMENT ,
35
+ device_class = DEVICE_CLASS_TEMPERATURE ,
36
+ )
35
37
tempsensors .append (
36
- SectorAlarmTemperatureSensor (
37
- sector_hub , coordinator , sensor , name , description
38
- )
38
+ SectorAlarmTemperatureSensor (sector_hub , coordinator , description )
39
39
)
40
40
41
- if tempsensors is not None :
41
+ if tempsensors :
42
42
async_add_entities (tempsensors )
43
43
else :
44
+ _LOGGER .debug ("No tempsensors to add" )
44
45
return False
45
46
46
47
return True
47
48
48
49
49
50
class SectorAlarmTemperatureSensor (CoordinatorEntity , SensorEntity ):
50
- def __init__ (self , hub , coordinator , sensor , name , description ):
51
+ def __init__ (self , hub , coordinator , description ):
51
52
self ._hub = hub
52
53
super ().__init__ (coordinator )
53
- self ._serial = sensor
54
- self ._attr_name = name
55
- self ._attr_unique_id : str = "sa_temp_" + str (self . _serial )
54
+ self ._serial = description . key
55
+ self ._attr_name = description . name
56
+ self ._attr_unique_id : str = "sa_temp_" + str (description . key )
56
57
self .entity_description = description
57
58
58
59
@property
0 commit comments