mirror of
https://codeberg.org/icewind/lightflash.git
synced 2026-06-03 10:04:07 +02:00
flake update:
This commit is contained in:
parent
4254707d82
commit
2ff729bfa5
6 changed files with 38 additions and 32 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
name = "lightflash"
|
name = "lightflash"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
rust-version = "1.91.1"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
# lightflash
|
# lightflash
|
||||||
|
|
||||||
Flash tasmota controlled lights with a tasmota button.
|
Flash tasmota controlled lights with a tasmota button.
|
||||||
|
|
|
||||||
34
flake.lock
generated
34
flake.lock
generated
|
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"crane": {
|
"crane": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1748970125,
|
"lastModified": 1763938834,
|
||||||
"narHash": "sha256-UDyigbDGv8fvs9aS95yzFfOKkEjx1LO3PL3DsKopohA=",
|
"narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=",
|
||||||
"owner": "ipetkov",
|
"owner": "ipetkov",
|
||||||
"repo": "crane",
|
"repo": "crane",
|
||||||
"rev": "323b5746d89e04b22554b061522dfce9e4c49b18",
|
"rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -22,11 +22,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1750683087,
|
"lastModified": 1770643227,
|
||||||
"narHash": "sha256-CkmobghX9K9soC4DoorFo/vlWXxpf8xuZyoCsOnWzqM=",
|
"narHash": "sha256-Dhl7sU33nociCpvK51Dc6Kr3c3g6e37GiaQ8RsdhaiE=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "flakelight",
|
"repo": "flakelight",
|
||||||
"rev": "aa93e0e1ecdccc70c7a185f60c562effbfe3c8d9",
|
"rev": "06f0fad6089dbc5cff57607c9ed4ee01dea00c90",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -44,11 +44,11 @@
|
||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1750254239,
|
"lastModified": 1764619631,
|
||||||
"narHash": "sha256-RRhboiUiw4o4hPhxTTnUcd2+8yOLdt6hOTDraMPE/rg=",
|
"narHash": "sha256-WojMP5S9qLmOLecEQ+7+yc33Ly1ydoRsODNG6hlLqiQ=",
|
||||||
"ref": "refs/heads/main",
|
"ref": "refs/heads/main",
|
||||||
"rev": "b7201d4a2220de413e6426c405b69839f6130d1c",
|
"rev": "0fae557bf52d8493840aca52d433c473ecc305ef",
|
||||||
"revCount": 53,
|
"revCount": 67,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://codeberg.org/icewind/mill-scale"
|
"url": "https://codeberg.org/icewind/mill-scale"
|
||||||
},
|
},
|
||||||
|
|
@ -59,16 +59,16 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1750622754,
|
"lastModified": 1770617025,
|
||||||
"narHash": "sha256-kMhs+YzV4vPGfuTpD3mwzibWUE6jotw5Al2wczI0Pv8=",
|
"narHash": "sha256-1jZvgZoAagZZB6NwGRv2T2ezPy+X6EFDsJm+YSlsvEs=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "c7ab75210cb8cb16ddd8f290755d9558edde7ee1",
|
"rev": "2db38e08fdadcc0ce3232f7279bab59a15b94482",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"id": "nixpkgs",
|
||||||
"ref": "nixos-25.05",
|
"ref": "nixos-25.11",
|
||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -88,11 +88,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1750214276,
|
"lastModified": 1764557621,
|
||||||
"narHash": "sha256-1kniuhH70q4TAC/xIvjFYH46aHiLrbIlcr6fdrRwO1A=",
|
"narHash": "sha256-kX5PoY8hQZ80+amMQgOO9t8Tc1JZ70gYRnzaVD4AA+o=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "f9b2b2b1327ff6beab4662b8ea41689e0a57b8d4",
|
"rev": "93316876c2229460a5d6f5f052766cc4cef538ce",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "nixpkgs/nixos-25.05";
|
nixpkgs.url = "nixpkgs/nixos-25.11";
|
||||||
flakelight = {
|
flakelight = {
|
||||||
url = "github:nix-community/flakelight";
|
url = "github:nix-community/flakelight";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ impl TryFrom<RawMqttConfig> for MqttConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ConfigError {
|
pub enum ConfigError {
|
||||||
#[error("Failed to read config file {}: {error:#}", path.display())]
|
#[error("Failed to read config file {}: {error:#}", path.display())]
|
||||||
|
|
|
||||||
30
src/main.rs
30
src/main.rs
|
|
@ -67,21 +67,20 @@ async fn main() -> MainResult {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let notification = event_loop.poll().await?;
|
let notification = event_loop.poll().await?;
|
||||||
if let Event::Incoming(Packet::Publish(packet)) = notification {
|
if let Event::Incoming(Packet::Publish(packet)) = notification
|
||||||
if let Some(triggered) = packet
|
&& let Some(triggered) = packet
|
||||||
.topic
|
.topic
|
||||||
.as_str()
|
.as_str()
|
||||||
.strip_prefix("tele/")
|
.strip_prefix("tele/")
|
||||||
.and_then(|topic| topic.strip_suffix("/SENSOR"))
|
.and_then(|topic| topic.strip_suffix("/SENSOR"))
|
||||||
{
|
{
|
||||||
for switch in &switches {
|
for switch in &switches {
|
||||||
if switch.name == triggered {
|
if switch.name == triggered {
|
||||||
let payload: SwitchPayload = serde_json::from_slice(&packet.payload)?;
|
let payload: SwitchPayload = serde_json::from_slice(&packet.payload)?;
|
||||||
if payload.doorbell.starts_with("ON") {
|
if payload.doorbell.starts_with("ON") {
|
||||||
spawn(flash(mqtt_client.clone(), switch.clone()));
|
spawn(flash(mqtt_client.clone(), switch.clone()));
|
||||||
} else if payload.doorbell.starts_with("OFF") {
|
} else if payload.doorbell.starts_with("OFF") {
|
||||||
switch.active.store(false, Ordering::SeqCst);
|
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> {
|
async fn toggle_light(mqtt_client: &AsyncClient, light: &str) -> Result<(), ClientError> {
|
||||||
debug!(light, "toggling light");
|
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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue