Compare commits
4 Commits
8babffed76
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
77a32d1507
|
|||
|
ce302b148e
|
|||
|
fe6b3b52e1
|
|||
|
361d799377
|
Generated
+2
-4
@@ -151,14 +151,12 @@ dependencies = [
|
|||||||
"inventory",
|
"inventory",
|
||||||
"lua_typed",
|
"lua_typed",
|
||||||
"mlua",
|
"mlua",
|
||||||
"reqwest",
|
|
||||||
"rumqttc",
|
"rumqttc",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"webpki-root-certs",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2880,9 +2878,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webpki-root-certs"
|
name = "webpki-root-certs"
|
||||||
version = "1.0.8"
|
version = "1.0.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0d46a5a140e6f7afeccd8eae97eff335163939eac8b929834875168b29b3d267"
|
checksum = "f31141ce3fc3e300ae89b78c0dd67f9708061d1d2eda54b8209346fd6be9a92c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
]
|
]
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ ENV RELEASE_VERSION=${RELEASE_VERSION}
|
|||||||
RUN cargo auditable build --release
|
RUN cargo auditable build --release
|
||||||
|
|
||||||
|
|
||||||
FROM scratch AS runtime
|
FROM gcr.io/distroless/static-debian13:nonroot AS runtime
|
||||||
COPY --from=builder /app/target/release/automation /app/automation
|
COPY --from=builder /app/target/release/automation /app/automation
|
||||||
ENV AUTOMATION__ENTRYPOINT=/app/config/config.lua
|
ENV AUTOMATION__ENTRYPOINT=/app/config/config.lua
|
||||||
ENV LUA_PATH="/app/?.lua;;"
|
ENV LUA_PATH="/app/?.lua;;"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use automation_lib::config::InfoConfig;
|
use automation_lib::config::InfoConfig;
|
||||||
use automation_lib::device::{Device, LuaDeviceCreate};
|
use automation_lib::device::{Device, LuaDeviceCreate};
|
||||||
use automation_lib::reqwest::new_client;
|
|
||||||
use automation_macro::{Device, LuaDeviceConfig};
|
use automation_macro::{Device, LuaDeviceConfig};
|
||||||
use google_home::device::Name;
|
use google_home::device::Name;
|
||||||
use google_home::errors::ErrorCode;
|
use google_home::errors::ErrorCode;
|
||||||
@@ -53,21 +52,20 @@ impl AirFilter {
|
|||||||
async fn set_fan_speed(&self, speed: air_filter_types::FanSpeed) -> Result<(), Error> {
|
async fn set_fan_speed(&self, speed: air_filter_types::FanSpeed) -> Result<(), Error> {
|
||||||
let message = air_filter_types::SetFanSpeed::new(speed);
|
let message = air_filter_types::SetFanSpeed::new(speed);
|
||||||
let url = format!("{}/state/fan", self.config.url);
|
let url = format!("{}/state/fan", self.config.url);
|
||||||
new_client().put(url).json(&message).send().await?;
|
let client = reqwest::Client::new();
|
||||||
|
client.put(url).json(&message).send().await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_fan_state(&self) -> Result<air_filter_types::FanState, Error> {
|
async fn get_fan_state(&self) -> Result<air_filter_types::FanState, Error> {
|
||||||
let url = format!("{}/state/fan", self.config.url);
|
let url = format!("{}/state/fan", self.config.url);
|
||||||
let client = new_client();
|
Ok(reqwest::get(url).await?.json().await?)
|
||||||
Ok(client.get(url).send().await?.json().await?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_sensor_data(&self) -> Result<air_filter_types::SensorData, Error> {
|
async fn get_sensor_data(&self) -> Result<air_filter_types::SensorData, Error> {
|
||||||
let url = format!("{}/state/sensor", self.config.url);
|
let url = format!("{}/state/sensor", self.config.url);
|
||||||
let client = new_client();
|
Ok(reqwest::get(url).await?.json().await?)
|
||||||
Ok(client.get(url).send().await?.json().await?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use std::net::SocketAddr;
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use automation_lib::device::{Device, LuaDeviceCreate};
|
use automation_lib::device::{Device, LuaDeviceCreate};
|
||||||
use automation_lib::lua::traits::PartialUserData;
|
use automation_lib::lua::traits::PartialUserData;
|
||||||
use automation_lib::reqwest::new_client;
|
|
||||||
use automation_macro::{Device, LuaDeviceConfig};
|
use automation_macro::{Device, LuaDeviceConfig};
|
||||||
use lua_typed::Typed;
|
use lua_typed::Typed;
|
||||||
use mlua::LuaSerdeExt;
|
use mlua::LuaSerdeExt;
|
||||||
@@ -99,7 +98,7 @@ impl HueBridge {
|
|||||||
);
|
);
|
||||||
|
|
||||||
trace!(?flag, flag_id, value, "Sending request to change flag");
|
trace!(?flag, flag_id, value, "Sending request to change flag");
|
||||||
let res = new_client()
|
let res = reqwest::Client::new()
|
||||||
.put(url)
|
.put(url)
|
||||||
.json(&FlagMessage { flag: value })
|
.json(&FlagMessage { flag: value })
|
||||||
.send()
|
.send()
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use std::net::SocketAddr;
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use automation_lib::lua::traits::PartialUserData;
|
use automation_lib::lua::traits::PartialUserData;
|
||||||
use automation_lib::reqwest::new_client;
|
|
||||||
use automation_macro::{Device, LuaDeviceConfig};
|
use automation_macro::{Device, LuaDeviceConfig};
|
||||||
use google_home::errors::ErrorCode;
|
use google_home::errors::ErrorCode;
|
||||||
use google_home::traits::OnOff;
|
use google_home::traits::OnOff;
|
||||||
@@ -75,7 +74,7 @@ impl OnOff for HueGroup {
|
|||||||
message::Action::on(false)
|
message::Action::on(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = new_client()
|
let res = reqwest::Client::new()
|
||||||
.put(self.url_set_action())
|
.put(self.url_set_action())
|
||||||
.json(&message)
|
.json(&message)
|
||||||
.send()
|
.send()
|
||||||
@@ -95,7 +94,10 @@ impl OnOff for HueGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn on(&self) -> Result<bool, ErrorCode> {
|
async fn on(&self) -> Result<bool, ErrorCode> {
|
||||||
let res = new_client().get(self.url_get_state()).send().await;
|
let res = reqwest::Client::new()
|
||||||
|
.get(self.url_get_state())
|
||||||
|
.send()
|
||||||
|
.await;
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
@@ -126,7 +128,10 @@ struct AllOn;
|
|||||||
impl PartialUserData<HueGroup> for AllOn {
|
impl PartialUserData<HueGroup> for AllOn {
|
||||||
fn add_methods<M: mlua::UserDataMethods<HueGroup>>(methods: &mut M) {
|
fn add_methods<M: mlua::UserDataMethods<HueGroup>>(methods: &mut M) {
|
||||||
methods.add_async_method("all_on", async |_lua, this, ()| {
|
methods.add_async_method("all_on", async |_lua, this, ()| {
|
||||||
let res = new_client().get(this.url_get_state()).send().await;
|
let res = reqwest::Client::new()
|
||||||
|
.get(this.url_get_state())
|
||||||
|
.send()
|
||||||
|
.await;
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use std::convert::Infallible;
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use automation_lib::device::{Device, LuaDeviceCreate};
|
use automation_lib::device::{Device, LuaDeviceCreate};
|
||||||
use automation_lib::lua::traits::PartialUserData;
|
use automation_lib::lua::traits::PartialUserData;
|
||||||
use automation_lib::reqwest::new_client;
|
|
||||||
use automation_macro::{Device, LuaDeviceConfig};
|
use automation_macro::{Device, LuaDeviceConfig};
|
||||||
use lua_typed::Typed;
|
use lua_typed::Typed;
|
||||||
use mlua::LuaSerdeExt;
|
use mlua::LuaSerdeExt;
|
||||||
@@ -144,7 +143,7 @@ impl Ntfy {
|
|||||||
let notification = notification.finalize(&self.config.topic);
|
let notification = notification.finalize(&self.config.topic);
|
||||||
|
|
||||||
// Create the request
|
// Create the request
|
||||||
let res = new_client()
|
let res = reqwest::Client::new()
|
||||||
.post(self.config.url.clone())
|
.post(self.config.url.clone())
|
||||||
.json(¬ification)
|
.json(¬ification)
|
||||||
.send()
|
.send()
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = { workspace = true }
|
|
||||||
automation_macro = { workspace = true }
|
automation_macro = { workspace = true }
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
automation_cast = { workspace = true }
|
automation_cast = { workspace = true }
|
||||||
@@ -22,4 +21,3 @@ serde_json = { workspace = true }
|
|||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
webpki-root-certs = "1.0.8"
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ pub mod helpers;
|
|||||||
pub mod lua;
|
pub mod lua;
|
||||||
pub mod messages;
|
pub mod messages;
|
||||||
pub mod mqtt;
|
pub mod mqtt;
|
||||||
pub mod reqwest;
|
|
||||||
|
|
||||||
type RegisterFn = fn(lua: &mlua::Lua) -> mlua::Result<mlua::Table>;
|
type RegisterFn = fn(lua: &mlua::Lua) -> mlua::Result<mlua::Table>;
|
||||||
type DefinitionsFn = fn() -> String;
|
type DefinitionsFn = fn() -> String;
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
use reqwest::{Certificate, Client};
|
|
||||||
|
|
||||||
pub fn new_client() -> Client {
|
|
||||||
println!(
|
|
||||||
"{}/{}",
|
|
||||||
std::env!("CARGO_PKG_NAME"),
|
|
||||||
std::env!("CARGO_PKG_VERSION")
|
|
||||||
);
|
|
||||||
|
|
||||||
Client::builder()
|
|
||||||
.user_agent(format!(
|
|
||||||
"{}/{}",
|
|
||||||
std::env!("CARGO_PKG_NAME"),
|
|
||||||
std::env!("CARGO_PKG_VERSION")
|
|
||||||
))
|
|
||||||
.tls_certs_only(
|
|
||||||
webpki_root_certs::TLS_SERVER_ROOT_CERTS
|
|
||||||
.iter()
|
|
||||||
.map(|cert| Certificate::from_der(cert).unwrap()),
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
.expect("Client should build")
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,7 @@ function module.setup(mqtt_client)
|
|||||||
local light = nil
|
local light = nil
|
||||||
|
|
||||||
local bambu = devices.Bambu.new({
|
local bambu = devices.Bambu.new({
|
||||||
host = "thalia.huizinga.lan",
|
host = "10.0.0.108",
|
||||||
device_id = secrets.printer_device_id,
|
device_id = secrets.printer_device_id,
|
||||||
access_code = secrets.printer_access_code,
|
access_code = secrets.printer_access_code,
|
||||||
callbacks = {
|
callbacks = {
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
use std::result;
|
use std::result;
|
||||||
|
|
||||||
use automation_lib::reqwest::new_client;
|
|
||||||
use axum::extract::{FromRef, FromRequestParts};
|
use axum::extract::{FromRef, FromRequestParts};
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use axum::http::request::Parts;
|
use axum::http::request::Parts;
|
||||||
@@ -94,7 +93,7 @@ where
|
|||||||
// TODO: Do some discovery to find the correct url for this instead of assuming
|
// TODO: Do some discovery to find the correct url for this instead of assuming
|
||||||
// TODO: I think we can also just run Authlia in front of the endpoint instead
|
// TODO: I think we can also just run Authlia in front of the endpoint instead
|
||||||
// This would then give us a header containing the logged in user info?
|
// This would then give us a header containing the logged in user info?
|
||||||
let mut req = new_client().get(format!("{}/userinfo", openid_url));
|
let mut req = reqwest::Client::new().get(format!("{}/userinfo", openid_url));
|
||||||
|
|
||||||
// Add auth header to the request if it exists
|
// Add auth header to the request if it exists
|
||||||
if let Some(auth) = parts.headers.get(axum::http::header::AUTHORIZATION) {
|
if let Some(auth) = parts.headers.get(axum::http::header::AUTHORIZATION) {
|
||||||
|
|||||||
Reference in New Issue
Block a user