mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-15 21:26:29 +00:00
Handle dbus single byte (#2237)
This commit is contained in:
parent
0a7c75830b
commit
c4847ad10d
@ -44,7 +44,7 @@ class NetworkWirelessAP(DBusInterfaceProxy):
|
||||
@property
|
||||
def strength(self) -> int:
|
||||
"""Return details about mac address."""
|
||||
return int(self.properties[DBUS_ATTR_STRENGTH])
|
||||
return int(self.properties[DBUS_ATTR_STRENGTH][0])
|
||||
|
||||
async def connect(self) -> None:
|
||||
"""Get connection information."""
|
||||
|
@ -150,7 +150,7 @@ class NetworkManager(CoreSysAttributes):
|
||||
try:
|
||||
await accesspoint.connect()
|
||||
except DBusError as err:
|
||||
_LOGGER.waring("Can't process an AP: %s", err)
|
||||
_LOGGER.warning("Can't process an AP: %s", err)
|
||||
continue
|
||||
else:
|
||||
accesspoints.append(
|
||||
|
@ -34,7 +34,7 @@ RE_GVARIANT_STRING: re.Pattern[Any] = re.compile(
|
||||
r"(?<=(?: |{|\[|\(|<))'(.*?)'(?=(?:|]|}|,|\)|>))"
|
||||
)
|
||||
RE_GVARIANT_BINARY: re.Pattern[Any] = re.compile(
|
||||
r"\"[^\"\\]*(?:\\.[^\"\\]*)*\"|\[byte (.*?)\]|\[(0x[0-9A-Za-z]{2}.*?)\]"
|
||||
r"\"[^\"\\]*(?:\\.[^\"\\]*)*\"|\[byte (.*?)\]|\[(0x[0-9A-Za-z]{2}.*?)\]|<byte (.*?)>"
|
||||
)
|
||||
RE_GVARIANT_BINARY_STRING: re.Pattern[Any] = re.compile(
|
||||
r"\"[^\"\\]*(?:\\.[^\"\\]*)*\"|<?b\'(.*?)\'>?"
|
||||
@ -143,8 +143,8 @@ class DBus:
|
||||
# Handle Bytes
|
||||
json_raw = RE_GVARIANT_BINARY.sub(
|
||||
lambda x: x.group(0)
|
||||
if not (x.group(1) or x.group(2))
|
||||
else _convert_bytes(x.group(1) or x.group(2)),
|
||||
if not (x.group(1) or x.group(2) or x.group(3))
|
||||
else _convert_bytes(x.group(1) or x.group(2) or x.group(3)),
|
||||
json_raw,
|
||||
)
|
||||
json_raw = RE_GVARIANT_BINARY_STRING.sub(
|
||||
|
@ -7,6 +7,6 @@
|
||||
"HwAddress": "E4:57:40:A9:D7:DE",
|
||||
"Mode": 2,
|
||||
"MaxBitrate": 195000,
|
||||
"Strength": 47,
|
||||
"Strength": [47],
|
||||
"LastSeen": 1398776
|
||||
}
|
||||
|
@ -7,6 +7,6 @@
|
||||
"HwAddress": "18:4B:0D:23:A1:9C",
|
||||
"Mode": 2,
|
||||
"MaxBitrate": 540000,
|
||||
"Strength": 63,
|
||||
"Strength": [63],
|
||||
"LastSeen": 1398839
|
||||
}
|
||||
|
@ -473,3 +473,25 @@ def test_v6():
|
||||
],
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_single_byte():
|
||||
"""Test a singlebyte response."""
|
||||
raw = "({'Flags': <uint32 1>, 'WpaFlags': <uint32 0>, 'RsnFlags': <uint32 392>, 'Ssid': <[byte 0x53, 0x59, 0x53, 0x48, 0x41, 0x43, 0x4b, 0x5f, 0x48, 0x6f, 0x6d, 0x65]>, 'Frequency': <uint32 5660>, 'HwAddress': <'18:4B:0D:A3:A1:9C'>, 'Mode': <uint32 2>, 'MaxBitrate': <uint32 540000>, 'Strength': <byte 0x2c>, 'LastSeen': <1646569>},)"
|
||||
|
||||
data = DBus.parse_gvariant(raw)
|
||||
|
||||
assert data == [
|
||||
{
|
||||
"Flags": 1,
|
||||
"Frequency": 5660,
|
||||
"HwAddress": "18:4B:0D:A3:A1:9C",
|
||||
"LastSeen": 1646569,
|
||||
"MaxBitrate": 540000,
|
||||
"Mode": 2,
|
||||
"RsnFlags": 392,
|
||||
"Ssid": [83, 89, 83, 72, 65, 67, 75, 95, 72, 111, 109, 101],
|
||||
"Strength": [44],
|
||||
"WpaFlags": 0,
|
||||
}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user