mirror of
https://codeberg.org/icewind/taspromto.git
synced 2026-06-03 08:34:21 +02:00
new mqtt topic
This commit is contained in:
parent
f51fe2c2ab
commit
f0e28ed95c
3 changed files with 7 additions and 9 deletions
|
|
@ -7,13 +7,12 @@ use std::time::Instant;
|
|||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
|
||||
pub struct Device {
|
||||
pub topic: String,
|
||||
pub hostname: String,
|
||||
}
|
||||
|
||||
impl Device {
|
||||
pub fn get_topic(&self, prefix: &str, command: &str) -> String {
|
||||
format!("{}/{}/{}/{}", prefix, self.topic, self.hostname, command)
|
||||
format!("{}/{}/{}", prefix, self.hostname, command)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ pub async fn mqtt_stream(
|
|||
mqtt_options: MqttOptions,
|
||||
) -> Result<(AsyncClient, impl Stream<Item = Result<Publish>>)> {
|
||||
let (client, event_loop) = AsyncClient::new(mqtt_options, 10);
|
||||
client.subscribe("tele/+/+/LWT", QoS::AtMostOnce).await?;
|
||||
client.subscribe("stat/+/+/POWER", QoS::AtMostOnce).await?;
|
||||
client.subscribe("tele/+/+/SENSOR", QoS::AtMostOnce).await?;
|
||||
client.subscribe("stat/+/+/RESULT", QoS::AtMostOnce).await?;
|
||||
client.subscribe("tele/+/LWT", QoS::AtMostOnce).await?;
|
||||
client.subscribe("stat/+/POWER", QoS::AtMostOnce).await?;
|
||||
client.subscribe("tele/+/SENSOR", QoS::AtMostOnce).await?;
|
||||
client.subscribe("stat/+/RESULT", QoS::AtMostOnce).await?;
|
||||
|
||||
let stream = event_loop_to_stream(event_loop).filter_map(|event| match event {
|
||||
Ok(Event::Incoming(Packet::Publish(message))) => Some(Ok(message)),
|
||||
|
|
|
|||
|
|
@ -13,11 +13,10 @@ pub enum Topic {
|
|||
impl From<&str> for Topic {
|
||||
fn from(raw: &str) -> Self {
|
||||
let mut parts = raw.split('/');
|
||||
if let (Some(prefix), Some(topic), Some(hostname), Some(cmd)) =
|
||||
(parts.next(), parts.next(), parts.next(), parts.next())
|
||||
if let (Some(prefix), Some(hostname), Some(cmd)) =
|
||||
(parts.next(), parts.next(), parts.next())
|
||||
{
|
||||
let device = Device {
|
||||
topic: topic.to_string(),
|
||||
hostname: hostname.to_string(),
|
||||
};
|
||||
match (prefix, cmd) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue