blob: 28092556795a2af92b43f6e82e4304bb26d0c99f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
mod common;
use common::AsyncTcp;
use embassy_executor::{Executor, Spawner};
use embassy_time::Timer;
use static_cell::StaticCell;
static RESOURCES: StaticCell<embassy_ha::DeviceResources> = StaticCell::new();
#[embassy_executor::task]
async fn main_task(spawner: Spawner) {
let mut stream = AsyncTcp::connect(std::env!("MQTT_ADDRESS"));
let mut device = embassy_ha::Device::new(
RESOURCES.init(Default::default()),
embassy_ha::DeviceConfig {
device_id: "example-device-id",
device_name: "Example Device Name",
manufacturer: "Example Device Manufacturer",
model: "Example Device Model",
},
);
let sensor = device.create_binary_sensor(
"binary-sensor-id",
"Binary Sensor",
embassy_ha::constants::HA_DEVICE_CLASS_BINARY_SENSOR_SMOKE,
);
spawner.must_spawn(binary_sensor_class(sensor));
device.run(&mut stream).await;
}
#[embassy_executor::task]
async fn binary_sensor_class(mut switch: embassy_ha::BinarySensor<'static>) {
loop {
let state = switch.toggle();
println!("state = {}", state);
Timer::after_secs(2).await;
}
}
example_main!();
|