Skip to content

Commit

Permalink
[ 1.0.70 ] * Added [configuration option](https://github.com/thlucas1…
Browse files Browse the repository at this point in the history
…/homeassistantcomponent_spotifyplus/wiki/Device-Configuration-Options#spotify-polling-scan-interval) to specify the Spotify polling scan interval.  This option specifies the polling scan interval (in seconds) used to query Spotify Player playstate.
  • Loading branch information
thlucas1 committed Dec 12, 2024
1 parent 11d3822 commit dd319cc
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 35 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ Change are listed in reverse chronological order (newest to oldest).

<span class="changelog">

###### [ 1.0.70 ] - 2024/12/12

* Added [configuration option](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/Device-Configuration-Options#spotify-polling-scan-interval) to specify the Spotify polling scan interval. This option specifies the polling scan interval (in seconds) used to query Spotify Player playstate.

###### [ 1.0.69 ] - 2024/12/09

* Updated code when calling the spotifywebapiPython `GetPlaylist` method to not log exception information if the call fails. This was causing exceptions to be logged when trying to retrieve details for Spotify-owned algorithmic playlist details; the call now fails due to the unannounced Spotify Web API changes that were made by the Spotify Developer Team on 2024/11/27. Note that the call works fine for user-defined playlists.
* The `media_playlist` extended attribute will now display `Unknown` if the currently playing context is a Spotify-owned algorithmic playlist (e.g. "Daily Mix 1", etc). It will display the correct playlist name if the currently playing context is a user-defined playlist.
* The `sp_playlist_name` extended attribute will now display `Unknown` if the currently playing context is a Spotify-owned algorithmic playlist (e.g. "Daily Mix 1", etc). It will display the correct playlist name if the currently playing context is a user-defined playlist.
* Updated service `turn_on` to first check if the previously selected source is active or not; if so, then play is resumed immediately; if not, then a `source_select` is performed to activate the selected source.
* Updated underlying `spotifywebapiPython` package requirement to version 1.0.125.

###### [ 1.0.68 ] - 2024/12/06
Expand Down
11 changes: 11 additions & 0 deletions custom_components/spotifyplus/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
CONF_OPTION_DEVICE_LOGINID,
CONF_OPTION_DEVICE_PASSWORD,
CONF_OPTION_DEVICE_USERNAME,
CONF_OPTION_SPOTIFY_SCAN_INTERVAL,
CONF_OPTION_SCRIPT_TURN_OFF,
CONF_OPTION_SCRIPT_TURN_ON,
CONF_OPTION_SOURCE_LIST_HIDE,
DEFAULT_OPTION_SPOTIFY_SCAN_INTERVAL,
DOMAIN,
DOMAIN_SCRIPT,
SPOTIFY_SCOPES
Expand Down Expand Up @@ -372,6 +374,7 @@ async def async_step_init(self, user_input:dict[str,Any]=None) -> FlowResult:
self._Options[CONF_OPTION_DEVICE_LOGINID] = user_input.get(CONF_OPTION_DEVICE_LOGINID, None)
self._Options[CONF_OPTION_DEVICE_USERNAME] = user_input.get(CONF_OPTION_DEVICE_USERNAME, None)
self._Options[CONF_OPTION_DEVICE_PASSWORD] = user_input.get(CONF_OPTION_DEVICE_PASSWORD, None)
self._Options[CONF_OPTION_SPOTIFY_SCAN_INTERVAL] = user_input.get(CONF_OPTION_SPOTIFY_SCAN_INTERVAL, DEFAULT_OPTION_SPOTIFY_SCAN_INTERVAL)
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)
self._Options[CONF_OPTION_SOURCE_LIST_HIDE] = user_input.get(CONF_OPTION_SOURCE_LIST_HIDE, None)
Expand All @@ -386,6 +389,11 @@ async def async_step_init(self, user_input:dict[str,Any]=None) -> FlowResult:
if (deviceUsername is not None) and (deviceLoginid is None):
errors["base"] = "device_loginid_required"

# spotify scan interval must be in the 4 to 60 range (if specified).
spotifyScanInterval:int = user_input.get(CONF_OPTION_SPOTIFY_SCAN_INTERVAL, DEFAULT_OPTION_SPOTIFY_SCAN_INTERVAL)
if (spotifyScanInterval is not None) and ((spotifyScanInterval < 4) or (spotifyScanInterval > 60)):
errors["base"] = "spotify_scan_interval_range_invalid"

# any validation errors? if not, then ...
if "base" not in errors:

Expand Down Expand Up @@ -432,6 +440,9 @@ async def async_step_init(self, user_input:dict[str,Any]=None) -> FlowResult:
vol.Optional(CONF_OPTION_DEVICE_PASSWORD,
description={"suggested_value": self._Options.get(CONF_OPTION_DEVICE_PASSWORD)},
): cv.string,
vol.Optional(CONF_OPTION_SPOTIFY_SCAN_INTERVAL,
description={"suggested_value": self._Options.get(CONF_OPTION_SPOTIFY_SCAN_INTERVAL)},
): cv.positive_int,
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,
Expand Down
3 changes: 3 additions & 0 deletions custom_components/spotifyplus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
CONF_OPTION_SCRIPT_TURN_ON = "script_turn_on"
CONF_OPTION_SCRIPT_TURN_OFF = "script_turn_off"
CONF_OPTION_SOURCE_LIST_HIDE = "source_list_hide"
CONF_OPTION_SPOTIFY_SCAN_INTERVAL = "spotify_scan_interval"

DEFAULT_OPTION_SPOTIFY_SCAN_INTERVAL = 30

# security scopes required by various Spotify Web API endpoints.
SPOTIFY_SCOPES:list = \
Expand Down
10 changes: 10 additions & 0 deletions custom_components/spotifyplus/instancedata_spotifyplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
CONF_OPTION_DEVICE_LOGINID,
CONF_OPTION_DEVICE_PASSWORD,
CONF_OPTION_DEVICE_USERNAME,
CONF_OPTION_SPOTIFY_SCAN_INTERVAL,
CONF_OPTION_SCRIPT_TURN_OFF,
CONF_OPTION_SCRIPT_TURN_ON,
CONF_OPTION_SOURCE_LIST_HIDE,
DEFAULT_OPTION_SPOTIFY_SCAN_INTERVAL,
)

@dataclass
Expand Down Expand Up @@ -86,6 +88,14 @@ def OptionDeviceUsername(self) -> str | None:
"""
return self.options.get(CONF_OPTION_DEVICE_USERNAME, None)

@property
def OptionSpotifyScanInterval(self) -> int:
"""
Scan Interval (in seconds) to use when querying Spotify Player for current playstate.
Defaults to 30 (seconds) if not set.
"""
return self.options.get(CONF_OPTION_SPOTIFY_SCAN_INTERVAL, DEFAULT_OPTION_SPOTIFY_SCAN_INTERVAL)

@property
def OptionScriptTurnOff(self) -> str | None:
"""
Expand Down
Loading

0 comments on commit dd319cc

Please sign in to comment.