Migrate LastFM to has entity name (#98766)

pull/98666/head
Joost Lekkerkerker 2023-08-21 22:31:04 +02:00 committed by GitHub
parent 53c118f652
commit 52cabed98f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 8 deletions

View File

@ -87,6 +87,8 @@ class LastFmSensor(CoordinatorEntity[LastFMDataUpdateCoordinator], SensorEntity)
_attr_attribution = "Data provided by Last.fm"
_attr_icon = "mdi:radio-fm"
_attr_has_entity_name = True
_attr_name = None
def __init__(
self,
@ -98,7 +100,6 @@ class LastFmSensor(CoordinatorEntity[LastFMDataUpdateCoordinator], SensorEntity)
super().__init__(coordinator)
self._username = username
self._attr_unique_id = hashlib.sha256(username.encode("utf-8")).hexdigest()
self._attr_name = username
self._attr_device_info = DeviceInfo(
configuration_url="https://www.last.fm",
entry_type=DeviceEntryType.SERVICE,

View File

@ -4,14 +4,14 @@
'attributes': ReadOnlyDict({
'attribution': 'Data provided by Last.fm',
'entity_picture': 'image',
'friendly_name': 'testaccount1',
'friendly_name': 'LastFM testaccount1',
'icon': 'mdi:radio-fm',
'last_played': 'artist - title',
'play_count': 1,
'top_played': 'artist - title',
}),
'context': <ANY>,
'entity_id': 'sensor.testaccount1',
'entity_id': 'sensor.lastfm_testaccount1',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'artist - title',
@ -22,14 +22,14 @@
'attributes': ReadOnlyDict({
'attribution': 'Data provided by Last.fm',
'entity_picture': 'image',
'friendly_name': 'testaccount1',
'friendly_name': 'LastFM testaccount1',
'icon': 'mdi:radio-fm',
'last_played': None,
'play_count': 0,
'top_played': None,
}),
'context': <ANY>,
'entity_id': 'sensor.testaccount1',
'entity_id': 'sensor.lastfm_testaccount1',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'Not Scrobbling',

View File

@ -20,11 +20,11 @@ async def test_load_unload_entry(
await setup_integration(config_entry, default_user)
entry = hass.config_entries.async_entries(DOMAIN)[0]
state = hass.states.get("sensor.testaccount1")
state = hass.states.get("sensor.lastfm_testaccount1")
assert state
await hass.config_entries.async_remove(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("sensor.testaccount1")
state = hass.states.get("sensor.lastfm_testaccount1")
assert not state

View File

@ -55,7 +55,7 @@ async def test_sensors(
user = request.getfixturevalue(fixture)
await setup_integration(config_entry, user)
entity_id = "sensor.testaccount1"
entity_id = "sensor.lastfm_testaccount1"
state = hass.states.get(entity_id)