Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed elisheba keys format #111

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions bin/elisheba/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, String> = 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");
Expand Down Expand Up @@ -176,3 +173,11 @@ async fn subscribe_state(mqtt: MqClient, mut sonoff: Client) -> Result<(), Erase
}
}
}

fn parse_keys_string(string: String) -> HashMap<String, Token<16>> {
string
.split(",")
.filter_map(|s| s.split_once("="))
.map(|(id, key)| (id.to_string(), md5::compute(key).0))
.collect()
}