fix(driver): raise from getters instead of answering defaults (#9) #10

Merged
christianmanivong merged 1 commits from fix/bugs-2026-11-02 into main 2026-11-02 08:23:40 +00:00
Owner

What

get_volume(), get_mute(), get_playback_state() and get_current_track() raise instead of answering defaults.

  • Not connected: ConnectionClosedException (was 0 / False / "STOPPED" / {}).
  • Speaker unreachable (requests' errors are OSErrors): ConnectionException; an error the speaker answers with (SoCoException, e.g. a UPnP fault): CommandErrorException. The SoCo error stays attached as __cause__.
  • get_playback_state() called get_playback_state() on the SoCo object, which SoCo (0.31.2, and the 0.30 floor) does not have; the AttributeError was swallowed and every speaker read as STOPPED. It now returns get_current_transport_info()["current_transport_state"].

The test speaker is now MagicMock(spec=soco.SoCo), so a call to a method SoCo lacks fails the test instead of being invented by the mock.

netOrk does not call these getters today, so nothing changes there.

Not in this PR

The wired-speaker detection (see #2) stays open: deviceProperties in SoCo is the UPnP DeviceProperties service, and none of its actions reports wired vs. wireless (GetZoneInfo returns serial, versions, IP, MAC, HTAudioIn, Flags, ExtraInfo); the only candidate, EthLink, is an evented variable that needs a UPnP event subscription. Renaming the attribute would still never report eth0. That needs a decision, written up separately.

Tests

Fixtures only (no speaker). Red first: the new tests for the transport state, the four not-connected cases and the failed reads failed against main; all pass now. pytest (42 passed), ruff format/check, mypy, napalm-standard ratchet green, coverage 78.8 % (floor 71).

Closes #9

## What `get_volume()`, `get_mute()`, `get_playback_state()` and `get_current_track()` raise instead of answering defaults. - Not connected: `ConnectionClosedException` (was `0` / `False` / `"STOPPED"` / `{}`). - Speaker unreachable (`requests`' errors are `OSError`s): `ConnectionException`; an error the speaker answers with (`SoCoException`, e.g. a UPnP fault): `CommandErrorException`. The SoCo error stays attached as `__cause__`. - `get_playback_state()` called `get_playback_state()` on the SoCo object, which SoCo (0.31.2, and the 0.30 floor) does not have; the `AttributeError` was swallowed and every speaker read as `STOPPED`. It now returns `get_current_transport_info()["current_transport_state"]`. The test speaker is now `MagicMock(spec=soco.SoCo)`, so a call to a method SoCo lacks fails the test instead of being invented by the mock. netOrk does not call these getters today, so nothing changes there. ## Not in this PR The wired-speaker detection (see #2) stays open: `deviceProperties` in SoCo is the UPnP `DeviceProperties` service, and none of its actions reports wired vs. wireless (`GetZoneInfo` returns serial, versions, IP, MAC, `HTAudioIn`, `Flags`, `ExtraInfo`); the only candidate, `EthLink`, is an evented variable that needs a UPnP event subscription. Renaming the attribute would still never report `eth0`. That needs a decision, written up separately. ## Tests Fixtures only (no speaker). Red first: the new tests for the transport state, the four not-connected cases and the failed reads failed against main; all pass now. pytest (42 passed), ruff format/check, mypy, `napalm-standard ratchet` green, coverage 78.8 % (floor 71). Closes #9
christianmanivong added 1 commit 2026-11-02 07:39:00 +00:00
fix(driver): raise from getters instead of answering defaults
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m21s
driver / test (3.12) (pull_request) Successful in 3m44s
driver / test (3.13) (pull_request) Successful in 3m19s
driver / lowest (pull_request) Successful in 2m49s
driver / build (pull_request) Successful in 37s
driver / security (pull_request) Successful in 1m16s
CI / driver (pull_request) Successful in 5m32s
driver / publish (pull_request) Skipped
15ba670a02
get_volume, get_mute, get_playback_state and get_current_track
answered 0, False, "STOPPED" and {} when the driver was not connected
or the read failed, so an unreachable speaker looked like a silent,
stopped one. They now raise ConnectionClosedException, or
ConnectionException / CommandErrorException with the SoCo error as
the cause.

get_playback_state called get_playback_state() on the SoCo object,
which SoCo does not have; the AttributeError was swallowed and every
speaker read as STOPPED. It now reads current_transport_state from
get_current_transport_info(). The tests mock the speaker with
MagicMock(spec=soco.SoCo), so a call to a method SoCo lacks fails.

Closes #9
christianmanivong merged commit 7a9acd5bbb into main 2026-11-02 08:23:40 +00:00
christianmanivong deleted branch fix/bugs-2026-11-02 2026-11-02 08:23:40 +00:00
Sign in to join this conversation.