mqtt: Add Home Assistant config for refresh button
dustin/mqttmarionette/pipeline/head This commit looks good
Details
dustin/mqttmarionette/pipeline/head This commit looks good
Details
The MQTT Marionette will now publish Home Assistant discovery configuration for a button entity to initiate a page reload. Each managed screen has its own button, so individual windows are refreshed independently.master
parent
17d4f2a143
commit
99baf9b8c0
22
src/mqtt.rs
22
src/mqtt.rs
|
@ -285,6 +285,27 @@ impl<'a> MqttPublisher<'a> {
|
|||
trace!("Publishing message: {:?}", msg);
|
||||
self.client.lock().await.publish(msg).await?;
|
||||
|
||||
let command_topic = Some(format!("{}/{}/refresh", prefix, screen));
|
||||
let name = format!("Refresh {}", screen);
|
||||
let unique_id = format!("button.{}_refresh", key);
|
||||
let object_id = unique_id.clone();
|
||||
let config = HassConfig {
|
||||
command_topic,
|
||||
name,
|
||||
unique_id,
|
||||
object_id,
|
||||
state_topic: "".into(),
|
||||
icon: "mdi:refresh".into(),
|
||||
..config
|
||||
};
|
||||
let msg = Message::new_retained(
|
||||
format!("homeassistant/button/{}_refresh/config", key),
|
||||
serde_json::to_string(&config).unwrap(),
|
||||
0,
|
||||
);
|
||||
trace!("Publishing message: {:?}", msg);
|
||||
self.client.lock().await.publish(msg).await?;
|
||||
|
||||
let unique_id = format!("light.{}", key);
|
||||
let object_id = unique_id.clone();
|
||||
let command_topic = Some(format!("{}/power", prefix));
|
||||
|
@ -296,6 +317,7 @@ impl<'a> MqttPublisher<'a> {
|
|||
name,
|
||||
unique_id,
|
||||
object_id,
|
||||
icon: "mdi:monitor".into(),
|
||||
..config
|
||||
};
|
||||
let msg = Message::new_retained(
|
||||
|
|
Loading…
Reference in New Issue