get_entity_info(): AttributeError when client.players.get() returns None
get_entity_info() in utils.py dereferences client.players.get(player_id) without a None check, so the get_entity_info websocket command fails with a generic unknown_error.
I see this reliably after a Home Assistant restart: dashboard clients reconnect and call get_entity_info before the Music Assistant integration has finished registering its players, so the lookup misses.
Traceback:
File "custom_components/mass_queue/websocket_commands.py", line 38, in api_get_entity_info
result = get_entity_info(hass, entity_id)
File "custom_components/mass_queue/utils.py", line 339, in get_entity_info
available = player.available
AttributeError: 'NoneType' object has no attribute 'available'
Cause:
player = client.players.get(player_id) # can return None
...
available = player.available # line 339
A typed error here would also let clients back off and retry instead of just seeing unknown_error:
player = client.players.get(player_id)
if player is None:
raise ServiceValidationError(f"Music Assistant player {player_id} is not available yet")
entity_registry.async_get(entity_id) and device_registry.async_get(dev_id) a few lines above can return None as well.
Not sure how that would happen since it would fail by then if the player ID isn't set. However, I have pushed a PR to throw an error.
Whoa, you're fast, thanks!!
It's a startup race condition since player_id comes from the HA device registry and client.players is a runtime dict populated over websocket from the MA server. Since HA device registry is persisted to disk and fully available the instant HA starts, there can be a window of time at startup where the device lookup succeeds and players.get() returns None. That's the race I can consistently hit on HA restarts.