diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ab51b831..f4024fc7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ and this project adheres to `Semantic Versioning None: # need to remove callbacks first, otherwise we get TxPower # and RSSI properties removed during stop which causes # incorrect advertisement data callbacks - self._advertisement_callbacks.remove(callback_and_state) + self._advertisement_callbacks[adapter_path].remove( + advertisement_callback + ) self._device_removed_callbacks.remove( device_removed_callback_and_state ) @@ -478,7 +467,9 @@ async def stop() -> None: return stop except BaseException: # if starting scanning failed, don't leak the callbacks - self._advertisement_callbacks.remove(callback_and_state) + self._advertisement_callbacks[adapter_path].remove( + advertisement_callback + ) self._device_removed_callbacks.remove(device_removed_callback_and_state) raise @@ -512,8 +503,7 @@ async def passive_scan( # error message. self._check_adapter(adapter_path) - callback_and_state = CallbackAndState(advertisement_callback, adapter_path) - self._advertisement_callbacks.append(callback_and_state) + self._advertisement_callbacks[adapter_path].append(advertisement_callback) device_removed_callback_and_state = DeviceRemovedCallbackAndState( device_removed_callback, adapter_path @@ -556,7 +546,9 @@ async def stop() -> None: # need to remove callbacks first, otherwise we get TxPower # and RSSI properties removed during stop which causes # incorrect advertisement data callbacks - self._advertisement_callbacks.remove(callback_and_state) + self._advertisement_callbacks[adapter_path].remove( + advertisement_callback + ) self._device_removed_callbacks.remove( device_removed_callback_and_state ) @@ -580,7 +572,9 @@ async def stop() -> None: except BaseException: # if starting scanning failed, don't leak the callbacks - self._advertisement_callbacks.remove(callback_and_state) + self._advertisement_callbacks[adapter_path].remove( + advertisement_callback + ) self._device_removed_callbacks.remove(device_removed_callback_and_state) raise @@ -926,7 +920,7 @@ def _parse_msg(self, message: Message) -> None: # devices that only advertise once and then go to sleep for a while. elif interface == defs.DEVICE_INTERFACE: self._run_advertisement_callbacks( - obj_path, cast(Device1, unpacked_props), unpacked_props.keys() + obj_path, cast(Device1, unpacked_props) ) elif message.member == "InterfacesRemoved": obj_path, interfaces = message.body @@ -1003,7 +997,7 @@ def _parse_msg(self, message: Message) -> None: device_path = message_path self._run_advertisement_callbacks( - device_path, cast(Device1, self_interface), changed.keys() + device_path, cast(Device1, self_interface) ) # handle device condition watchers @@ -1035,22 +1029,16 @@ def _parse_msg(self, message: Message) -> None: message_path, new_value ) - def _run_advertisement_callbacks( - self, device_path: str, device: Device1, changed: Iterable[str] - ) -> None: + def _run_advertisement_callbacks(self, device_path: str, device: Device1) -> None: """ Runs any registered advertisement callbacks. Args: device_path: The D-Bus object path of the remote device. device: The current D-Bus properties of the device. - changed: A list of properties that have changed since the last call. """ - for callback, adapter_path in self._advertisement_callbacks: - # filter messages from other adapters - if adapter_path != device["Adapter"]: - continue - + adapter_path = device["Adapter"] + for callback in self._advertisement_callbacks[adapter_path]: callback(device_path, device.copy())