fix: sync {camera}/motion topic from camera_activity updates

applyCameraActivity expanded camera_activity into many per-camera
topics ({camera}/enabled/state, {camera}/detect/state, etc.) but
never synced the motion field into {camera}/motion.

This caused a critical bug: a stale retained MQTT "OFF" value in
{camera}/motion would permanently override the live motion state
from camera_activity.motion. In useCameraActivity the detectingMotion
check (truthy string "OFF") took priority over camera_activity.motion,
so activeMotion was always false even with real motion present.

Now applyCameraActivity writes state.motion → {camera}/motion ("ON"/
"OFF"), keeping it in sync with the authoritative camera_activity data.

https://claude.ai/code/session_019B4dJXtcxvHn97ZaqHUB62
This commit is contained in:
Claude 2026-03-18 05:21:29 +00:00
parent 621f484b92
commit 703ffcf82e
No known key found for this signature in database

View File

@ -149,6 +149,12 @@ function applyCameraActivity(payload: string) {
for (const [name, state] of Object.entries(activity)) {
applyTopicUpdate(`camera_activity/${name}`, state);
// Sync motion state so {camera}/motion topic stays up-to-date with
// camera_activity and doesn't remain stale from a retained MQTT value.
if (state.motion !== undefined) {
applyTopicUpdate(`${name}/motion`, state.motion ? "ON" : "OFF");
}
const cameraConfig = state?.config;
if (!cameraConfig) continue;