70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
import unittest
|
|
|
|
from frigate_camera_control_bridge.app import CameraControlBridge
|
|
|
|
|
|
class DummyAction:
|
|
def __init__(self, action_id, camera=None, kind="hikvision_colorvu", name_key=None):
|
|
self.id = action_id
|
|
self.kind = kind
|
|
self.cfg = {}
|
|
if name_key:
|
|
self.cfg["name_key"] = name_key
|
|
if camera:
|
|
self.cfg["snapshot"] = {
|
|
"frigate_url": "http://frigate.example.test:5000",
|
|
"camera": camera,
|
|
}
|
|
|
|
|
|
class RefreshSummaryTest(unittest.TestCase):
|
|
def test_camera_keys_ignore_global_actions(self):
|
|
keys = CameraControlBridge.camera_keys_from_actions(
|
|
[
|
|
DummyAction("one_light", "one"),
|
|
DummyAction("all_off", kind="all_off"),
|
|
]
|
|
)
|
|
|
|
self.assertEqual(keys, {("http://frigate.example.test:5000", "one")})
|
|
|
|
def test_refresh_message_reports_camera_changes_first(self):
|
|
message = CameraControlBridge.refresh_message(
|
|
"en",
|
|
{
|
|
"added_cameras": 1,
|
|
"removed_cameras": 0,
|
|
"added_actions": 2,
|
|
"removed_actions": 0,
|
|
},
|
|
)
|
|
|
|
self.assertEqual(message, "Cameras updated: +1, -0.")
|
|
|
|
def test_refresh_message_reports_no_changes(self):
|
|
message = CameraControlBridge.refresh_message(
|
|
"en",
|
|
{
|
|
"added_cameras": 0,
|
|
"removed_cameras": 0,
|
|
"added_actions": 0,
|
|
"removed_actions": 0,
|
|
},
|
|
)
|
|
|
|
self.assertEqual(message, "No camera changes found.")
|
|
|
|
def test_light_actions_refresh_snapshot_after_on_off(self):
|
|
white = DummyAction("white", "one", name_key="action.manual_white")
|
|
red_blue = DummyAction("red_blue", "one", name_key="action.red_blue")
|
|
siren = DummyAction("siren", "one", name_key="action.siren")
|
|
|
|
self.assertTrue(CameraControlBridge.should_refresh_snapshot_after_command(white, "on"))
|
|
self.assertTrue(CameraControlBridge.should_refresh_snapshot_after_command(red_blue, "off"))
|
|
self.assertFalse(CameraControlBridge.should_refresh_snapshot_after_command(siren, "on"))
|
|
self.assertFalse(CameraControlBridge.should_refresh_snapshot_after_command(white, "press"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|