From f6a8f9de78b89daee8a7ccbd1702d4b61a46707e Mon Sep 17 00:00:00 2001 From: Vladimir Burdukov Date: Mon, 1 Apr 2024 17:32:52 +0300 Subject: [PATCH] Fixed elisheba keys format --- bin/elisheba/src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/elisheba/src/main.rs b/bin/elisheba/src/main.rs index c09d7cc..d9391bf 100644 --- a/bin/elisheba/src/main.rs +++ b/bin/elisheba/src/main.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::time::Duration; +use crypto::Token; use elisheba::{handle_action_request, handle_state_request, ErasedError, Storage}; use sonoff::{Client, Error}; use transport::state::StateUpdate; @@ -21,11 +22,7 @@ async fn main() -> Result<(), ErasedError> { info!("elisheba version {VERSION}"); let keys = std::env::var("KEYS").expect("set ENV variable KEYS"); - let keys: HashMap = serde_json::from_str(&keys)?; - let keys = keys - .into_iter() - .map(|(k, v)| (k, md5::compute(v).0)) - .collect(); + let keys = parse_keys_string(keys); let client = Client::connect(keys).await?; info!("connected sonoff"); @@ -176,3 +173,11 @@ async fn subscribe_state(mqtt: MqClient, mut sonoff: Client) -> Result<(), Erase } } } + +fn parse_keys_string(string: String) -> HashMap> { + string + .split(",") + .filter_map(|s| s.split_once("=")) + .map(|(id, key)| (id.to_string(), md5::compute(key).0)) + .collect() +}