mirror of
https://codeberg.org/icewind/tasmota-mqtt-client.git
synced 2026-06-03 10:14:10 +02:00
discovery wip
This commit is contained in:
parent
70b2874d3b
commit
56dc433854
5 changed files with 128 additions and 4 deletions
|
|
@ -19,7 +19,8 @@ async fn main() -> Result<()> {
|
|||
&args.hostname,
|
||||
args.port,
|
||||
Some((&args.username, &args.password)),
|
||||
)?;
|
||||
)
|
||||
.await?;
|
||||
let file = client
|
||||
.download_config(&args.device, &args.device_password)
|
||||
.await?;
|
||||
|
|
|
|||
37
examples/discovery.rs
Normal file
37
examples/discovery.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use clap::Parser;
|
||||
use std::pin::pin;
|
||||
use tasmota_mqtt_client::DeviceUpdate;
|
||||
pub use tasmota_mqtt_client::{Result, TasmotaClient};
|
||||
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) => {
|
||||
println!("discovered {device}");
|
||||
}
|
||||
DeviceUpdate::Removed(device) => {
|
||||
println!("{device} has gone offline");
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue