diff --git a/src/habluetooth/manager.py b/src/habluetooth/manager.py index 6283c09..da67633 100644 --- a/src/habluetooth/manager.py +++ b/src/habluetooth/manager.py @@ -564,7 +564,7 @@ def scanner_adv_received(self, service_info: BluetoothServiceInfoBleak) -> None: service_info.service_uuids, source, service_info.device, - service_info.advertisement, + service_info._advertisement, True, service_info.time, service_info.tx_power, diff --git a/src/habluetooth/models.py b/src/habluetooth/models.py index 439f665..fe8a4b9 100644 --- a/src/habluetooth/models.py +++ b/src/habluetooth/models.py @@ -173,12 +173,28 @@ def __init__( self.time = time self.tx_power = tx_power + def __repr__(self) -> str: + """Return the representation of the object.""" + return ( + f"<{self.__class__.__name__} " + f"name={self.name} " + f"address={self.address} " + f"rssi={self.rssi} " + f"manufacturer_data={self.manufacturer_data} " + f"service_data={self.service_data} " + f"service_uuids={self.service_uuids} " + f"source={self.source} " + f"connectable={self.connectable} " + f"time={self.time} " + f"tx_power={self.tx_power}>" + ) + @property def advertisement(self) -> AdvertisementData: """Get the advertisement data.""" if self._advertisement is None: self._advertisement = AdvertisementData( - None if self.name == "" else self.name, + None if self.name == "" or self.name == self.address else self.name, self.manufacturer_data, self.service_data, self.service_uuids, diff --git a/tests/test_models.py b/tests/test_models.py index 657b3aa..88e4999 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -172,6 +172,12 @@ def test_from_device_and_advertisement_data(): "time": now_monotonic, "tx_power": -127, } + assert str(service_info) == ( + "" + ) def test_pyobjc_compat():