From c413a37074eb2b538b0ab6135811fe088980321b Mon Sep 17 00:00:00 2001 From: MicheleMercuri Date: Tue, 17 Mar 2026 18:22:50 +0100 Subject: [PATCH] Fix SmartMotionHuman/Vehicle not triggered when CrossLine/CrossRegion events are subscribed When both CrossLineDetection/CrossRegionDetection and SmartMotionHuman are in the events list, translate_event_code() should prioritize translating to SmartMotionHuman/SmartMotionVehicle when the ObjectType matches and a listener exists for the SmartMotion event. Previously, the `is None` check on the CrossLineDetection listener always failed (returned False) when both events were subscribed, because the listener for CrossLineDetection was registered. This meant CrossLineDetection events with ObjectType=Human were never translated to SmartMotionHuman, leaving those binary_sensors permanently off. The fix adds a priority check: if a SmartMotionHuman or SmartMotionVehicle listener exists, translate to it first. The original fallback (translate when no CrossLine listener exists) is preserved for backward compatibility. --- custom_components/dahua/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/custom_components/dahua/__init__.py b/custom_components/dahua/__init__.py index 2426c19..df73c75 100755 --- a/custom_components/dahua/__init__.py +++ b/custom_components/dahua/__init__.py @@ -594,6 +594,11 @@ def translate_event_code(self, event: dict): if code == "CrossLineDetection" or code == "CrossRegionDetection": data = event.get("data", event.get("Data", {})) is_human = data.get("Object", {}).get("ObjectType", "").lower() == "human" + is_vehicle = data.get("Object", {}).get("ObjectType", "").lower() == "vehicle" + if is_human and self._dahua_event_listeners.get(self.get_event_key("SmartMotionHuman")) is not None: + return "SmartMotionHuman" + if is_vehicle and self._dahua_event_listeners.get(self.get_event_key("SmartMotionVehicle")) is not None: + return "SmartMotionVehicle" if is_human and self._dahua_event_listeners.get(self.get_event_key(code)) is None: return "SmartMotionHuman"