flake update:

This commit is contained in:
Robin Appelman 2026-02-10 19:18:00 +01:00
commit 2ff729bfa5
6 changed files with 38 additions and 32 deletions

View file

@ -75,7 +75,6 @@ impl TryFrom<RawMqttConfig> for MqttConfig {
}
}
#[derive(Debug, Error)]
pub enum ConfigError {
#[error("Failed to read config file {}: {error:#}", path.display())]

View file

@ -67,21 +67,20 @@ async fn main() -> MainResult {
loop {
let notification = event_loop.poll().await?;
if let Event::Incoming(Packet::Publish(packet)) = notification {
if let Some(triggered) = packet
if let Event::Incoming(Packet::Publish(packet)) = notification
&& let Some(triggered) = packet
.topic
.as_str()
.strip_prefix("tele/")
.and_then(|topic| topic.strip_suffix("/SENSOR"))
{
for switch in &switches {
if switch.name == triggered {
let payload: SwitchPayload = serde_json::from_slice(&packet.payload)?;
if payload.doorbell.starts_with("ON") {
spawn(flash(mqtt_client.clone(), switch.clone()));
} else if payload.doorbell.starts_with("OFF") {
switch.active.store(false, Ordering::SeqCst);
}
{
for switch in &switches {
if switch.name == triggered {
let payload: SwitchPayload = serde_json::from_slice(&packet.payload)?;
if payload.doorbell.starts_with("ON") {
spawn(flash(mqtt_client.clone(), switch.clone()));
} else if payload.doorbell.starts_with("OFF") {
switch.active.store(false, Ordering::SeqCst);
}
}
}
@ -130,5 +129,12 @@ async fn flash(mqtt_client: Arc<AsyncClient>, switch: Arc<Switch>) {
async fn toggle_light(mqtt_client: &AsyncClient, light: &str) -> Result<(), ClientError> {
debug!(light, "toggling light");
mqtt_client.publish(format!("cmnd/{light}/POWER"), QoS::ExactlyOnce, false, "toggle").await
mqtt_client
.publish(
format!("cmnd/{light}/POWER"),
QoS::ExactlyOnce,
false,
"toggle",
)
.await
}