feat: Added Typed impl for all automation devices
To accomplish this a basic implementation was also provided for some types in automation_lib
This commit is contained in:
@@ -13,6 +13,7 @@ google_home = { workspace = true }
|
||||
hostname = { workspace = true }
|
||||
indexmap = { workspace = true }
|
||||
inventory = { workspace = true }
|
||||
lua_typed = { workspace = true }
|
||||
mlua = { workspace = true }
|
||||
rumqttc = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use futures::future::try_join_all;
|
||||
use lua_typed::Typed;
|
||||
use mlua::{FromLua, IntoLuaMulti};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -9,6 +10,23 @@ pub struct ActionCallback<P> {
|
||||
_parameters: PhantomData<P>,
|
||||
}
|
||||
|
||||
impl<A: Typed> Typed for ActionCallback<A> {
|
||||
fn type_name() -> String {
|
||||
let type_name = A::type_name();
|
||||
format!("fun(_: {type_name}) | fun(_: {type_name})[]")
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Typed, B: Typed> Typed for ActionCallback<(A, B)> {
|
||||
fn type_name() -> String {
|
||||
let type_name_a = A::type_name();
|
||||
let type_name_b = B::type_name();
|
||||
format!(
|
||||
"fun(_: {type_name_a}, _: {type_name_b}) | fun(_: {type_name_a}, _: {type_name_b})[]"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: For some reason the derive macro combined with PhantomData leads to issues where it
|
||||
// requires all types part of P to implement default, even if they never actually get constructed.
|
||||
// By manually implemented Default it works fine.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::net::{Ipv4Addr, SocketAddr};
|
||||
use std::time::Duration;
|
||||
|
||||
use lua_typed::Typed;
|
||||
use rumqttc::{MqttOptions, Transport};
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -52,7 +53,7 @@ fn default_fulfillment_port() -> u16 {
|
||||
7878
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, Typed)]
|
||||
pub struct InfoConfig {
|
||||
pub name: String,
|
||||
pub room: Option<String>,
|
||||
@@ -68,7 +69,7 @@ impl InfoConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize, Typed)]
|
||||
pub struct MqttDeviceConfig {
|
||||
pub topic: String,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(iterator_try_collect)]
|
||||
#![feature(with_negative_coherence)]
|
||||
|
||||
use tracing::debug;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use lua_typed::Typed;
|
||||
use mlua::FromLua;
|
||||
use rumqttc::{AsyncClient, Event, EventLoop, Incoming};
|
||||
use tracing::{debug, warn};
|
||||
@@ -9,6 +10,12 @@ use crate::event::{self, EventChannel};
|
||||
#[derive(Debug, Clone, FromLua)]
|
||||
pub struct WrappedAsyncClient(pub AsyncClient);
|
||||
|
||||
impl Typed for WrappedAsyncClient {
|
||||
fn type_name() -> String {
|
||||
"AsyncClient".into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for WrappedAsyncClient {
|
||||
type Target = AsyncClient;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user