don't drop batched camera add/remove config updates

TrackedObjectProcessor drained all pending camera config updates at once but handled them in a mutually exclusive if/elif on enabled/add/remove, so only one topic was processed per drain. When an add arrived in the same batch as an enabled update, the add was skipped and the new camera never got a camera state. Adding a camera reliably produced that batch: config_set now re-applies runtime overrides, which republishes an enabled update for every previously toggled camera immediately before the add, in the same request. The dashboard and camera capture still saw the camera (the maintainer does not subscribe to enabled, so it got a clean add-only batch), but object_processing did not, and disabling the camera then crashed with a KeyError on the unguarded camera_states lookup.

Handle add and remove independently instead of as exclusive branches so a batched add is no longer dropped, and guard the remove lookup so a missing state is skipped rather than raising. Drop the enabled branch entirely: it only ever set prev_enabled when it was None, but prev_enabled is seeded to a bool at camera state creation and is never None (mypy flags the body as unreachable), and the actual enable/disable transition is already driven by the disabled-state loop from config.enabled.
This commit is contained in:
Josh Hawkins
2026-07-16 09:37:15 -05:00
parent fa2452e0c8
commit 4c3e0fdea9
+14 -15
View File
@@ -684,22 +684,21 @@ class TrackedObjectProcessor(threading.Thread):
# check for config updates # check for config updates
updated_topics = self.camera_config_subscriber.check_for_updates() updated_topics = self.camera_config_subscriber.check_for_updates()
if "enabled" in updated_topics: # a single drain can carry several topics at once, so add and
for camera in updated_topics["enabled"]: # remove are handled independently rather than as exclusive branches
if self.camera_states[camera].prev_enabled is None: for camera in updated_topics.get("add", []):
self.camera_states[camera].prev_enabled = self.config.cameras[ self.config.cameras[camera] = (
camera self.camera_config_subscriber.camera_configs[camera]
].enabled )
elif "add" in updated_topics: self.create_camera_state(camera)
for camera in updated_topics["add"]:
self.config.cameras[camera] = ( if "remove" in updated_topics:
self.camera_config_subscriber.camera_configs[camera]
)
self.create_camera_state(camera)
elif "remove" in updated_topics:
for camera in updated_topics["remove"]: for camera in updated_topics["remove"]:
removed_camera_state = self.camera_states[camera] camera_state = self.camera_states.get(camera)
removed_camera_state.shutdown() if camera_state is None:
continue
camera_state.shutdown()
self.camera_states.pop(camera) self.camera_states.pop(camera)
self.camera_activity.pop(camera, None) self.camera_activity.pop(camera, None)
self.last_motion_detected.pop(camera, None) self.last_motion_detected.pop(camera, None)