Switched to proper Ipv4Addr type
This commit is contained in:
parent
c9b2127eed
commit
69abaf98d7
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user