Moved presence debug mqtt message to lua
This commit is contained in:
@@ -3,11 +3,9 @@ use std::convert::Infallible;
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use automation_lib::config::MqttDeviceConfig;
|
use automation_lib::config::MqttDeviceConfig;
|
||||||
use automation_lib::device::{Device, LuaDeviceCreate};
|
use automation_lib::device::{Device, LuaDeviceCreate};
|
||||||
use automation_lib::event::OnPresence;
|
|
||||||
use automation_lib::messages::PresenceMessage;
|
|
||||||
use automation_lib::mqtt::WrappedAsyncClient;
|
use automation_lib::mqtt::WrappedAsyncClient;
|
||||||
use automation_macro::{LuaDevice, LuaDeviceConfig};
|
use automation_macro::{LuaDevice, LuaDeviceConfig};
|
||||||
use tracing::{trace, warn};
|
use tracing::trace;
|
||||||
|
|
||||||
#[derive(Debug, LuaDeviceConfig, Clone)]
|
#[derive(Debug, LuaDeviceConfig, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
@@ -39,27 +37,3 @@ impl Device for DebugBridge {
|
|||||||
self.config.identifier.clone()
|
self.config.identifier.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl OnPresence for DebugBridge {
|
|
||||||
async fn on_presence(&self, presence: bool) {
|
|
||||||
let message = PresenceMessage::new(presence);
|
|
||||||
let topic = format!("{}/presence", self.config.mqtt.topic);
|
|
||||||
self.config
|
|
||||||
.client
|
|
||||||
.publish(
|
|
||||||
topic,
|
|
||||||
rumqttc::QoS::AtLeastOnce,
|
|
||||||
true,
|
|
||||||
serde_json::to_string(&message).expect("Serialization should not fail"),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!(
|
|
||||||
"Failed to update presence on {}/presence: {err}",
|
|
||||||
self.config.mqtt.topic
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -70,6 +70,12 @@ on_presence:add(function(presence)
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
on_presence:add(function(presence)
|
||||||
|
mqtt_client:send_message(mqtt_automation("debug") .. "/presence", {
|
||||||
|
state = presence,
|
||||||
|
updated = automation.util.get_epoch(),
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
local on_light = {
|
local on_light = {
|
||||||
add = function(self, f)
|
add = function(self, f)
|
||||||
|
|||||||
Reference in New Issue
Block a user