Skip to content

Fix: return list from translate_event_code to dispatch all matching listeners - #561

Merged
rroller merged 1 commit into
rroller:mainfrom
MicheleMercuri:fix/translate-event-code-return-list
Mar 23, 2026
Merged

Fix: return list from translate_event_code to dispatch all matching listeners#561
rroller merged 1 commit into
rroller:mainfrom
MicheleMercuri:fix/translate-event-code-return-list

Conversation

@MicheleMercuri

Copy link
Copy Markdown
Contributor

Summary

Fixes #560 — regression from #557 where CrossLineDetection sensors stopped firing when SmartMotionHuman/SmartMotionVehicle listeners also existed.

Root cause: translate_event_code() returned a single event code string. When both a CrossLine and a SmartMotion listener were registered, the CrossLine event was exclusively translated to SmartMotion — the original CrossLineDetection sensor never fired.

Fix: translate_event_code() now returns a list[str] of event codes, and both callers (on_receive_vto_event, on_receive) iterate over the list to dispatch all matching listeners.

Behavior matrix

User config CrossLine + ObjectType=Human Result
Only CrossLine subscribed [CrossLineDetection] works (unchanged)
Only SmartMotion subscribed [SmartMotionHuman] works (unchanged)
Both subscribed [CrossLineDetection, SmartMotionHuman] both fire (was broken)
Neither subscribed [SmartMotionHuman] fallback works (unchanged)

Changes (3 touch points in __init__.py)

  1. translate_event_code() — returns list[str] instead of str. Builds a list: always includes original CrossLine/CrossRegion if its listener exists, then appends SmartMotion* if that listener also exists.
  2. on_receive_vto_event()codes = ... + for code in codes: loop around the existing handler body.
  3. on_receive()event_names = ... + for event_name in event_names: loop around the existing handler body.

Test plan

  • Verified on 4 Dahua cameras with IVS CrossLineDetection + SmartMotionHuman both enabled — both binary_sensor.*_crosslinedetection and binary_sensor.*_smart_motion_human fire on the same event
  • Verified CrossLineDetection-only setup (no SmartMotion entities) still works
  • Verified SmartMotionHuman-only setup (no CrossLine entities) still works
  • Verified doorbell (BackKeyLight → DoorbellPressed) still works (returns ["DoorbellPressed"])
  • Verified VTO events (AccessControl, DoorStatus Pulse) still work

…teners

Fixes rroller#560. The previous implementation (rroller#557) returned a single event
code, which meant CrossLineDetection was silently dropped when a
SmartMotion* listener also existed. This change makes
translate_event_code() return a list of codes so both the original
CrossLine/CrossRegion sensor AND the SmartMotion* sensor fire on the
same raw event.

Three touch points:
1. translate_event_code() → returns list[str] instead of str
2. on_receive_vto_event() → iterates over the list
3. on_receive() → iterates over the list

Behavior matrix:
| Config                     | CrossLine + Human | Result                              |
|----------------------------|-------------------|-------------------------------------|
| Only CrossLine subscribed  | ✓                 | [CrossLineDetection]                |
| Only SmartMotion subscribed| ✓                 | [SmartMotionHuman]                  |
| Both subscribed            | ✓                 | [CrossLineDetection, SmartMotionHuman] |
| Neither subscribed         | ✓                 | [SmartMotionHuman] (fallback)       |
@rroller
rroller merged commit 81319a2 into rroller:main Mar 23, 2026
3 checks passed
@rroller

rroller commented Mar 23, 2026

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CrossLine not working any more after 0.9.8 Fix

2 participants