diff --git a/homeassistant/components/emoncms/sensor.py b/homeassistant/components/emoncms/sensor.py index 746877c4e5f3ff..588163396c82b6 100644 --- a/homeassistant/components/emoncms/sensor.py +++ b/homeassistant/components/emoncms/sensor.py @@ -72,9 +72,9 @@ ) -def get_id(sensorid, feedtag, feedname, feedid, feeduserid): +def get_id(sensorid: str, feeduserid: str, feedid: str) -> str: """Return unique identifier for feed / sensor.""" - return f"emoncms{sensorid}_{feedtag}_{feedname}_{feedid}_{feeduserid}" + return f"emoncms{sensorid}_{feeduserid}_{feedid}" def setup_platform( @@ -150,12 +150,11 @@ def __init__( id_for_name = "" if str(sensorid) == "1" else sensorid # Use the feed name assigned in EmonCMS or fall back to the feed ID feed_name = elem.get("name") or f"Feed {elem['id']}" - self._name = f"EmonCMS{id_for_name} {feed_name}" + self._attr_name = f"EmonCMS{id_for_name} {feed_name}" else: - self._name = name - self._identifier = get_id( - sensorid, elem["tag"], elem["name"], elem["id"], elem["userid"] - ) + self._attr_name = name + self._attr_unique_id = get_id(sensorid, elem["userid"], elem["id"]) + self._attr_native_unit_of_measurement = unit_of_measurement self._hass = hass self._data = data self._value_template = value_template @@ -197,11 +196,6 @@ def __init__( else: self._state = None - @property - def name(self): - """Return the name of the sensor.""" - return self._name - @property def native_unit_of_measurement(self): """Return the unit of measurement of this entity, if any.""" @@ -238,12 +232,10 @@ def update(self) -> None: for elem in self._data.data if get_id( self._sensorid, - elem["tag"], - elem["name"], - elem["id"], elem["userid"], + elem["id"], ) - == self._identifier + == self._attr_unique_id ), None, )