mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add unique ID to dsmr_reader sensors (#79101)
This commit is contained in:
parent
88500145d2
commit
a58f919972
@ -40,12 +40,12 @@ async def async_setup_platform(
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
_: HomeAssistant,
|
||||||
config: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up DSMR Reader sensors from config entry."""
|
"""Set up DSMR Reader sensors from config entry."""
|
||||||
async_add_entities(DSMRSensor(description) for description in SENSORS)
|
async_add_entities(DSMRSensor(description, config_entry) for description in SENSORS)
|
||||||
|
|
||||||
|
|
||||||
class DSMRSensor(SensorEntity):
|
class DSMRSensor(SensorEntity):
|
||||||
@ -53,12 +53,15 @@ class DSMRSensor(SensorEntity):
|
|||||||
|
|
||||||
entity_description: DSMRReaderSensorEntityDescription
|
entity_description: DSMRReaderSensorEntityDescription
|
||||||
|
|
||||||
def __init__(self, description: DSMRReaderSensorEntityDescription) -> None:
|
def __init__(
|
||||||
|
self, description: DSMRReaderSensorEntityDescription, config_entry: ConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
slug = slugify(description.key.replace("/", "_"))
|
slug = slugify(description.key.replace("/", "_"))
|
||||||
self.entity_id = f"sensor.{slug}"
|
self.entity_id = f"sensor.{slug}"
|
||||||
|
self._attr_unique_id = f"{config_entry.entry_id}-{slug}"
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to MQTT events."""
|
"""Subscribe to MQTT events."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user