diff --git a/supervisor/dbus/network/configuration.py b/supervisor/dbus/network/configuration.py index 5aafc391b..716e583ff 100644 --- a/supervisor/dbus/network/configuration.py +++ b/supervisor/dbus/network/configuration.py @@ -68,3 +68,4 @@ class WirelessProperties: properties: dict = attr.ib() security: dict = attr.ib() + ssid: str = attr.ib() diff --git a/supervisor/dbus/network/connection.py b/supervisor/dbus/network/connection.py index 71aa78f21..3ca4ecdf7 100644 --- a/supervisor/dbus/network/connection.py +++ b/supervisor/dbus/network/connection.py @@ -1,7 +1,7 @@ """Connection object for Network Manager.""" from typing import Optional -from ...const import ATTR_ADDRESS, ATTR_IPV4, ATTR_METHOD, ATTR_PREFIX +from ...const import ATTR_ADDRESS, ATTR_IPV4, ATTR_METHOD, ATTR_PREFIX, ATTR_SSID from ...utils.gdbus import DBus from ..const import ( DBUS_ATTR_802_WIRELESS, @@ -134,6 +134,7 @@ class NetworkConnection(NetworkAttributes): self._wireless = WirelessProperties( data.get(DBUS_ATTR_802_WIRELESS, {}), data.get(DBUS_ATTR_802_WIRELESS_SECURITY, {}), + bytes(data.get(DBUS_ATTR_802_WIRELESS, {}).get(ATTR_SSID, [])).decode(), ) self._device = NetworkDevice( diff --git a/supervisor/dbus/payloads/generate.py b/supervisor/dbus/payloads/generate.py index 523c1e95b..3b740de47 100644 --- a/supervisor/dbus/payloads/generate.py +++ b/supervisor/dbus/payloads/generate.py @@ -35,10 +35,7 @@ def interface_update_payload(interface, **kwargs) -> str: kwargs[ATTR_SSID] = ", ".join( [ f"0x{x}" - for x in interface.connection.wireless.properties[ATTR_SSID] - .encode() - .hex(",") - .split(",") + for x in interface.connection.wireless.ssid.encode().hex(",").split(",") ] ) diff --git a/supervisor/utils/gdbus.py b/supervisor/utils/gdbus.py index 26b8b0594..84e4c18f2 100644 --- a/supervisor/utils/gdbus.py +++ b/supervisor/utils/gdbus.py @@ -10,6 +10,8 @@ from signal import SIGINT from typing import Any, Dict, List, Optional, Set import xml.etree.ElementTree as ET +import sentry_sdk + from ..exceptions import ( DBusFatalError, DBusInterfaceError, @@ -31,7 +33,7 @@ RE_GVARIANT_STRING_ESC: re.Pattern[Any] = re.compile( RE_GVARIANT_STRING: re.Pattern[Any] = re.compile( r"(?<=(?: |{|\[|\(|<))'(.*?)'(?=(?:|]|}|,|\)|>))" ) -RE_GVARIANT_BINARY: re.Pattern[Any] = re.compile(r"<\[byte (.*?)\]>") +RE_GVARIANT_BINARY: re.Pattern[Any] = re.compile(r"\[byte (.*?)\]") RE_GVARIANT_TUPLE_O: re.Pattern[Any] = re.compile(r"\"[^\"\\]*(?:\\.[^\"\\]*)*\"|(\()") RE_GVARIANT_TUPLE_C: re.Pattern[Any] = re.compile( r"\"[^\"\\]*(?:\\.[^\"\\]*)*\"|(,?\))" @@ -61,12 +63,7 @@ DBUS_METHOD_GETALL: str = "org.freedesktop.DBus.Properties.GetAll" def _convert_bytes(value: str) -> str: """Convert bytes to string or byte-array.""" data: bytes = bytes(int(char, 0) for char in value.split(", ")) - try: - text = data.decode() - except UnicodeDecodeError: - return f"<[{', '.join(str(char) for char in data)}]>" - - return f"<'{text}'>" + return f"[{', '.join(str(char) for char in data)}]" class DBus: @@ -153,7 +150,8 @@ class DBus: try: return json.loads(json_raw) except json.JSONDecodeError as err: - _LOGGER.critical("Can't parse '%s': '%s' - %s", json_raw, raw, err) + _LOGGER.error("Can't parse '%s': '%s' - %s", json_raw, raw, err) + sentry_sdk.capture_exception(err) raise DBusParseError() from err @staticmethod diff --git a/tests/dbus/payloads/test_interface_update_payload.py b/tests/dbus/payloads/test_interface_update_payload.py index 536064235..8a9634628 100644 --- a/tests/dbus/payloads/test_interface_update_payload.py +++ b/tests/dbus/payloads/test_interface_update_payload.py @@ -32,4 +32,4 @@ async def test_interface_update_payload_wireless(network_interface): ) assert DBus.parse_gvariant(data)["ipv4"]["method"] == "manual" assert DBus.parse_gvariant(data)["ipv4"]["address-data"][0]["address"] == "1.1.1.1" - assert DBus.parse_gvariant(data)["802-11-wireless"]["ssid"] == "NETT" + assert DBus.parse_gvariant(data)["802-11-wireless"]["ssid"] == [78, 69, 84, 84] diff --git a/tests/utils/test_gvariant_parser.py b/tests/utils/test_gvariant_parser.py index e3122c884..5e9d80ed8 100644 --- a/tests/utils/test_gvariant_parser.py +++ b/tests/utils/test_gvariant_parser.py @@ -325,7 +325,7 @@ def test_networkmanager_binary_data(): "mode": "infrastructure", "security": "802-11-wireless-security", "seen-bssids": ["7C:2E:BD:98:1B:06"], - "ssid": "NETT", + "ssid": [78, 69, 84, 84], }, "connection": { "id": "NETT", @@ -370,7 +370,7 @@ def test_networkmanager_binary_data(): "mode": "infrastructure", "security": "802-11-wireless-security", "seen-bssids": ["7C:2E:BD:98:1B:06"], - "ssid": "NETT", + "ssid": [78, 69, 84, 84], }, "802-11-wireless-security": {"auth-alg": "open", "key-mgmt": "wpa-psk"}, "connection": { @@ -402,3 +402,23 @@ def test_networkmanager_binary_data(): "proxy": {}, } ] + + +def test_v6(): + """Test IPv6 Property.""" + raw = "({'addresses': <[([byte 0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10], uint32 64, [byte 0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])]>, 'dns': <[[byte 0x20, 0x01, 0x04, 0x70, 0x79, 0x2d, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05]]>})" + + data = DBus.parse_gvariant(raw) + + assert data == [ + { + "addresses": [ + [ + [32, 1, 4, 112, 121, 45, 0, 1, 0, 18, 0, 0, 0, 0, 0, 16], + 64, + [32, 1, 4, 112, 121, 45, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], + ] + ], + "dns": [[32, 1, 4, 112, 121, 45, 0, 1, 0, 18, 0, 0, 0, 0, 0, 5]], + } + ]