Skip to content

Commit

Permalink
Fix key of 4 sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdelprete committed Feb 28, 2024
1 parent efe937a commit 6bb1fef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
8 changes: 4 additions & 4 deletions custom_components/sinapsi_alfa/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 1 addition & 15 deletions custom_components/sinapsi_alfa/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import re
from typing import Any

from homeassistant.components.sensor import SensorEntity
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 6bb1fef

Please sign in to comment.