hassio-addons / addon-spotify-connect

Spotify Connect - Home Assistant Community Add-ons
https://addons.community
MIT License
170 stars 51 forks source link

Source shown in Spotify App, but not in HA Integration / Spotify API #234

Closed Alwinator closed 10 months ago

Alwinator commented 11 months ago

Problem/Motivation

Everything worked fine for a long time until I updated HA. After that I could still use Spotify Connect without a problem, however, the device was not shown anymore in the Spotify Integration. I first assumed it was an issue with the integration (see https://github.com/home-assistant/core/issues/97867), however, after writing the following script I found out that it was the Spotify API.

config.yml

auth_manager:
    client_id: xxx
    client_secret: xxx
    redirect_uri: http://localhost:7777

test.py

import spotipy
import yaml
from spotipy import SpotifyOAuth

with open("config.yml", "r") as stream:
    config = yaml.safe_load(stream)

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope="user-read-playback-state", **config['auth_manager']))
print("Authenticated as {}".format(sp.current_user()['display_name']))

res = sp.devices()
for device in res.get("devices"):
    print(device)

Expected behavior

The device should be listed in the Spotify sources.

Actual behavior

There are two devices listed, however my HA Spotify is not listed.

Authenticated as Alwin
{'id': 'xxx', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'My TV', 'supports_volume': True, 'type': 'TV', 'volume_percent': 6}
{'id': 'xxx', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'My PC', 'supports_volume': True, 'type': 'Computer', 'volume_percent': 100}

Steps to reproduce

  1. Setup HA with Spotify Connect with the same versions
  2. Use my attached script

Logs

In my opinion the logs are looking fine:

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service base-addon-banner: starting
-----------------------------------------------------------
 Add-on: Spotify Connect
 Play Spotify music on your Home Assistant device
-----------------------------------------------------------
 Add-on version: 0.12.4
 You are running the latest version of this add-on.
 System: Home Assistant OS 10.4  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2023.8.1
 Home Assistant Supervisor: 2023.08.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
s6-rc: info: service base-addon-banner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service base-addon-log-level: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service base-addon-log-level successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun spotifyd (no readiness notification)
s6-rc: info: service legacy-services successfully started
[20:18:36] INFO: Starting the Spotify daemon...
[2023-08-09T18:18:37Z INFO  librespot] librespot 0.4.2 UNKNOWN (Built on 2023-05-17, Build ID: PtL7ynVq, Profile: release)

It also works with the official Spotify app.

Alwinator commented 10 months ago

Not sure what the root cause was, but this bug magically fixed itself. I assume it was a bug in the Spotify API and was fixed by the Spotify team.