|
7 | 7 |
|
8 | 8 | from homeassistant.components.sensor import SensorEntity, SensorEntityDescription |
9 | 9 | from homeassistant.core import HomeAssistant |
10 | | -from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo |
11 | 10 | from homeassistant.helpers.entity_platform import AddEntitiesCallback |
12 | | -from homeassistant.helpers.update_coordinator import CoordinatorEntity |
13 | 11 |
|
14 | | -from . import DOMAIN, SpotifyConfigEntry |
15 | | -from .coordinator import SpotifyCoordinator |
| 12 | +from .coordinator import SpotifyConfigEntry, SpotifyCoordinator |
| 13 | +from .entity import SpotifyEntity |
16 | 14 |
|
17 | 15 |
|
18 | 16 | @dataclass(frozen=True, kw_only=True) |
@@ -41,41 +39,28 @@ async def async_setup_entry( |
41 | 39 | """Set up Spotify sensor based on a config entry.""" |
42 | 40 | coordinator = entry.runtime_data.coordinator |
43 | 41 |
|
44 | | - user_id = entry.unique_id |
45 | | - |
46 | | - assert user_id is not None |
47 | | - |
48 | 42 | async_add_entities( |
49 | | - SpotifyAudioFeatureSensor(coordinator, description, user_id, entry.title) |
| 43 | + SpotifyAudioFeatureSensor(coordinator, description) |
50 | 44 | for description in AUDIO_FEATURE_SENSORS |
51 | 45 | ) |
52 | 46 |
|
53 | 47 |
|
54 | | -class SpotifyAudioFeatureSensor(CoordinatorEntity[SpotifyCoordinator], SensorEntity): |
| 48 | +class SpotifyAudioFeatureSensor(SpotifyEntity, SensorEntity): |
55 | 49 | """Representation of a Spotify sensor.""" |
56 | 50 |
|
57 | | - _attr_has_entity_name = True |
58 | 51 | entity_description: SpotifyAudioFeaturesSensorEntityDescription |
59 | 52 |
|
60 | 53 | def __init__( |
61 | 54 | self, |
62 | 55 | coordinator: SpotifyCoordinator, |
63 | 56 | entity_description: SpotifyAudioFeaturesSensorEntityDescription, |
64 | | - user_id: str, |
65 | | - name: str, |
66 | 57 | ) -> None: |
67 | 58 | """Initialize.""" |
68 | 59 | super().__init__(coordinator) |
69 | | - self._attr_unique_id = f"{user_id}_{entity_description.key}" |
70 | | - self.entity_description = entity_description |
71 | | - self._attr_device_info = DeviceInfo( |
72 | | - identifiers={(DOMAIN, user_id)}, |
73 | | - manufacturer="Spotify AB", |
74 | | - model=f"Spotify {coordinator.current_user.product}", |
75 | | - name=f"Spotify {name}", |
76 | | - entry_type=DeviceEntryType.SERVICE, |
77 | | - configuration_url="https://open.spotify.com", |
| 60 | + self._attr_unique_id = ( |
| 61 | + f"{coordinator.current_user.user_id}_{entity_description.key}" |
78 | 62 | ) |
| 63 | + self.entity_description = entity_description |
79 | 64 |
|
80 | 65 | @property |
81 | 66 | def native_value(self) -> float | None: |
|
0 commit comments