From 69abaf98d7f57108e107c23a8936a2e6a892285d Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Thu, 5 Jan 2023 02:09:36 +0100 Subject: [PATCH] Switched to proper Ipv4Addr type --- config/zeus.dev.toml | 6 +++--- src/config.rs | 6 +++--- src/devices/audio_setup.rs | 22 ++++------------------ 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/config/zeus.dev.toml b/config/zeus.dev.toml index 8e3b8d0..01044a1 100644 --- a/config/zeus.dev.toml +++ b/config/zeus.dev.toml @@ -10,7 +10,7 @@ username="Dreaded_X" topic = "automation_dev/presence" [light_sensor] -topic = "zigbee2mqtt/living/light" +topic = "zigbee2mqtt_dev/living/light" min = 23_000 max = 25_000 @@ -37,5 +37,5 @@ mac_address = "30:9c:23:60:9c:13" [devices.audio] type = "AudioSetup" topic = "zigbee2mqtt/living/remote" -mixer = [10, 0, 0, 49] -speakers = [10, 0, 0, 182] +mixer = "10.0.0.49" +speakers = "10.0.0.182" diff --git a/src/config.rs b/src/config.rs index 2dabbe1..76399ff 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,4 @@ -use std::{fs, error::Error, collections::HashMap}; +use std::{fs, error::Error, collections::HashMap, net::Ipv4Addr}; use tracing::{debug, trace}; use rumqttc::AsyncClient; @@ -100,8 +100,8 @@ pub enum Device { AudioSetup { #[serde(flatten)] mqtt: MqttDeviceConfig, - mixer: [u8; 4], - speakers: [u8; 4], + mixer: Ipv4Addr, + speakers: Ipv4Addr, } } diff --git a/src/devices/audio_setup.rs b/src/devices/audio_setup.rs index db12fb2..5ce5c0c 100644 --- a/src/devices/audio_setup.rs +++ b/src/devices/audio_setup.rs @@ -1,5 +1,5 @@ use std::io::{Write, Read}; -use std::net::{TcpStream, SocketAddr}; +use std::net::{TcpStream, SocketAddr, Ipv4Addr}; use bytes::{BufMut, Buf}; use google_home::errors::{ErrorCode, DeviceError}; @@ -19,25 +19,12 @@ struct TPLinkOutlet { } impl TPLinkOutlet { - pub fn new(ip: [u8; 4]) -> Self { + pub fn new(ip: Ipv4Addr) -> Self { // @TODO Get the current state of the outlet Self { addr: (ip, 9999).into() } } - - pub fn encrypt(data: bytes::Bytes) -> bytes::Bytes { - let mut key: u8 = 171; - let mut encrypted = bytes::BytesMut::with_capacity(data.len() + 4); - - encrypted.put_u32(data.len() as u32); - - for c in data { - key = key ^ c; - encrypted.put_u8(key); - } - - return encrypted.freeze(); - } } + #[derive(Debug, Serialize)] struct RequestRelayState { state: isize, @@ -80,7 +67,6 @@ impl Request { } } - fn encrypt(&self) -> bytes::Bytes { let data: bytes::Bytes = serde_json::to_string(self).unwrap().into(); @@ -221,7 +207,7 @@ pub struct AudioSetup { } impl AudioSetup { - pub fn new(identifier: String, mqtt: MqttDeviceConfig, mixer_ip: [u8; 4], speakers_ip: [u8; 4], client: AsyncClient) -> Self { + pub fn new(identifier: String, mqtt: MqttDeviceConfig, mixer_ip: Ipv4Addr, speakers_ip: Ipv4Addr, client: AsyncClient) -> Self { let mixer = TPLinkOutlet::new(mixer_ip); let speakers = TPLinkOutlet::new(speakers_ip);