Add Home Assistant discovery icons
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import unittest
|
||||
|
||||
from frigate_camera_control_bridge.app import Action, CameraControlBridge
|
||||
|
||||
|
||||
class HomeAssistantDiscoveryTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.bridge = object.__new__(CameraControlBridge)
|
||||
self.bridge.config = {"mqtt": {"base_topic": "test/camera_control"}}
|
||||
self.bridge.default_language = "en"
|
||||
|
||||
def payload_for(self, cfg):
|
||||
base_cfg = {
|
||||
"id": "example_action",
|
||||
"name": "Example action",
|
||||
"platform": "switch",
|
||||
"kind": "dahua_coaxial_io",
|
||||
"device": {"identifiers": ["camera_example"], "name": "Example camera"},
|
||||
}
|
||||
base_cfg.update(cfg)
|
||||
action = Action(base_cfg, http_client=None)
|
||||
return self.bridge.discovery_payload(action, "test/camera_control/status")
|
||||
|
||||
def test_switch_discovery_includes_semantic_icons(self):
|
||||
cases = {
|
||||
"action.siren": "mdi:bullhorn",
|
||||
"action.red_blue": "mdi:alarm-light",
|
||||
"action.manual_white": "mdi:lightbulb-on",
|
||||
}
|
||||
|
||||
for name_key, icon in cases.items():
|
||||
with self.subTest(name_key=name_key):
|
||||
payload = self.payload_for({"name_key": name_key})
|
||||
|
||||
self.assertEqual(payload["icon"], icon)
|
||||
|
||||
def test_all_off_button_discovery_includes_power_icon(self):
|
||||
payload = self.payload_for(
|
||||
{
|
||||
"platform": "button",
|
||||
"kind": "all_off",
|
||||
"name_key": "action.all_off",
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(payload["icon"], "mdi:power")
|
||||
|
||||
def test_configured_icon_overrides_default_icon(self):
|
||||
payload = self.payload_for({"name_key": "action.siren", "icon": "mdi:test-tube"})
|
||||
|
||||
self.assertEqual(payload["icon"], "mdi:test-tube")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user