|
8 | 8 | import logging
|
9 | 9 | from typing import Any, Dict
|
10 | 10 |
|
11 |
| -from .constants import INPUT_TOPIC, OUTPUT_TOPIC, SENSOR_TOPIC, SET_SUFFIX |
| 11 | +from .constants import INPUT_TOPIC, OUTPUT_TOPIC, SENSOR_TOPIC, STREAM_TOPIC, SET_SUFFIX, SEND_SUFFIX |
12 | 12 | from .mqtt import MQTTClientOptions, MQTTMessageSend
|
13 | 13 | from .types import ConfigType
|
14 | 14 | from . import VERSION
|
@@ -148,3 +148,35 @@ def hass_announce_sensor_input(
|
148 | 148 | json.dumps(sensor_config).encode("utf8"),
|
149 | 149 | retain=True,
|
150 | 150 | )
|
| 151 | + |
| 152 | +def hass_announce_stream( |
| 153 | + in_conf: ConfigType, mqtt_conf: ConfigType, mqtt_options: MQTTClientOptions |
| 154 | +) -> MQTTMessageSend: |
| 155 | + """ |
| 156 | + Create a message which announces stream as text to Home Assistant. |
| 157 | + """ |
| 158 | + disco_conf: ConfigType = mqtt_conf["ha_discovery"] |
| 159 | + name: str = in_conf["name"] |
| 160 | + disco_prefix: str = disco_conf["prefix"] |
| 161 | + stream_config = get_common_config(in_conf, mqtt_conf, mqtt_options) |
| 162 | + stream_config.update( |
| 163 | + dict( |
| 164 | + unique_id=f"{mqtt_options.client_id}_{in_conf['module']}_input_{name}", |
| 165 | + state_topic="/".join((mqtt_conf["topic_prefix"], STREAM_TOPIC, name)), |
| 166 | + command_topic="/".join((mqtt_conf["topic_prefix"], STREAM_TOPIC, name, SEND_SUFFIX)) |
| 167 | + ) |
| 168 | + ) |
| 169 | + return MQTTMessageSend( |
| 170 | + "/".join( |
| 171 | + ( |
| 172 | + disco_prefix, |
| 173 | + stream_config.pop("component", "text"), |
| 174 | + mqtt_options.client_id, |
| 175 | + name, |
| 176 | + "config", |
| 177 | + ) |
| 178 | + ), |
| 179 | + json.dumps(stream_config).encode("utf8"), |
| 180 | + retain=True, |
| 181 | + ) |
| 182 | + |
0 commit comments