Quickly hacked in is_on function on devices in lua
All checks were successful
Build and deploy automation_rs / Build automation_rs (push) Successful in 5m48s
Build and deploy automation_rs / Build Docker image (push) Successful in 47s
Build and deploy automation_rs / Deploy Docker container (push) Successful in 30s

In order to get feature parity with pre-lua the is_on function is
manually implemented on all wrapped devices in lua
This implementation will need to be improved in the future.
This commit is contained in:
Dreaded_X 2024-05-07 00:02:02 +02:00
parent c7fc25d239
commit 794b8eef19
Signed by: Dreaded_X
GPG Key ID: FA5F485356B0D2D4
2 changed files with 20 additions and 5 deletions

View File

@ -137,8 +137,7 @@ automation.device_manager:add(IkeaOutlet.new({
topic = mqtt_z2m("workbench/outlet"), topic = mqtt_z2m("workbench/outlet"),
client = mqtt_client, client = mqtt_client,
})) }))
local hallway_lights = HueGroup.new({
local hallway_lights = automation.device_manager:add(HueGroup.new({
identifier = "hallway_lights", identifier = "hallway_lights",
ip = hue_ip, ip = hue_ip,
login = hue_token, login = hue_token,
@ -149,7 +148,8 @@ local hallway_lights = automation.device_manager:add(HueGroup.new({
{ topic = mqtt_z2m("hallway/remote") }, { topic = mqtt_z2m("hallway/remote") },
}, },
client = mqtt_client, client = mqtt_client,
})) })
automation.device_manager:add(hallway_lights)
automation.device_manager:add(ContactSensor.new({ automation.device_manager:add(ContactSensor.new({
identifier = "hallway_frontdoor", identifier = "hallway_frontdoor",
@ -173,6 +173,9 @@ local bedroom_air_filter = AirFilter.new({
}) })
automation.device_manager:add(bedroom_air_filter) automation.device_manager:add(bedroom_air_filter)
automation.device_manager:schedule("0/1 * * * * *", function() automation.device_manager:schedule("0 0 19 * * *", function()
print("Device: " .. bedroom_air_filter:get_id()) bedroom_air_filter:set_on(true)
end)
automation.device_manager:schedule("0 0 20 * * *", function()
bedroom_air_filter:set_on(false)
end) end)

View File

@ -5,6 +5,7 @@ use std::sync::Arc;
use futures::future::join_all; use futures::future::join_all;
use futures::Future; use futures::Future;
use google_home::traits::OnOff;
use mlua::FromLua; use mlua::FromLua;
use tokio::sync::{RwLock, RwLockReadGuard}; use tokio::sync::{RwLock, RwLockReadGuard};
use tokio_cron_scheduler::{Job, JobScheduler}; use tokio_cron_scheduler::{Job, JobScheduler};
@ -42,6 +43,17 @@ impl mlua::UserData for WrappedDevice {
methods.add_async_method("get_id", |_lua, this, _: ()| async { methods.add_async_method("get_id", |_lua, this, _: ()| async {
Ok(crate::devices::Device::get_id(this.0.read().await.as_ref())) Ok(crate::devices::Device::get_id(this.0.read().await.as_ref()))
}); });
methods.add_async_method("set_on", |_lua, this, on: bool| async move {
let mut device = this.0.write().await;
let device = device.as_mut();
if let Some(device) = device.cast_mut() as Option<&mut dyn OnOff> {
device.set_on(on).await.unwrap()
};
Ok(())
});
} }
} }