Compare commits

..

2 Commits

Author SHA1 Message Date
1e9bd300a6 feat: Add proper type definition for devices
All checks were successful
Build and deploy / build (push) Successful in 10m38s
Build and deploy / Deploy container (push) Has been skipped
Depending on the implemented traits the lua class will inherit from the
associated interface class.

It also specifies the constructor function for each of the devices.
2025-10-11 00:14:30 +02:00
8010f7a404 feat: Added Typed impl for all automation devices
To accomplish this a basic implementation was also provided for some
types in automation_lib
2025-10-10 03:56:33 +02:00
12 changed files with 39 additions and 43 deletions

4
Cargo.lock generated
View File

@@ -1108,7 +1108,7 @@ dependencies = [
[[package]]
name = "lua_typed"
version = "0.1.0"
source = "git+https://git.huizinga.dev/Dreaded_X/lua_typed#d30a01aada8f5fc49ad3a296ddbf6e369e08d1f4"
source = "git+https://git.huizinga.dev/Dreaded_X/lua_typed#513b36afdbc23efcf10847f070faff7fcd30f29d"
dependencies = [
"eui48",
"lua_typed_macro",
@@ -1117,7 +1117,7 @@ dependencies = [
[[package]]
name = "lua_typed_macro"
version = "0.1.0"
source = "git+https://git.huizinga.dev/Dreaded_X/lua_typed#d30a01aada8f5fc49ad3a296ddbf6e369e08d1f4"
source = "git+https://git.huizinga.dev/Dreaded_X/lua_typed#513b36afdbc23efcf10847f070faff7fcd30f29d"
dependencies = [
"convert_case",
"itertools",

View File

@@ -17,7 +17,7 @@ use tracing::{debug, trace};
#[typed(as = "AirFilterConfig")]
pub struct Config {
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub info: InfoConfig,
pub url: String,
}

View File

@@ -30,25 +30,25 @@ crate::register_type!(SensorType);
#[typed(as = "ContactSensorConfig")]
pub struct Config {
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub info: InfoConfig,
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub mqtt: MqttDeviceConfig,
#[device_config(default(SensorType::Window))]
#[typed(default)]
#[serde(default)]
pub sensor_type: SensorType,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub callback: ActionCallback<(ContactSensor, bool)>,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub battery_callback: ActionCallback<(ContactSensor, f32)>,
#[device_config(from_lua)]
#[typed(default)]
#[serde(default)]
pub client: WrappedAsyncClient,
}
crate::register_type!(Config);

View File

@@ -14,34 +14,34 @@ use tracing::{debug, trace, warn};
#[typed(as = "HueSwitchConfig")]
pub struct Config {
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub info: InfoConfig,
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub mqtt: MqttDeviceConfig,
#[device_config(from_lua)]
pub client: WrappedAsyncClient,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub left_callback: ActionCallback<HueSwitch>,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub right_callback: ActionCallback<HueSwitch>,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub left_hold_callback: ActionCallback<HueSwitch>,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub right_hold_callback: ActionCallback<HueSwitch>,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub battery_callback: ActionCallback<(HueSwitch, f32)>,
}
crate::register_type!(Config);

View File

@@ -14,25 +14,25 @@ use tracing::{debug, error, trace};
#[typed(as = "IkeaRemoteConfig")]
pub struct Config {
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub info: InfoConfig,
#[device_config(default)]
#[typed(default)]
#[serde(default)]
pub single_button: bool,
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub mqtt: MqttDeviceConfig,
#[device_config(from_lua)]
pub client: WrappedAsyncClient,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub callback: ActionCallback<(IkeaRemote, bool)>,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub battery_callback: ActionCallback<(IkeaRemote, f32)>,
}
crate::register_type!(Config);

View File

@@ -18,13 +18,13 @@ use tracing::{debug, trace, warn};
pub struct Config {
pub identifier: String,
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub mqtt: MqttDeviceConfig,
pub min: isize,
pub max: isize,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub callback: ActionCallback<(LightSensor, bool)>,
#[device_config(from_lua)]

View File

@@ -24,12 +24,10 @@ crate::register_type!(Priority);
#[derive(Debug, Serialize, Deserialize, Clone, Typed)]
#[serde(rename_all = "snake_case", tag = "action")]
#[typed(rename_all = "snake_case", tag = "action")]
pub enum ActionType {
Broadcast {
#[serde(skip_serializing_if = "HashMap::is_empty")]
#[serde(default)]
#[typed(default)]
extras: HashMap<String, String>,
},
// View,
@@ -39,7 +37,6 @@ pub enum ActionType {
#[derive(Debug, Serialize, Deserialize, Clone, Typed)]
pub struct Action {
#[serde(flatten)]
#[typed(flatten)]
pub action: ActionType,
pub label: String,
pub clear: Option<bool>,
@@ -50,7 +47,6 @@ crate::register_type!(Action);
struct NotificationFinal {
topic: String,
#[serde(flatten)]
#[typed(flatten)]
inner: Notification,
}
@@ -80,7 +76,7 @@ impl Notification {
#[typed(as = "NtfyConfig")]
pub struct Config {
#[device_config(default("https://ntfy.sh".into()))]
#[typed(default)]
#[serde(default)]
pub url: String,
pub topic: String,
}

View File

@@ -18,11 +18,11 @@ use tracing::{debug, trace, warn};
#[typed(as = "PresenceConfig")]
pub struct Config {
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub mqtt: MqttDeviceConfig,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub callback: ActionCallback<(Presence, bool)>,
#[device_config(from_lua)]

View File

@@ -20,14 +20,14 @@ use tracing::{debug, error, trace};
#[typed(as = "WolConfig")]
pub struct Config {
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub info: InfoConfig,
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub mqtt: MqttDeviceConfig,
pub mac_address: MacAddress,
#[device_config(default(Ipv4Addr::new(255, 255, 255, 255)))]
#[typed(default)]
#[serde(default)]
pub broadcast_ip: Ipv4Addr,
#[device_config(from_lua)]
pub client: WrappedAsyncClient,

View File

@@ -18,13 +18,13 @@ use tracing::{debug, error, trace};
pub struct Config {
pub identifier: String,
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub mqtt: MqttDeviceConfig,
// Power in Watt
pub threshold: f32,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub done_callback: ActionCallback<Washer>,
#[device_config(from_lua)]

View File

@@ -34,18 +34,18 @@ where
Light<T>: Typed,
{
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub info: InfoConfig,
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub mqtt: MqttDeviceConfig,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub callback: ActionCallback<(Light<T>, T)>,
#[device_config(from_lua)]
#[typed(default)]
#[serde(default)]
pub client: WrappedAsyncClient,
}
crate::register_type!(Config<StateOnOff>);

View File

@@ -50,17 +50,17 @@ where
Outlet<T>: Typed,
{
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub info: InfoConfig,
#[device_config(flatten)]
#[typed(flatten)]
#[serde(flatten)]
pub mqtt: MqttDeviceConfig,
#[device_config(default(OutletType::Outlet))]
#[typed(default)]
#[serde(default)]
pub outlet_type: OutletType,
#[device_config(from_lua, default)]
#[typed(default)]
#[serde(default)]
pub callback: ActionCallback<(Outlet<T>, T)>,
#[device_config(from_lua)]