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()
+22
View File
@@ -37,6 +37,9 @@ class UiRenderTest(unittest.TestCase):
self.assertIn('data-requires-ack="true"', html)
self.assertIn("Example camera", html)
self.assertIn("v=42", html)
self.assertIn('class="snapshot-refresh"', html)
self.assertIn('title="Refresh snapshot"', html)
self.assertIn('disabled title="Already active until automatic turn-off"', html)
def test_controls_from_same_camera_share_one_card(self):
actions = [
@@ -92,6 +95,25 @@ class UiRenderTest(unittest.TestCase):
"https://frigate.example.test/#example",
)
def test_on_button_is_available_when_no_auto_off_timer_runs(self):
action = DummyAction()
action.auto_off_at = None
html = render_page([action], "en")
self.assertIn('class="cmd cmd-on"', html)
self.assertNotIn('Already active until automatic turn-off', html)
def test_camera_card_uses_friendly_display_name(self):
action = DummyAction()
action.cfg["camera_name"] = "camera_key"
action.cfg["camera_display_name"] = "Camera Friendly"
html = render_page([action], "en")
self.assertIn("<h2>Camera Friendly</h2>", html)
self.assertNotIn("<h2>camera_key</h2>", html)
if __name__ == "__main__":
unittest.main()