mirror of
https://codeberg.org/icewind/tasmota-mqtt-client.git
synced 2026-06-03 10:14:10 +02:00
38 lines
1,001 B
Rust
38 lines
1,001 B
Rust
use clap::Parser;
|
|
use std::pin::pin;
|
|
use tasmota_mqtt_client::{DeviceUpdate, Result, TasmotaClient};
|
|
use tokio::join;
|
|
use tokio_stream::StreamExt;
|
|
|
|
#[derive(Debug, Parser)]
|
|
struct Args {
|
|
hostname: String,
|
|
port: u16,
|
|
username: String,
|
|
password: String,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
let args = Args::parse();
|
|
let client = TasmotaClient::connect(
|
|
&args.hostname,
|
|
args.port,
|
|
Some((&args.username, &args.password)),
|
|
)
|
|
.await?;
|
|
|
|
let mut discovery = pin!(client.devices());
|
|
while let Some(update) = discovery.next().await {
|
|
match update {
|
|
DeviceUpdate::Added(device) => {
|
|
let (ip, name) = join!(client.device_ip(&device), client.device_name(&device));
|
|
println!("discovered {}({device}) with ip {}", name?, ip?);
|
|
}
|
|
DeviceUpdate::Removed(device) => {
|
|
println!("{device} has gone offline");
|
|
}
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|