fix(driver): stop guessing whether a speaker is wired

The wired check read device_properties, which SoCo does not have
(deviceProperties is the UPnP service, and none of its actions says
wired or wireless), and swallowed the AttributeError, so eth0 was never
reported and the guess served nothing. It is gone: a speaker reports
its one connection as wlan0, described as of unknown medium, and the
README and the getter docstrings say that wired vs. wireless is not
known.

Closes #2
This commit is contained in:
Christian Manivong committed 2026-11-02 09:26:58 +01:00
1 parent 7a9acd5bbb
commit 53ea5f051f
4 files changed
+38 -44

No files matched your search

+16 -43
View File
@@ -24,6 +24,9 @@ _T = TypeVar("_T")
logger = logging.getLogger(__name__)
#: The speaker's one network connection. Wired or wireless is not known (#2).
_INTERFACE = "wlan0"
class SonosDriver(MediaDriver):
"""NAPALM driver for controlling Sonos speakers.
@@ -110,54 +113,29 @@ class SonosDriver(MediaDriver):
"hostname": info.get("player_name", self.hostname),
"fqdn": info.get("ip_address", self.hostname),
"uptime": 0,
"interface_list": self._detect_interfaces(info),
"interface_list": [_INTERFACE],
}
def _detect_interfaces(self, info: dict[str, Any]) -> list[str]:
ifaces: list[str] = []
has_eth = self._check_wired_connection()
if has_eth:
ifaces.append("eth0")
ifaces.append("wlan0")
return ifaces
def _check_wired_connection(self) -> bool:
if self._device is None:
return False
try:
props = self._device.device_properties
if isinstance(props, dict):
wifimode = props.get("WifiMode", "")
return wifimode in ("0", "", None)
except Exception:
# Broad catch: SoCo device_properties may fail for many reasons
logger.debug("Sonos device properties: ignored", exc_info=True)
return False
def get_interfaces(self) -> dict[str, dict[str, Any]]:
"""Return interface information for this speaker."""
"""Return the speaker's one network connection, as ``wlan0``.
Whether the speaker is wired or wireless is not known: SoCo offers no
reading for it (``deviceProperties`` is a UPnP service whose actions do
not say), so the driver reports no ``eth0`` and does not guess. The
name ``wlan0`` is kept for continuity; it stands for the connection,
whatever its medium.
"""
if not self._speaker_info:
return {}
info = self._speaker_info
mac = info.get("mac_address", "")
is_up = self.is_alive().get("is_alive", False)
has_eth = self._check_wired_connection()
interfaces: dict[str, dict[str, Any]] = {}
if has_eth:
interfaces["eth0"] = {
"is_up": is_up,
"is_enabled": True,
"description": "Ethernet",
"last_flapped": -1.0,
"speed": 100,
"mtu": 1500,
"mac_address": mac,
}
interfaces["wlan0"] = {
interfaces[_INTERFACE] = {
"is_up": is_up,
"is_enabled": True,
"description": "WiFi",
"description": "Network (wired or wireless unknown)",
"last_flapped": -1.0,
"speed": 0,
"mtu": 1500,
@@ -166,23 +144,18 @@ class SonosDriver(MediaDriver):
return interfaces
def get_interfaces_ip(self) -> dict[str, dict[str, Any]]:
"""Return IP address information for the speaker interfaces."""
"""Return the speaker's address, on its one connection (see :meth:`get_interfaces`)."""
if not self._speaker_info:
return {}
info = self._speaker_info
ip = info.get("ip_address", self.hostname)
has_eth = self._check_wired_connection()
ipv4_entry = {
ip: {
"prefix_length": 24,
}
}
interfaces: dict[str, Any] = {}
if has_eth:
interfaces["eth0"] = {"ipv4": ipv4_entry, "ipv6": {}}
interfaces["wlan0"] = {"ipv4": ipv4_entry, "ipv6": {}}
return interfaces
return {_INTERFACE: {"ipv4": ipv4_entry, "ipv6": {}}}
def get_arp_table(self, vrf: str = "") -> list[dict[str, Any]]:
"""Return the ARP table (not supported on Sonos)."""