From 3783f74eb8aa58270567aadb2a4e63119c455450 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sun, 1 Nov 2026 21:51:22 +0100 Subject: [PATCH] fix(interfaces): report the WAN speed in Mbit/s NewLayer1DownstreamMaxBitRate is bit/s; dividing by 1000 gave kbit/s, so a 250 Mbit/s line came out as 250000 in a field NAPALM defines as Mbit/s. Closes #2 --- CHANGELOG.md | 2 ++ napalm_fritzbox/fritzbox.py | 5 ++++- tests/unit/test_driver.py | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5be912..51369b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ 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). ## [0.3.0] - 2026-10-23 diff --git a/napalm_fritzbox/fritzbox.py b/napalm_fritzbox/fritzbox.py index acd5444..0ee4466 100644 --- a/napalm_fritzbox/fritzbox.py +++ b/napalm_fritzbox/fritzbox.py @@ -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: diff --git a/tests/unit/test_driver.py b/tests/unit/test_driver.py index d006c65..bccc8dc 100644 --- a/tests/unit/test_driver.py +++ b/tests/unit/test_driver.py @@ -393,6 +393,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"