getters return defaults instead of raising; get_playback_state calls a method SoCo does not have and always says STOPPED #9

Closed
opened 2026-11-01 21:44:47 +00:00 by christianmanivong · 0 comments
Owner

What happens

get_volume, get_mute, get_playback_state and get_current_track (napalm_sonos/sonos_driver.py ~310-345) return a default when the driver is not connected (self._device is None) and swallow every exception (# Broad catch: SoCo transport errors are unpredictable): volume 0, mute False, state "STOPPED", track {}. A speaker that is unreachable reads as a silent, stopped speaker. The setters (set_volume, set_mute, play, …) silently do nothing when not connected.

get_playback_state is worse: it calls self._device.get_playback_state() (line 316), and SoCo has no such method (none in soco 0.31.2, the version in netOrk's venv; the state is get_current_transport_info()["current_transport_state"]). The AttributeError is swallowed, so the getter returns "STOPPED" for every speaker. The unit test mocks the device with a MagicMock that invents the method (tests/test_sonos.py:29), which is why it passes.

Expected

  • Not connected → ConnectionClosedException; a failed read raises (wrapped with the cause).
  • get_playback_state reads get_current_transport_info()["current_transport_state"].
  • Tests use MagicMock(spec=soco.SoCo) so a call to a method SoCo lacks fails.

Priority: P4 — netOrk does not call these getters today; they report wrong values for any other user.

Found during the bug sweep of 2026-11-01.

## What happens `get_volume`, `get_mute`, `get_playback_state` and `get_current_track` (`napalm_sonos/sonos_driver.py` ~310-345) return a default when the driver is not connected (`self._device is None`) and swallow every exception (`# Broad catch: SoCo transport errors are unpredictable`): volume `0`, mute `False`, state `"STOPPED"`, track `{}`. A speaker that is unreachable reads as a silent, stopped speaker. The setters (`set_volume`, `set_mute`, `play`, …) silently do nothing when not connected. `get_playback_state` is worse: it calls `self._device.get_playback_state()` (line 316), and SoCo has no such method (none in soco 0.31.2, the version in netOrk's venv; the state is `get_current_transport_info()["current_transport_state"]`). The `AttributeError` is swallowed, so the getter returns `"STOPPED"` for every speaker. The unit test mocks the device with a `MagicMock` that invents the method (`tests/test_sonos.py:29`), which is why it passes. ## Expected - Not connected → `ConnectionClosedException`; a failed read raises (wrapped with the cause). - `get_playback_state` reads `get_current_transport_info()["current_transport_state"]`. - Tests use `MagicMock(spec=soco.SoCo)` so a call to a method SoCo lacks fails. Priority: P4 — netOrk does not call these getters today; they report wrong values for any other user. Found during the bug sweep of 2026-11-01.
christianmanivong added the
prio
P4
bug
labels 2026-11-01 21:44:47 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-sonos#9