Empty string in gateway returns none (#3873)

This commit is contained in:
Mike Degatano 2022-09-17 10:24:56 -04:00 committed by GitHub
parent 50c277137d
commit cd10b597dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -39,9 +39,13 @@ class IpConfiguration(DBusInterfaceProxy):
@property @property
@dbus_property @dbus_property
def gateway(self) -> IPv4Address | IPv6Address: def gateway(self) -> IPv4Address | IPv6Address | None:
"""Get gateway.""" """Get gateway."""
return ip_address(self.properties[DBUS_ATTR_GATEWAY]) return (
ip_address(self.properties[DBUS_ATTR_GATEWAY])
if self.properties.get(DBUS_ATTR_GATEWAY)
else None
)
@property @property
@dbus_property @dbus_property

View File

@ -40,3 +40,11 @@ async def test_ipv6_configuration(network_manager: NetworkManager):
fire_property_change_signal(ipv6, {}, ["Gateway"]) fire_property_change_signal(ipv6, {}, ["Gateway"])
await asyncio.sleep(0) await asyncio.sleep(0)
assert ipv6.gateway == IPv6Address("fe80::da58:d7ff:fe00:9c69") assert ipv6.gateway == IPv6Address("fe80::da58:d7ff:fe00:9c69")
async def test_gateway_empty_string(network_manager: NetworkManager):
"""Test empty string in gateway returns None."""
ipv4 = network_manager.interfaces[TEST_INTERFACE].connection.ipv4
fire_property_change_signal(ipv4, {"Gateway": ""})
await asyncio.sleep(0)
assert ipv4.gateway is None