Skip to content

Commit

Permalink
[ 1.0.16 ] * Added extra state attribute spotifyplus_device_id that…
Browse files Browse the repository at this point in the history
… lists the Spotify Connect Player device id that is in use.

  * Added extra state attribute `spotifyplus_device_name` that lists the Spotify Connect Player device name that is in use.
  * Refer to the [wiki documentation](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/Media-Player-Service-Enhancements#state-custom-variables) page for more details about custom state variables.
  • Loading branch information
thlucas1 committed Apr 21, 2024
1 parent 5e25dbf commit 64df8b9
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Change are listed in reverse chronological order (newest to oldest).

<span class="changelog">

###### [ 1.0.16 ] - 2024/04/21

* Added extra state attribute `spotifyplus_device_id` that lists the Spotify Connect Player device id that is in use.
* Added extra state attribute `spotifyplus_device_name` that lists the Spotify Connect Player device name that is in use.
* Refer to the [wiki documentation](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/Media-Player-Service-Enhancements#state-custom-variables) page for more details about custom state variables.

###### [ 1.0.15 ] - 2024/04/05

* Added `MediaPlayerEntityFeature.VOLUME_MUTE` support to handle volume mute requests.
Expand Down
71 changes: 52 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Platform | Description

The following Home Assistant media_player Platform services are supplied by this integration.
- BROWSE_MEDIA
- MEDIA_ENQUEUE
- NEXT_TRACK
- PAUSE
- PLAY
Expand All @@ -26,28 +27,60 @@ The following Home Assistant media_player Platform services are supplied by this
- SEEK
- SELECT_SOURCE
- SHUFFLE_SET
- TURN_OFF
- TURN_ON
- VOLUME_MUTE
- VOLUME_SET
- VOLUME_STEP

The following custom services are also supplied by this integration.
- Get Album: Get Spotify catalog information for a single album.
- Get Album Favorites: Get a list of the albums saved in the current Spotify user's 'Your Library'.
- Get Album New Releases: Get a list of new album releases featured in Spotify.
- Get Artist: Get Spotify catalog information for a single artist.
- Get Artist Albums: Get Spotify catalog information about an artist's albums.
- Get Artists Followed: Get the current user's followed artists.
- Get Browse Categorys: Get a sorted list of ALL categories used to tag items in Spotify.
- Get Category Playlists: Get a list of Spotify playlists tagged with a particular category.
- Get Featured Playlists: Get a list of Spotify featured playlists.
- Get Player Recent Tracks: Get tracks from the current user's recently played tracks; currently doesn't support podcast episodes, and only 50 items may be returned due to spotify limits.
- Get Playlist: Get a playlist owned by a Spotify user.
- Get Playlist Favorites: Get a list of the playlists owned or followed by the current Spotify user.
- Get Show: Get Spotify catalog information for a single show identified by its unique Spotify ID.
- Get Show Episodes: Get Spotify catalog information about a show's episodes.
- Get Show Favorites: Get a list of the shows saved in the current Spotify user's 'Your Library'.
- Get Track Favorites: Get a list of the tracks saved in the current Spotify user's 'Your Library'.
- Get Users Top Artists: Get the current user's top artists based on calculated affinity.
- Get Users Top Tracks: Get the current user's top tracks based on calculated affinity.
- Search Playlists: Get Spotify catalog information about Playlists that match a keyword string.
- Follow Artists
- Follow Playlist
- Follow Users
- Get Album
- Get Album Favorites
- Get Album New Releases
- Get Artist
- Get Artists Albums
- Get Artists Followed
- Get Browse Categories
- Get Category Playlists
- Get Featured Playlists
- Get Player Devices
- Get Player Queue Info
- Get Player Recent Tracks
- Get Playlist
- Get Playlist Favorites
- Get Show
- Get Show Episodes
- Get Show Favorites
- Get Track Favorites
- Get Users Top Artists
- Get Users Top Tracks
- Player Media Play Context
- Player Media Play Track Favorites
- Player Media Play Tracks
- Player Transfer Playback
- Playlist Change
- Playlist Cover Image Add
- Playlist Create
- Playlist Items Add
- Playlist Items Clear
- Playlist Items Remove
- Save Album Favorites
- Save Track Favorites
- Remove Album Favorites
- Remove Track Favorites
- Search Albums
- Search Artists
- Search Audiobooks
- Search Episodes
- Search Playlists
- Search Shows
- Search Tracks
- Unfollow Artists
- Unfollow Playlist
- Unfollow Users

Check out the [Services Provided wiki](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/Services-Provided) page for detailed explanations and YAML examples of the custom services provided by this integration.

Expand Down
2 changes: 1 addition & 1 deletion custom_components/spotifyplus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"spotifywebapiPython==1.0.42",
"urllib3>=1.21.1,<1.27"
],
"version": "1.0.15",
"version": "1.0.16",
"zeroconf": [ "_spotify-connect._tcp.local." ]
}
22 changes: 22 additions & 0 deletions custom_components/spotifyplus/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
_logsi.SystemLogger = LOGGER


# our extra state attribute names.
ATTR_SPOTIFYPLUS_DEVICE_ID = "spotifyplus_device_id"
ATTR_SPOTIFYPLUS_DEVICE_NAME = "spotifyplus_device_name"


# annotate the `spotify_exception_handler` callable.
_SpotifyMediaPlayerT = TypeVar("_SpotifyMediaPlayerT", bound="SpotifyMediaPlayer")
_R = TypeVar("_R")
Expand Down Expand Up @@ -333,6 +338,23 @@ def __init__(self, data:InstanceDataSpotifyPlus) -> None:
_logsi.LeaveMethod(SILevel.Debug)


@property
def extra_state_attributes(self):
""" Return entity specific state attributes. """
# build list of our extra state attributes to return to HA UI.
attributes = {}
attributes[ATTR_SPOTIFYPLUS_DEVICE_ID] = "no_device"
attributes[ATTR_SPOTIFYPLUS_DEVICE_NAME] = "no_device"

# get currently active device id.
if self._playerState is not None:
if self._playerState.Device is not None:
attributes[ATTR_SPOTIFYPLUS_DEVICE_ID] = self._playerState.Device.Id
attributes[ATTR_SPOTIFYPLUS_DEVICE_NAME] = self._playerState.Device.Name

return attributes


@property
def state(self) -> MediaPlayerState:
""" Return the playback state. """
Expand Down

0 comments on commit 64df8b9

Please sign in to comment.