fix: WAN speed in Mbit/s, time zone name (#2, #3) #10

Merged
christianmanivong merged 3 commits from fix/bugs-2026-11 into main 2026-11-01 22:00:38 +00:00
4 changed files with 44 additions and 6 deletions

No files matched your search

+7
View File
@@ -16,6 +16,13 @@ All notable changes to this driver. The format follows
- `get_arp_table()` reports an unknown age as `-1.0` (napalm-device-types'
`ARP_AGE_UNKNOWN`) instead of `0.0`, which means "confirmed just now": the host
list says a host is active, not when the box last saw it (NetOrk/netork#1327).
- `get_interfaces()` reports the `wan` speed in Mbit/s as NAPALM defines it: a
250 Mbit/s line was shown as 250000 (#2).
- `get_system_config()` reports the box's time zone (`NewLocalTimeZoneName`) as
`timezone`; it held the box's current local time (#3).
- `get_system_config()`'s `firmware_version` is documented for what it is: the
version the box offers as an update, empty when it offers none, not the running
version (that is `get_facts()["os_version"]`). Unchanged in behaviour (#3).
## [0.3.0] - 2026-10-23
+12
View File
@@ -66,6 +66,18 @@ d.close()
FritzBox serves TR-064 over HTTPS with a self-signed certificate; `fritzconnection`
does not verify it, so no separate `verify` option is needed.
## `get_system_config()`
A snapshot of the box's settings, every field best-effort (a TR-064 service the
box does not offer leaves its fields out). Two of them are easy to misread:
- `firmware_version` is the version the box **offers** as an update, empty when
it offers none — not the version running, which is `get_facts()["os_version"]`.
`firmware_update_available` says whether there is one. A box that only answers
`UserInterface1.GetInfo` (not `X_AVM-DE_GetInfo`) reports
`firmware_update_available` without `firmware_version`.
- `timezone` is the box's time zone name (`NewLocalTimeZoneName`).
## Limitations
- Read-only: configuration management methods (`load_merge_candidate`,
+9 -6
View File
@@ -66,6 +66,9 @@ _ANY_REMOTE = "0.0.0.0" # nosec B104
# (e.g. a service not present on a given FritzOS version/model).
_OPTIONAL_SERVICE_ERRORS = (FritzServiceError, FritzActionError, FritzConnectionException)
#: TR-064 reports the WAN sync rate in bit/s; NAPALM's interface ``speed`` is Mbit/s.
_BIT_PER_MBIT = 1_000_000
def _to_float(value: Any, default: float = 0.0) -> float:
"""Convert a TR-064 field to float, returning *default* for non-numeric values like 'Auto'."""
@@ -265,7 +268,7 @@ class FritzBoxDriver(ResidentialGatewayDriver):
"description": link.get("NewWANAccessType", "WAN"),
"last_flapped": -1.0,
"mac_address": "",
"speed": _to_float(link.get("NewLayer1DownstreamMaxBitRate")) / 1000,
"speed": _to_float(link.get("NewLayer1DownstreamMaxBitRate")) / _BIT_PER_MBIT,
"mtu": 1500,
}
except _OPTIONAL_SERVICE_ERRORS:
@@ -331,11 +334,11 @@ class FritzBoxDriver(ResidentialGatewayDriver):
return result
def get_system_config(self) -> dict[str, Any]:
"""Return a system configuration snapshot for storage as ``system_snapshot``.
"""Return a best-effort snapshot of DSL statistics, firmware updates, DNS and NTP.
Collects DSL line statistics, firmware update status, upstream DNS
servers and NTP settings. All fields are best-effort: missing
TR-064 services are silently skipped.
``firmware_version`` is the version on *offer* (empty when none), not the one
running (``get_facts()["os_version"]``); a box answering only
``UserInterface1.GetInfo`` leaves it out. A missing TR-064 service is skipped.
"""
available = self.fc.services if self.fc else {}
result: dict[str, Any] = {}
@@ -402,7 +405,7 @@ class FritzBoxDriver(ResidentialGatewayDriver):
time_info = self._call("Time1", "GetInfo")
result["ntp_server"] = time_info.get("NewNTPServer1", "")
result["ntp_server2"] = time_info.get("NewNTPServer2", "")
result["timezone"] = time_info.get("NewCurrentLocalTime", "")
result["timezone"] = time_info.get("NewLocalTimeZoneName", "")
except _OPTIONAL_SERVICE_ERRORS:
pass
+16
View File
@@ -161,6 +161,8 @@ TIME_INFO = {
"NewNTPServer1": "ntp.example.com",
"NewNTPServer2": "",
"NewCurrentLocalTime": "2026-06-24T16:00:00+02:00",
"NewLocalTimeZone": "+01:00",
"NewLocalTimeZoneName": "CET-1CEST,M3.5.0,M10.5.0/3",
}
IPV6_FIREWALL_STATUS = {"NewFirewallEnabled": True, "NewInboundPinholeAllowed": True}
@@ -393,6 +395,10 @@ class TestGetInterfaces:
assert interfaces["wan"]["is_up"] is True
assert interfaces["wan"]["description"] == "DSL"
def test_wan_speed_in_mbit(self, driver):
# NewLayer1DownstreamMaxBitRate is bit/s: 250 000 000 bit/s is 250 Mbit/s.
assert driver.get_interfaces()["wan"]["speed"] == 250.0
def test_wlan_interfaces_present(self, driver):
interfaces = driver.get_interfaces()
assert interfaces["wlanconfiguration1"]["description"] == "MyWifi"
@@ -708,6 +714,16 @@ class TestGetSystemConfig:
def test_ntp_server(self, driver):
assert driver.get_system_config()["ntp_server"] == "ntp.example.com"
def test_timezone_is_the_zone_name_not_the_clock(self, driver):
assert driver.get_system_config()["timezone"] == "CET-1CEST,M3.5.0,M10.5.0/3"
def test_timezone_empty_when_box_names_none(self, driver):
time_info = {k: v for k, v in TIME_INFO.items() if k != "NewLocalTimeZoneName"}
driver.fc.call_action.side_effect = lambda svc, act, **kw: (
time_info if (svc, act) == ("Time1", "GetInfo") else _call_action(svc, act, **kw)
)
assert driver.get_system_config()["timezone"] == ""
def test_empty_when_no_dsl_service(self, driver):
del driver.fc.services["WANDSLInterfaceConfig1"]
cfg = driver.get_system_config()