Skip to content

Commit 7f5a2fe

Browse files
committed
New Entity description
1 parent d43ecf4 commit 7f5a2fe

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

custom_components/sector/sensor.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,38 @@ async def async_setup_entry(hass, entry, async_add_entities):
2222
coordinator = hass.data[DOMAIN][entry.entry_id]["coordinator"]
2323

2424
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-
)
3025

3126
tempsensors = []
3227
for sensor in thermometers:
3328
name = await sector_hub.get_name(sensor, "temp")
3429
_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+
)
3537
tempsensors.append(
36-
SectorAlarmTemperatureSensor(
37-
sector_hub, coordinator, sensor, name, description
38-
)
38+
SectorAlarmTemperatureSensor(sector_hub, coordinator, description)
3939
)
4040

41-
if tempsensors is not None:
41+
if tempsensors:
4242
async_add_entities(tempsensors)
4343
else:
44+
_LOGGER.debug("No tempsensors to add")
4445
return False
4546

4647
return True
4748

4849

4950
class SectorAlarmTemperatureSensor(CoordinatorEntity, SensorEntity):
50-
def __init__(self, hub, coordinator, sensor, name, description):
51+
def __init__(self, hub, coordinator, description):
5152
self._hub = hub
5253
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)
5657
self.entity_description = description
5758

5859
@property

0 commit comments

Comments
 (0)