Some cleanup and added light sensor

This commit is contained in:
2023-01-03 20:46:37 +01:00
parent cfd10a7daf
commit c9b2127eed
10 changed files with 182 additions and 43 deletions

View File

@@ -25,10 +25,8 @@ pub struct IkeaOutlet {
impl IkeaOutlet {
pub fn new(identifier: String, info: InfoConfig, mqtt: MqttDeviceConfig, kettle: Option<KettleConfig>, client: AsyncClient) -> Self {
let c = client.clone();
let t = mqtt.topic.clone();
// @TODO Handle potential errors here
c.subscribe(t, rumqttc::QoS::AtLeastOnce).block_on().unwrap();
client.subscribe(mqtt.topic.clone(), rumqttc::QoS::AtLeastOnce).block_on().unwrap();
Self{ identifier, info, mqtt, kettle, client, last_known_state: false, handle: None }
}
@@ -115,9 +113,7 @@ impl OnPresence for IkeaOutlet {
// Turn off the outlet when we leave the house
if !presence {
debug!(id = self.identifier, "Turning device off");
let client = self.client.clone();
let topic = self.mqtt.topic.clone();
set_on(client, topic, false).block_on();
set_on(self.client.clone(), self.mqtt.topic.clone(), false).block_on();
}
}
}
@@ -159,9 +155,7 @@ impl traits::OnOff for IkeaOutlet {
}
fn set_on(&mut self, on: bool) -> Result<(), ErrorCode> {
let client = self.client.clone();
let topic = self.mqtt.topic.clone();
set_on(client, topic, on).block_on();
set_on(self.client.clone(), self.mqtt.topic.clone(), on).block_on();
Ok(())
}

View File

@@ -16,9 +16,8 @@ pub struct WakeOnLAN {
impl WakeOnLAN {
pub fn new(identifier: String, info: InfoConfig, mqtt: MqttDeviceConfig, mac_address: String, client: AsyncClient) -> Self {
let t = mqtt.topic.clone();
// @TODO Handle potential errors here
client.subscribe(t, rumqttc::QoS::AtLeastOnce).block_on().unwrap();
client.subscribe(mqtt.topic.clone(), rumqttc::QoS::AtLeastOnce).block_on().unwrap();
Self { identifier, info, mqtt, mac_address }
}
@@ -32,7 +31,6 @@ impl Device for WakeOnLAN {
impl OnMqtt for WakeOnLAN {
fn on_mqtt(&mut self, message: &Publish) {
if message.topic != self.mqtt.topic {
return;
}