fix(driver): refuse media controls when not connected
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m18s
driver / test (3.12) (pull_request) Successful in 3m14s
driver / test (3.13) (pull_request) Successful in 2m54s
driver / lowest (pull_request) Successful in 2m23s
driver / build (pull_request) Successful in 35s
driver / security (pull_request) Successful in 1m11s
CI / driver (pull_request) Successful in 4m53s
driver / publish (pull_request) Skipped

play() and the other controls returned silently without a device, so
a control that did nothing looked like it had worked. They now raise
ConnectionClosedException. get_arp_table() takes NAPALM's vrf
argument, and the module docstring moves above the imports so
__doc__ is set again.

The wired-speaker part of the issue stays open: SoCo's
deviceProperties is a UPnP service, not a dict with WifiMode, so
renaming the attribute alone would still never report eth0.

Refs #2
This commit is contained in:
Christian Manivong committed 2026-11-01 21:53:55 +01:00
1 parent 0ed6a7093d
commit 322b7cd688
3 files changed
+61 -33

No files matched your search

+31 -1
View File
@@ -1,6 +1,7 @@
from unittest.mock import MagicMock, patch
from napalm.base.exceptions import ConnectionException
import pytest
from napalm.base.exceptions import ConnectionClosedException, ConnectionException
from napalm_sonos import SonosDriver
@@ -179,3 +180,32 @@ class TestSonosDriver:
self.driver.set_volume(42)
self.mock_device.play.assert_called_once()
assert self.mock_device.volume == 42
def test_the_driver_module_has_its_docstring():
import napalm_sonos.sonos_driver as module
assert module.__doc__ and "Sonos" in module.__doc__
def test_get_arp_table_takes_napalms_vrf_argument():
assert SonosDriver("192.168.1.100").get_arp_table(vrf="") == []
@pytest.mark.parametrize(
"control",
[
lambda d: d.play(),
lambda d: d.pause(),
lambda d: d.stop(),
lambda d: d.next_track(),
lambda d: d.previous_track(),
lambda d: d.set_volume(10),
lambda d: d.set_mute(True),
],
ids=["play", "pause", "stop", "next_track", "previous_track", "set_volume", "set_mute"],
)
def test_a_media_control_refuses_when_not_connected(control):
"""Returning silently made a control that did nothing look like it had worked."""
with pytest.raises(ConnectionClosedException):
control(SonosDriver("192.168.1.100"))