diff --git a/homeassistant/components/lastfm/sensor.py b/homeassistant/components/lastfm/sensor.py index 68d727626cf..3a830b9f4e6 100644 --- a/homeassistant/components/lastfm/sensor.py +++ b/homeassistant/components/lastfm/sensor.py @@ -1,4 +1,5 @@ """Sensor for Last.fm account status.""" +import hashlib import logging import re @@ -54,8 +55,10 @@ class LastfmSensor(Entity): def __init__(self, user, lastfm_api): """Initialize the sensor.""" + self._unique_id = hashlib.sha256(user.encode("utf-8")).hexdigest() self._user = lastfm_api.get_user(user) self._name = user + self._entity_id = user self._lastfm = lastfm_api self._state = "Not Scrobbling" self._playcount = None @@ -63,6 +66,11 @@ class LastfmSensor(Entity): self._topplayed = None self._cover = None + @property + def unique_id(self): + """Return the unique ID of the sensor.""" + return self._unique_id + @property def name(self): """Return the name of the sensor.""" @@ -71,7 +79,7 @@ class LastfmSensor(Entity): @property def entity_id(self): """Return the entity ID.""" - return f"sensor.lastfm_{self._name}" + return f"sensor.lastfm_{self._entity_id}" @property def state(self):