diff --git a/custom_components/sinapsi_alfa/const.py b/custom_components/sinapsi_alfa/const.py index b6993ae..2848212 100644 --- a/custom_components/sinapsi_alfa/const.py +++ b/custom_components/sinapsi_alfa/const.py @@ -155,7 +155,7 @@ }, { "name": "Energia Prelevata Giornaliera F4", - "key": "energia_prelevata_giornaliera_f1", + "key": "energia_prelevata_giornaliera_f4", "icon": "mdi:transmission-tower-import", "device_class": SensorDeviceClass.ENERGY, "state_class": SensorStateClass.TOTAL_INCREASING, @@ -165,7 +165,7 @@ }, { "name": "Energia Prelevata Giornaliera F5", - "key": "energia_prelevata_giornaliera_f1", + "key": "energia_prelevata_giornaliera_f5", "icon": "mdi:transmission-tower-import", "device_class": SensorDeviceClass.ENERGY, "state_class": SensorStateClass.TOTAL_INCREASING, @@ -215,7 +215,7 @@ }, { "name": "Energia Immessa Giornaliera F4", - "key": "energia_immessa_giornaliera_f1", + "key": "energia_immessa_giornaliera_f4", "icon": "mdi:transmission-tower-export", "device_class": SensorDeviceClass.ENERGY, "state_class": SensorStateClass.TOTAL_INCREASING, @@ -225,7 +225,7 @@ }, { "name": "Energia Immessa Giornaliera F5", - "key": "energia_immessa_giornaliera_f1", + "key": "energia_immessa_giornaliera_f5", "icon": "mdi:transmission-tower-export", "device_class": SensorDeviceClass.ENERGY, "state_class": SensorStateClass.TOTAL_INCREASING, diff --git a/custom_components/sinapsi_alfa/sensor.py b/custom_components/sinapsi_alfa/sensor.py index 1d23593..1649501 100644 --- a/custom_components/sinapsi_alfa/sensor.py +++ b/custom_components/sinapsi_alfa/sensor.py @@ -4,7 +4,6 @@ """ import logging -import re from typing import Any from homeassistant.components.sensor import SensorEntity @@ -53,19 +52,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entitie return True -def to_unique_id(raw: str): - """Convert string to unique_id.""" - string = ( - re.sub(r"(?<=[a-z0-9:_])(?=[A-Z])|[^a-zA-Z0-9:_]", " ", raw) - .strip() - .replace(" ", "_") - ) - result = "".join(string.lower()) - while "__" in result: - result = result.replace("__", "_") - return result - - class SinapsiAlfaSensor(CoordinatorEntity, SensorEntity): """Representation of a Sinapsi Alfa sensor.""" @@ -155,7 +141,7 @@ def should_poll(self) -> bool: @property def unique_id(self): """Return a unique ID to use for this entity.""" - return to_unique_id(f"{self._device_sn}_{self._key}") + return f"{DOMAIN}_{self._device_sn}_{self._key}" @property def device_info(self):