mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Introduce unique_id for lastfm to allow changing entity_id in backwards compatible way (#31163)
* Replace . with _ for lastfm entity_id * lint * double quotes * Rollback change, add unique_id * Expose prop * Generate unique ID from user * Linty * FIx linter * Revert changes for splitting entity_id * Simplify
This commit is contained in:
parent
cd72128a80
commit
bc196a3c9f
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user