82 lines
2.6 KiB
Python
82 lines
2.6 KiB
Python
import unittest
|
|
|
|
from frigate_camera_control_bridge.app import CameraControlBridge
|
|
|
|
|
|
class DummyAction:
|
|
def __init__(self, action_id="example_camera_white", kind="hikvision_colorvu"):
|
|
self.id = action_id
|
|
self.platform = "switch"
|
|
self.kind = kind
|
|
self.state = "ON"
|
|
self.auto_off_seconds = 600
|
|
self.auto_off_at = 1234567890
|
|
self.snapshot_version = 7
|
|
self.cfg = {
|
|
"id": self.id,
|
|
"name": "Example white light",
|
|
"name_key": "action.manual_white",
|
|
"requires_ack": False,
|
|
"snapshot": {
|
|
"camera": "example",
|
|
"frigate_url": "http://frigate.example.test:5000",
|
|
},
|
|
}
|
|
|
|
def command_list(self):
|
|
return ["on", "off"]
|
|
|
|
def display_name(self, _lang):
|
|
return "Example white light"
|
|
|
|
|
|
class ActionPayloadTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.bridge = object.__new__(CameraControlBridge)
|
|
self.bridge.default_language = "en"
|
|
self.action = DummyAction()
|
|
self.bridge.actions_snapshot = lambda: [self.action]
|
|
|
|
def test_api_action_includes_ui_state_fields(self):
|
|
payload = CameraControlBridge.api_action(self.bridge, self.action, "en")
|
|
|
|
self.assertEqual(payload["id"], "example_camera_white")
|
|
self.assertEqual(payload["state"], "ON")
|
|
self.assertEqual(payload["state_label"], "ON")
|
|
self.assertEqual(payload["snapshot_version"], 7)
|
|
self.assertEqual(payload["auto_off_at"], 1234567890)
|
|
|
|
def test_action_payload_returns_updated_action_for_json_gui(self):
|
|
payload = CameraControlBridge.action_payload(
|
|
self.bridge,
|
|
"en",
|
|
self.action,
|
|
"on",
|
|
{"ok": True, "command": "on"},
|
|
"/?lang=en",
|
|
)
|
|
|
|
self.assertTrue(payload["ok"])
|
|
self.assertEqual(payload["message"], "Command sent.")
|
|
self.assertEqual(payload["redirect_url"], "/?lang=en")
|
|
self.assertEqual(payload["action"]["id"], "example_camera_white")
|
|
|
|
def test_all_off_payload_includes_all_actions_for_gui_refresh(self):
|
|
action = DummyAction("example_all_off", kind="all_off")
|
|
payload = CameraControlBridge.action_payload(
|
|
self.bridge,
|
|
"en",
|
|
action,
|
|
"press",
|
|
{"ok": True, "results": []},
|
|
"/?lang=en",
|
|
)
|
|
|
|
self.assertEqual(payload["action_id"], "example_all_off")
|
|
self.assertEqual(len(payload["actions"]), 1)
|
|
self.assertEqual(payload["actions"][0]["id"], "example_camera_white")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|