Add Home Assistant discovery icons

This commit is contained in:
2026-08-03 01:50:42 +02:00
parent 15ec93f82e
commit 91b0fedbe8
3 changed files with 80 additions and 0 deletions
+23
View File
@@ -19,6 +19,12 @@ VERSION = "1.0"
DEFAULT_CONFIG = "/etc/frigate-camera-control-bridge.json"
LOG = logging.getLogger("frigate-camera-control-bridge")
STREAM_URL_RE = re.compile(r"(?:rtsp|rtsps|http|https)://[^\s'\"<>]+", re.IGNORECASE)
HOME_ASSISTANT_ACTION_ICONS = {
"action.siren": "mdi:bullhorn",
"action.red_blue": "mdi:alarm-light",
"action.manual_white": "mdi:lightbulb-on",
"action.all_off": "mdi:power",
}
from .i18n import DEFAULT_LANGUAGE, available_languages, normalize_language, text_for
from .ui import read_static_file, render_page
@@ -1401,6 +1407,9 @@ class CameraControlBridge:
},
"qos": 0,
}
icon = self.home_assistant_icon(action)
if icon:
payload["icon"] = icon
if action.platform == "switch":
payload.update(
{
@@ -1424,6 +1433,20 @@ class CameraControlBridge:
)
return payload
@staticmethod
def home_assistant_icon(action):
# Home Assistant MQTT discovery accepts MDI icons on switches and
# buttons. Keep icons semantic and overrideable by static action config.
configured = action.cfg.get("icon")
if configured:
return configured
name_key = action.cfg.get("name_key")
if name_key in HOME_ASSISTANT_ACTION_ICONS:
return HOME_ASSISTANT_ACTION_ICONS[name_key]
if action.kind == "all_off":
return HOME_ASSISTANT_ACTION_ICONS["action.all_off"]
return None
def execute_action(self, action_id, command, publish=True):
action = self.action_by_id(action_id)
if action is None: