-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add base entity to Spotify #128847
base: dev
Are you sure you want to change the base?
Add base entity to Spotify #128847
Changes from 3 commits
5bdfb3d
138723f
c5389c9
63e4436
319bf5f
f805fcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Base entity for Spotify.""" | ||
|
||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
||
from .const import DOMAIN | ||
from .coordinator import SpotifyCoordinator | ||
|
||
|
||
class SpotifyEntity(CoordinatorEntity[SpotifyCoordinator]): | ||
"""Defines a base Spotify entity.""" | ||
|
||
_attr_has_entity_name = True | ||
|
||
def __init__(self, coordinator: SpotifyCoordinator) -> None: | ||
"""Initialize the Spotify entity.""" | ||
super().__init__(coordinator) | ||
self._attr_device_info = DeviceInfo( | ||
identifiers={(DOMAIN, coordinator.current_user.user_id)}, | ||
manufacturer="Spotify AB", | ||
model=f"Spotify {coordinator.current_user.product}", | ||
name=f"Spotify {coordinator.config_entry.title}", | ||
entry_type=DeviceEntryType.SERVICE, | ||
configuration_url="https://open.spotify.com", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,17 +30,14 @@ | |
RepeatMode, | ||
) | ||
from homeassistant.core import HomeAssistant, callback | ||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.helpers.update_coordinator import ( | ||
CoordinatorEntity, | ||
DataUpdateCoordinator, | ||
) | ||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator | ||
|
||
from . import SpotifyConfigEntry | ||
from .browse_media import async_browse_media_internal | ||
from .const import DOMAIN, MEDIA_PLAYER_PREFIX, PLAYABLE_MEDIA_TYPES | ||
from .const import MEDIA_PLAYER_PREFIX, PLAYABLE_MEDIA_TYPES | ||
from .coordinator import SpotifyCoordinator | ||
from .entity import SpotifyEntity | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
@@ -99,10 +96,9 @@ def wrapper(self: SpotifyMediaPlayer) -> _R | None: | |
return wrapper | ||
class SpotifyMediaPlayer(CoordinatorEntity[SpotifyCoordinator], MediaPlayerEntity): | ||
class SpotifyMediaPlayer(SpotifyEntity, MediaPlayerEntity): | ||
"""Representation of a Spotify controller.""" | ||
_attr_has_entity_name = True | ||
_attr_media_image_remotely_accessible = False | ||
_attr_name = None | ||
_attr_translation_key = "spotify" | ||
|
@@ -117,18 +113,8 @@ def __init__( | |
"""Initialize.""" | ||
super().__init__(coordinator) | ||
self.devices = device_coordinator | ||
self._attr_unique_id = user_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case I don't have a suffix. In other examples I expect to be using an entity description so I'd rather set it in the platforms itself, since the unique id format changes per platform There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Which I guess would be fine as this is the main entity (name=None). So in this case hand in |
||
self._attr_device_info = DeviceInfo( | ||
identifiers={(DOMAIN, user_id)}, | ||
manufacturer="Spotify AB", | ||
model=f"Spotify {coordinator.current_user.product}", | ||
name=f"Spotify {name}", | ||
entry_type=DeviceEntryType.SERVICE, | ||
configuration_url="https://open.spotify.com", | ||
) | ||
@property | ||
def currently_playing(self) -> PlaybackState | None: | ||
"""Return the current playback.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this initialized somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the coordinator constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be a typed config entry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really use the runtime data here though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the policy was to update it everywhere...
For example, even if a migration doesn't use runtime_data, we still recommend the signature to match.