From 52cabed98f6d009448fbd389b9bad6ca0289eda5 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 21 Aug 2023 22:31:04 +0200 Subject: [PATCH] Migrate LastFM to has entity name (#98766) --- homeassistant/components/lastfm/sensor.py | 3 ++- tests/components/lastfm/snapshots/test_sensor.ambr | 8 ++++---- tests/components/lastfm/test_init.py | 4 ++-- tests/components/lastfm/test_sensor.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/lastfm/sensor.py b/homeassistant/components/lastfm/sensor.py index f0f3af3b672..40d6521bdc9 100644 --- a/homeassistant/components/lastfm/sensor.py +++ b/homeassistant/components/lastfm/sensor.py @@ -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, diff --git a/tests/components/lastfm/snapshots/test_sensor.ambr b/tests/components/lastfm/snapshots/test_sensor.ambr index e64cf6b2629..30ad40df428 100644 --- a/tests/components/lastfm/snapshots/test_sensor.ambr +++ b/tests/components/lastfm/snapshots/test_sensor.ambr @@ -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': , - 'entity_id': 'sensor.testaccount1', + 'entity_id': 'sensor.lastfm_testaccount1', 'last_changed': , 'last_updated': , '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': , - 'entity_id': 'sensor.testaccount1', + 'entity_id': 'sensor.lastfm_testaccount1', 'last_changed': , 'last_updated': , 'state': 'Not Scrobbling', diff --git a/tests/components/lastfm/test_init.py b/tests/components/lastfm/test_init.py index 8f731385e6f..2f126af11a3 100644 --- a/tests/components/lastfm/test_init.py +++ b/tests/components/lastfm/test_init.py @@ -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 diff --git a/tests/components/lastfm/test_sensor.py b/tests/components/lastfm/test_sensor.py index fa29862d012..f5723215e2a 100644 --- a/tests/components/lastfm/test_sensor.py +++ b/tests/components/lastfm/test_sensor.py @@ -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)