Refactor cleanup of BlueZ rules
@@ -134,6 +134,11 @@ class BleakClientBlueZDBus(BaseBleakClient):
)
return True
+ async def _cleanup(self) -> None:
+ for rule_name, rule_id in self._rules.items():
+ logger.debug("Removing rule {0}, ID: {1}".format(rule_name, rule_id))
+ await self._bus.delMatch(rule_id).asFuture(self.loop)
+
async def disconnect(self) -> bool:
"""Disconnect from the specified GATT server.
@@ -142,9 +147,9 @@ class BleakClientBlueZDBus(BaseBleakClient):
"""
logger.debug("Disconnecting from BLE device...")
- for rule_name, rule_id in self._rules.items():
- logger.debug("Removing rule {0}, ID: {1}".format(rule_name, rule_id))
- await self._bus.delMatch(rule_id).asFuture(self.loop)
+
+ await self._cleanup()
+
await self._bus.callRemote(
self._device_path,
"Disconnect",
