LuaDevice macro now uses LuaDeviceCreate trait to create devices from configs
All checks were successful
Build and deploy automation_rs / Build automation_rs (push) Successful in 4m53s
Build and deploy automation_rs / Build Docker image (push) Successful in 59s
Build and deploy automation_rs / Deploy Docker container (push) Has been skipped

This commit is contained in:
2024-04-29 02:53:21 +02:00
parent 40426862e5
commit 2b62aca78a
16 changed files with 116 additions and 84 deletions

View File

@@ -1,3 +1,4 @@
use std::convert::Infallible;
use std::net::SocketAddr;
use async_trait::async_trait;
@@ -5,8 +6,8 @@ use automation_macro::{LuaDevice, LuaDeviceConfig};
use serde::{Deserialize, Serialize};
use tracing::{error, trace, warn};
use super::LuaDeviceCreate;
use crate::devices::Device;
use crate::error::DeviceConfigError;
use crate::event::{OnDarkness, OnPresence};
#[derive(Debug)]
@@ -32,7 +33,6 @@ pub struct HueBridgeConfig {
#[derive(Debug, LuaDevice)]
pub struct HueBridge {
#[config]
config: HueBridgeConfig,
}
@@ -41,12 +41,18 @@ struct FlagMessage {
flag: bool,
}
impl HueBridge {
async fn create(config: HueBridgeConfig) -> Result<Self, DeviceConfigError> {
#[async_trait]
impl LuaDeviceCreate for HueBridge {
type Config = HueBridgeConfig;
type Error = Infallible;
async fn create(config: Self::Config) -> Result<Self, Infallible> {
trace!(id = config.identifier, "Setting up HueBridge");
Ok(Self { config })
}
}
impl HueBridge {
pub async fn set_flag(&self, flag: Flag, value: bool) {
let flag_id = match flag {
Flag::Presence => self.config.flags.presence,