diff --git a/Cargo.toml b/Cargo.toml index cfdfa47..297f6c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "lightflash" version = "0.1.0" edition = "2024" +rust-version = "1.91.1" [dependencies] serde = { version = "1.0.228", features = ["derive"] } diff --git a/README.md b/README.md index facf76f..bb0352d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # lightflash -Flash tasmota controlled lights with a tasmota button. \ No newline at end of file +Flash tasmota controlled lights with a tasmota button. diff --git a/flake.lock b/flake.lock index b86f2c8..a037cd8 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "crane": { "locked": { - "lastModified": 1748970125, - "narHash": "sha256-UDyigbDGv8fvs9aS95yzFfOKkEjx1LO3PL3DsKopohA=", + "lastModified": 1763938834, + "narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=", "owner": "ipetkov", "repo": "crane", - "rev": "323b5746d89e04b22554b061522dfce9e4c49b18", + "rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2", "type": "github" }, "original": { @@ -22,11 +22,11 @@ ] }, "locked": { - "lastModified": 1750683087, - "narHash": "sha256-CkmobghX9K9soC4DoorFo/vlWXxpf8xuZyoCsOnWzqM=", + "lastModified": 1770643227, + "narHash": "sha256-Dhl7sU33nociCpvK51Dc6Kr3c3g6e37GiaQ8RsdhaiE=", "owner": "nix-community", "repo": "flakelight", - "rev": "aa93e0e1ecdccc70c7a185f60c562effbfe3c8d9", + "rev": "06f0fad6089dbc5cff57607c9ed4ee01dea00c90", "type": "github" }, "original": { @@ -44,11 +44,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1750254239, - "narHash": "sha256-RRhboiUiw4o4hPhxTTnUcd2+8yOLdt6hOTDraMPE/rg=", + "lastModified": 1764619631, + "narHash": "sha256-WojMP5S9qLmOLecEQ+7+yc33Ly1ydoRsODNG6hlLqiQ=", "ref": "refs/heads/main", - "rev": "b7201d4a2220de413e6426c405b69839f6130d1c", - "revCount": 53, + "rev": "0fae557bf52d8493840aca52d433c473ecc305ef", + "revCount": 67, "type": "git", "url": "https://codeberg.org/icewind/mill-scale" }, @@ -59,16 +59,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1750622754, - "narHash": "sha256-kMhs+YzV4vPGfuTpD3mwzibWUE6jotw5Al2wczI0Pv8=", + "lastModified": 1770617025, + "narHash": "sha256-1jZvgZoAagZZB6NwGRv2T2ezPy+X6EFDsJm+YSlsvEs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c7ab75210cb8cb16ddd8f290755d9558edde7ee1", + "rev": "2db38e08fdadcc0ce3232f7279bab59a15b94482", "type": "github" }, "original": { "id": "nixpkgs", - "ref": "nixos-25.05", + "ref": "nixos-25.11", "type": "indirect" } }, @@ -88,11 +88,11 @@ ] }, "locked": { - "lastModified": 1750214276, - "narHash": "sha256-1kniuhH70q4TAC/xIvjFYH46aHiLrbIlcr6fdrRwO1A=", + "lastModified": 1764557621, + "narHash": "sha256-kX5PoY8hQZ80+amMQgOO9t8Tc1JZ70gYRnzaVD4AA+o=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "f9b2b2b1327ff6beab4662b8ea41689e0a57b8d4", + "rev": "93316876c2229460a5d6f5f052766cc4cef538ce", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 6202e93..2adf2d0 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - nixpkgs.url = "nixpkgs/nixos-25.05"; + nixpkgs.url = "nixpkgs/nixos-25.11"; flakelight = { url = "github:nix-community/flakelight"; inputs.nixpkgs.follows = "nixpkgs"; diff --git a/src/config.rs b/src/config.rs index 8ed1dac..1efb396 100644 --- a/src/config.rs +++ b/src/config.rs @@ -75,7 +75,6 @@ impl TryFrom for MqttConfig { } } - #[derive(Debug, Error)] pub enum ConfigError { #[error("Failed to read config file {}: {error:#}", path.display())] diff --git a/src/main.rs b/src/main.rs index 2cca111..7372fd9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, switch: Arc) { 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 }