From 7f168a6e5d37f33096a01095615482e66df737ee Mon Sep 17 00:00:00 2001 From: Cyrill Raccaud Date: Sun, 8 Sep 2024 14:56:18 +0200 Subject: [PATCH] fix the container filter not only at startup but also at runtime --- docker2mqtt/docker2mqtt.py | 42 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/docker2mqtt/docker2mqtt.py b/docker2mqtt/docker2mqtt.py index c28e956..1bea216 100755 --- a/docker2mqtt/docker2mqtt.py +++ b/docker2mqtt/docker2mqtt.py @@ -888,14 +888,15 @@ def _handle_events_queue(self) -> None: ) del self.pending_destroy_operations[container] - self._register_container( - { - "name": container, - "image": event["from"], - "status": "created", - "state": "off", - } - ) + if self._filter_container(container): + self._register_container( + { + "name": container, + "image": event["from"], + "status": "created", + "state": "off", + } + ) elif event["status"] == "destroy": # Add this container to pending_destroy_operations. @@ -924,16 +925,21 @@ def _handle_events_queue(self) -> None: "Container %s renamed to %s.", old_name, container ) self._unregister_container(old_name) - self._register_container( - { - "name": container, - "image": self.known_event_containers[old_name]["image"], - "status": self.known_event_containers[old_name][ - "status" - ], - "state": self.known_event_containers[old_name]["state"], - } - ) + if self._filter_container(container): + self._register_container( + { + "name": container, + "image": self.known_event_containers[old_name][ + "image" + ], + "status": self.known_event_containers[old_name][ + "status" + ], + "state": self.known_event_containers[old_name][ + "state" + ], + } + ) del self.known_event_containers[old_name] elif event["status"] == "start":