Skip to content

Commit

Permalink
[ 1.0.12 ] * Updated underlying spotifywebapiPython package require…
Browse files Browse the repository at this point in the history
…ment to version 1.0.40.

  * Added service `turn_on` and `turn_off` support for the player.  Playback control is transferred to the player after turning on.  Configuration options support the execution of scripts to allow external devices to be powered on and off.  Refer to the [wiki documentation](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/Media-Player-Service-Enhancements#turn-on--off) on how to configure this feature.
  * Added support for media controls to properly function when the Spotify Connect Player loses the active device reference.  For example, when the player goes into an `idle` state due to player pausing for extended period of time, you can now resume play without having to re-select the source (avoids `No active playback device found` errors).
  • Loading branch information
thlucas1 committed Mar 28, 2024
1 parent f4cb816 commit f6ade96
Show file tree
Hide file tree
Showing 11 changed files with 635 additions and 249 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.12 ] - 2024/03/27

* Updated underlying `spotifywebapiPython` package requirement to version 1.0.40.
* Added service `turn_on` and `turn_off` support for the player. Playback control is transferred to the player after turning on. Configuration options support the execution of scripts to allow external devices to be powered on and off. Refer to the [wiki documentation](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/Media-Player-Service-Enhancements#turn-on--off) on how to configure this feature.
* Added support for media controls to properly function when the Spotify Connect Player loses the active device reference. For example, when the player goes into an `idle` state due to player pausing for extended period of time, you can now resume play without having to re-select the source (avoids `No active playback device found` errors).

###### [ 1.0.11 ] - 2024/03/24

* Updated media_player SCAN_INTERVAL to 1 second to inform HA of Spotify status updates in near real time (e.g. pause, resume, next track, etc).
Expand Down
11 changes: 11 additions & 0 deletions custom_components/spotifyplus/appmessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ class STAppMessages:
"""
Retrieving information from the Spotify Web API
"""

MSG_MEDIAPLAYER_SERVICE:str = "'%s': MediaPlayer is executing service '%s'"
"""
'%s': MediaPlayer is executing service '%s'
"""

MSG_MEDIAPLAYER_SERVICE_WITH_PARMS:str = "'%s': MediaPlayer is executing service '%s' - parameters: %s"
"""
'%s': MediaPlayer is executing service '%s' - parameters: %s
"""

21 changes: 19 additions & 2 deletions custom_components/spotifyplus/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
from spotifywebapipython.models import Device

from homeassistant.config_entries import ConfigEntry, OptionsFlow
from homeassistant.const import CONF_DESCRIPTION, CONF_ID, CONF_NAME
from homeassistant.const import CONF_DESCRIPTION, CONF_ID, CONF_NAME, Platform
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv, selector
from homeassistant.helpers.selector import (
SelectSelector,
SelectSelectorConfig,
Expand All @@ -36,7 +36,10 @@

from .const import (
CONF_OPTION_DEVICE_DEFAULT,
CONF_OPTION_SCRIPT_TURN_OFF,
CONF_OPTION_SCRIPT_TURN_ON,
DOMAIN,
DOMAIN_SCRIPT,
SPOTIFY_SCOPES
)
from .instancedata_spotifyplus import InstanceDataSpotifyPlus
Expand Down Expand Up @@ -350,6 +353,8 @@ async def async_step_init(self, user_input:dict[str,Any]=None) -> FlowResult:

# update config entry options from user input values.
self._Options[CONF_OPTION_DEVICE_DEFAULT] = user_input.get(CONF_OPTION_DEVICE_DEFAULT, None)
self._Options[CONF_OPTION_SCRIPT_TURN_OFF] = user_input.get(CONF_OPTION_SCRIPT_TURN_OFF, None)
self._Options[CONF_OPTION_SCRIPT_TURN_ON] = user_input.get(CONF_OPTION_SCRIPT_TURN_ON, None)

# store the updated config entry options.
_logsi.LogDictionary(SILevel.Verbose, "'%s': OptionsFlow is updating configuration options - options" % self._name, self._Options)
Expand Down Expand Up @@ -382,6 +387,18 @@ async def async_step_init(self, user_input:dict[str,Any]=None) -> FlowResult:
mode=SelectSelectorMode.DROPDOWN
)
),
vol.Optional(CONF_OPTION_SCRIPT_TURN_ON,
description={"suggested_value": self._Options.get(CONF_OPTION_SCRIPT_TURN_ON)},
): selector.EntitySelector(selector.EntitySelectorConfig(integration=DOMAIN_SCRIPT,
#domain=Platform.SCENE,
multiple=False),
),
vol.Optional(CONF_OPTION_SCRIPT_TURN_OFF,
description={"suggested_value": self._Options.get(CONF_OPTION_SCRIPT_TURN_OFF)},
): selector.EntitySelector(selector.EntitySelectorConfig(integration=DOMAIN_SCRIPT,
#domain=Platform.SCENE,
multiple=False),
),
}
)

Expand Down
5 changes: 5 additions & 0 deletions custom_components/spotifyplus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
DOMAIN = "spotifyplus"
""" Domain identifier for this integration. """

DOMAIN_SCRIPT = "script"
""" Domain identifier for script integration. """

LOGGER = logging.getLogger(__package__)

CONF_OPTION_DEVICE_DEFAULT = "device_default"
CONF_OPTION_SCRIPT_TURN_ON = "script_turn_on"
CONF_OPTION_SCRIPT_TURN_OFF = "script_turn_off"

# security scopes required by various Spotify Web API endpoints.
SPOTIFY_SCOPES:list = \
Expand Down
17 changes: 17 additions & 0 deletions custom_components/spotifyplus/instancedata_spotifyplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

from .const import (
CONF_OPTION_DEVICE_DEFAULT,
CONF_OPTION_SCRIPT_TURN_OFF,
CONF_OPTION_SCRIPT_TURN_ON,
)

@dataclass
Expand Down Expand Up @@ -58,3 +60,18 @@ def OptionDeviceDefault(self) -> str | None:
The default Spotify Connect player device.
"""
return self.options.get(CONF_OPTION_DEVICE_DEFAULT, None)

@property
def OptionScriptTurnOff(self) -> str | None:
"""
Script entity id that will be called to power off the device that plays media content.
"""
return self.options.get(CONF_OPTION_SCRIPT_TURN_OFF, None)

@property
def OptionScriptTurnOn(self) -> str | None:
"""
Script entity id that will be called to power on the device that plays media content.
"""
return self.options.get(CONF_OPTION_SCRIPT_TURN_ON, None)

4 changes: 2 additions & 2 deletions custom_components/spotifyplus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"issue_tracker": "https://github.com/thlucas1/homeassistantcomponent_spotifyplus/issues",
"requirements": [
"smartinspectPython==3.0.33",
"spotifywebapiPython==1.0.37",
"spotifywebapiPython==1.0.40",
"urllib3>=1.21.1,<1.27"
],
"version": "1.0.11",
"version": "1.0.12",
"zeroconf": [ "_spotify-connect._tcp.local." ]
}
Loading

0 comments on commit f6ade96

Please sign in to comment.