Fix bluetooth diagnostics on macos (#79680)

* Fix bluetooth diagnostics on macos

The pyobjc objects cannot be pickled which cases dataclasses
asdict to raise an exception when trying to do the deepcopy

We now implement our own as_dict to avoid this problem

* add cover
This commit is contained in:
J. Nick Koston 2022-10-05 16:32:29 -10:00 committed by GitHub
parent 558b327928
commit c798723c27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 6 deletions

View file

@ -53,6 +53,25 @@ class BluetoothServiceInfoBleak(BluetoothServiceInfo):
connectable: bool
time: float
def as_dict(self) -> dict[str, Any]:
"""Return as dict.
The dataclass asdict method is not used because
it will try to deepcopy pyobjc data which will fail.
"""
return {
"name": self.name,
"address": self.address,
"rssi": self.rssi,
"manufacturer_data": self.manufacturer_data,
"service_data": self.service_data,
"service_uuids": self.service_uuids,
"source": self.source,
"advertisement": self.advertisement,
"connectable": self.connectable,
"time": self.time,
}
class BluetoothScanningMode(Enum):
"""The mode of scanning for bluetooth devices."""