Turn off the device directly if the timeout is set to zero
This commit is contained in:
@@ -59,6 +59,7 @@ impl PresenceDeviceConfig {
|
|||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct LightsConfig {
|
pub struct LightsConfig {
|
||||||
lights: Vec<String>,
|
lights: Vec<String>,
|
||||||
|
#[serde(default)]
|
||||||
timeout: u64, // Timeout in seconds
|
timeout: u64, // Timeout in seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,9 +196,14 @@ impl OnMqtt for ContactSensor {
|
|||||||
} else {
|
} else {
|
||||||
for (light, previous) in &lights.lights {
|
for (light, previous) in &lights.lights {
|
||||||
let mut light = light.write().await;
|
let mut light = light.write().await;
|
||||||
if !previous && let Some(light) = As::<dyn Timeout>::cast_mut(light.as_mut()) {
|
if !previous {
|
||||||
light.start_timeout(lights.timeout);
|
// If the timeout is zero just turn the light off directly
|
||||||
}
|
if lights.timeout.is_zero() && let Some(light) = As::<dyn OnOff>::cast_mut(light.as_mut()) {
|
||||||
|
light.set_on(false).await.ok();
|
||||||
|
} else if let Some(light) = As::<dyn Timeout>::cast_mut(light.as_mut()) {
|
||||||
|
light.start_timeout(lights.timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user