diff --git a/blueman/plugins/applet/AutoConnect.py b/blueman/plugins/applet/AutoConnect.py index e77d0ae4a..06cf67ba7 100644 --- a/blueman/plugins/applet/AutoConnect.py +++ b/blueman/plugins/applet/AutoConnect.py @@ -1,3 +1,4 @@ +import logging from gettext import gettext as _ from typing import TYPE_CHECKING, Any from blueman.bluemantyping import ObjectPath, BtAddress @@ -31,6 +32,7 @@ class AutoConnect(AppletPlugin): def __init__(self, parent: "BluemanApplet"): super().__init__(parent) + self._last_err: dict[str, str] = {} GLib.timeout_add(60000, self._run) def on_manager_state_changed(self, state: bool) -> None: @@ -65,12 +67,19 @@ def _run(self) -> bool: def reply(dev: Device | None = device, service_name: str = ServiceUUID(uuid).name) -> None: assert isinstance(dev, Device) # https://github.com/python/mypy/issues/2608 + self._last_err.pop(dev["Address"], None) Notification(_("Connected"), _("Automatically connected to %(service)s on %(device)s") % {"service": service_name, "device": dev.display_name}, icon_name=dev["Icon"]).show() - def err(_reason: Exception | str) -> None: - pass + def err(reason: Exception | str, dev: Device | None = device) -> None: + assert isinstance(dev, Device) + reason_str = str(reason) + address = dev["Address"] + if self._last_err.get(address) == reason_str: + return + self._last_err[address] = reason_str + logging.warning(f"AutoConnect failed for {dev.display_name}: {reason_str}") self.parent.Plugins.DBusService.connect_service(device.get_object_path(), uuid, reply, err)