Skip to content

Commit

Permalink
[ 1.0.25 ] * Fixed a bug that was causing `ValueError: list.remove(x)…
Browse files Browse the repository at this point in the history
…: x not in list` exceptions to be raised whenever the user changed configuration options for a service. This started appearing with the HA 2024.6.1 release.
  • Loading branch information
thlucas1 committed Jun 8, 2024
1 parent 5c92cc6 commit 88b0b60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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.25 ] - 2024/06/08

* Fixed a bug that was causing `ValueError: list.remove(x): x not in list` exceptions to be raised whenever the user changed configuration options for a service. This started appearing with the HA 2024.6.1 release.

###### [ 1.0.24 ] - 2024/06/07

* Updated underlying `spotifywebapiPython` package requirement to version 1.0.46.
Expand Down
11 changes: 8 additions & 3 deletions custom_components/spotifyplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,7 @@ def _TokenUpdater() -> dict:
# - get a reference to the HA OAuth2 session instance.
# - call `async_refresh_token` to refresh the expired token.
# - set a token `status` attribute to denote the configuration update is for a token refresh event. this allows the
# `options_update_listener` to bypass the confgiuration reload processing since we only need to reload the configuration
# `options_update_listener` to bypass the configuration reload processing since we only need to reload the configuration
# if the user initiated an options change via the UI (e.g. no need to reload the configuration for token updates).
# - call the `add_job` method to add a job that will call `async_update_entry` to persist the refreshed token to config storage.
# - return the refreshed token to the caller.
Expand Down Expand Up @@ -2004,6 +2004,9 @@ async def async_unload_entry(hass:HomeAssistant, entry:ConfigEntry) -> bool:
to be removed, as they are already removed by the time this method is called.
This is accomplished by the "entry.async_on_unload(listener)" call in async_setup_entry,
which removes them from the configuration entry just before it is unloaded.
Note that something changed with HA 2024.6 release that causes the `update_listeners` array
to still contain entries; prior to this release, the `update_listeners` array was empty by this point.
"""
try:

Expand All @@ -2025,8 +2028,10 @@ async def async_unload_entry(hass:HomeAssistant, entry:ConfigEntry) -> bool:

# a quick check to make sure all update listeners were removed (see method doc notes above).
if len(entry.update_listeners) > 0:
_logsi.LogArray(SILevel.Warning, "'%s': Component configuration update_listener(s) did not get removed before configuration unload (%d items - should be 0)" % (entry.title, len(entry.update_listeners)), entry.update_listeners)
entry.update_listeners.clear()
_logsi.LogArray(SILevel.Warning, "'%s': Component configuration update_listener(s) did not get removed before configuration unload (%d items - should be 0 prioer to HA 2026.0 release, but after that release still contains entries)" % (entry.title, len(entry.update_listeners)), entry.update_listeners)
# 2024/06/08 - I commented out the following line to clear the `update_listeners`, as it was causing `ValueError: list.remove(x): x not in list`
# exceptions starting with the HA 2024.6.0 release!
#entry.update_listeners.clear()

# return status to caller.
_logsi.LogVerbose("'%s': Component async_unload_entry completed" % entry.title)
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 @@ -18,6 +18,6 @@
"urllib3>=1.21.1,<1.27",
"zeroconf>=0.132.2"
],
"version": "1.0.24",
"version": "1.0.25",
"zeroconf": [ "_spotify-connect._tcp.local." ]
}

0 comments on commit 88b0b60

Please sign in to comment.