Skip to content

Commit

Permalink
[ 1.0.41 ] * Added support for Sonos device control and status update…
Browse files Browse the repository at this point in the history
…s via the Python [SoCo (Sonos Controller) API](https://docs.python-soco.com/en/latest/) package.  These changes will allow you to control playback, obtain current status, and transfer Spotify Connect Player control to / from the device.  Note that this works best when the device is controlled by the various Spotify Applications (e.g. Desktop, Mobile, and Web).  Sonos devices that are controlled by the Sonos Applications can behave erratically when controlled by SpotifyPlus.  More information on why that is can be found on the [Spotify Connect Brand Notes](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/Spotify-Connect-Brand-Notes) wiki documentation page.

  * Updated underlying `spotifywebapiPython` package requirement to version 1.0.76.
  • Loading branch information
thlucas1 committed Jul 18, 2024
1 parent 24ed7a7 commit b49dc91
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 144 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ config/*
/developer_notes.txt
/.github/workflows/lint.yml
/New_Release_Instructions.txt
/test/testdata/
/test/*
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Change are listed in reverse chronological order (newest to oldest).

<span class="changelog">

###### [ 1.0.41 ] - 2024/07/18

* Added support for Sonos device control and status updates via the Python [SoCo (Sonos Controller) API](https://docs.python-soco.com/en/latest/) package. These changes will allow you to control playback, obtain current status, and transfer Spotify Connect Player control to / from the device. Note that this works best when the device is controlled by the various Spotify Applications (e.g. Desktop, Mobile, and Web). Sonos devices that are controlled by the Sonos Applications can behave erratically when controlled by SpotifyPlus. More information on why that is can be found on the [Spotify Connect Brand Notes](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/Spotify-Connect-Brand-Notes) wiki documentation page.
* Updated underlying `spotifywebapiPython` package requirement to version 1.0.76.

###### [ 1.0.40 ] - 2024/07/02

* Updated underlying `spotifywebapiPython` package requirement to version 1.0.73.
Expand Down
13 changes: 5 additions & 8 deletions custom_components/spotifyplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1958,14 +1958,14 @@ async def async_setup_entry(hass:HomeAssistant, entry:ConfigEntry) -> bool:
# -----------------------------------------------------------------------------------
# Define DataUpdateCoordinator function.
# -----------------------------------------------------------------------------------
async def _update_devices() -> list[dict[str, Any]]:
async def _update_devices() -> SpotifyConnectDevices:
"""
DataUpdateCoordinator update method that will retrieve the list of Spotify Connect
devices that are available. This method will be executed by the DataUpdateCoordinator
every 5 minutes to refresh the device list.
Returns:
A list of Spotify Device class instances.
A `SpotifyConnectDevices` instance.
"""

shouldUpdate:bool = True
Expand Down Expand Up @@ -1996,12 +1996,9 @@ async def _update_devices() -> list[dict[str, Any]]:
True
)

# get the device list.
devices:list[Device] = scDevices.GetDeviceList()

# trace.
_logsi.LogDictionary(SILevel.Verbose, "'%s': Component DataUpdateCoordinator update results" % entry.title, devices, prettyPrint=True)
return devices
_logsi.LogDictionary(SILevel.Verbose, "'%s': Component DataUpdateCoordinator update results" % entry.title, scDevices.ToDictionary(), prettyPrint=True)
return scDevices

except Exception as ex:

Expand Down Expand Up @@ -2128,7 +2125,7 @@ def _TokenUpdater() -> dict:
_logsi.LogObject(SILevel.Verbose, "'%s': Component async_setup_entry Spotify UserProfile object" % entry.title, spotifyClient.UserProfile)

# define a data update coordinator that will poll for updated device entries every 5 minutes.
device_coordinator:DataUpdateCoordinator[list[Device]] = DataUpdateCoordinator(
device_coordinator:DataUpdateCoordinator[SpotifyConnectDevices] = DataUpdateCoordinator(
hass,
_LOGGER,
name=f"{entry.title} Devices",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/spotifyplus/instancedata_spotifyplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any

from spotifywebapipython import SpotifyClient
from spotifywebapipython.models import Device
from spotifywebapipython.models import SpotifyConnectDevices

from homeassistant.components.media_player import MediaPlayerEntity
from homeassistant.helpers.config_entry_oauth2_flow import (
Expand All @@ -30,7 +30,7 @@ class InstanceDataSpotifyPlus:
modules.
"""

devices: DataUpdateCoordinator[list[Device]]
devices: DataUpdateCoordinator[SpotifyConnectDevices]
"""
List of Spotify Connect devices that are available.
This property is refreshed every 5 minutes by a DataUpdateCoordinator.
Expand Down
4 changes: 2 additions & 2 deletions custom_components/spotifyplus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"requests>=2.31.0",
"requests_oauthlib>=1.3.1",
"smartinspectPython>=3.0.33",
"spotifywebapiPython>=1.0.73",
"spotifywebapiPython>=1.0.76",
"urllib3>=1.21.1,<1.27",
"zeroconf>=0.132.2"
],
"version": "1.0.40",
"version": "1.0.41",
"zeroconf": [ "_spotify-connect._tcp.local." ]
}
Loading

0 comments on commit b49dc91

Please sign in to comment.