Block repeated on while auto-off is active

This commit is contained in:
2026-08-03 01:37:14 +02:00
parent 4ea737024b
commit 6b2bc3853a
8 changed files with 204 additions and 6 deletions
+30
View File
@@ -7,6 +7,9 @@ class DummyAction:
def __init__(self, action_id, camera=None, kind="hikvision_colorvu", name_key=None):
self.id = action_id
self.kind = kind
self.platform = "switch"
self.auto_off_at = None
self.run_called = False
self.cfg = {}
if name_key:
self.cfg["name_key"] = name_key
@@ -16,6 +19,10 @@ class DummyAction:
"camera": camera,
}
def run(self, command, bridge=None):
self.run_called = True
return {"ok": True, "command": command}
class RefreshSummaryTest(unittest.TestCase):
def test_camera_keys_ignore_global_actions(self):
@@ -28,6 +35,18 @@ class RefreshSummaryTest(unittest.TestCase):
self.assertEqual(keys, {("http://frigate.example.test:5000", "one")})
def test_camera_display_name_uses_friendly_name(self):
self.assertEqual(
CameraControlBridge.camera_display_name("camera_key", {"friendly_name": "Camera Friendly"}),
"Camera Friendly",
)
def test_camera_display_name_falls_back_to_config_name(self):
self.assertEqual(
CameraControlBridge.camera_display_name("camera_key", {}),
"camera_key",
)
def test_refresh_message_reports_camera_changes_first(self):
message = CameraControlBridge.refresh_message(
"en",
@@ -64,6 +83,17 @@ class RefreshSummaryTest(unittest.TestCase):
self.assertFalse(CameraControlBridge.should_refresh_snapshot_after_command(siren, "on"))
self.assertFalse(CameraControlBridge.should_refresh_snapshot_after_command(white, "press"))
def test_execute_action_rejects_second_on_while_timer_runs(self):
action = DummyAction("white", "one", name_key="action.manual_white")
action.auto_off_at = 1234567890
bridge = object.__new__(CameraControlBridge)
bridge.action_by_id = lambda action_id: action
with self.assertRaisesRegex(RuntimeError, "already active"):
CameraControlBridge.execute_action(bridge, "white", "on", publish=False)
self.assertFalse(action.run_called)
if __name__ == "__main__":
unittest.main()