Compare commits

..

3 Commits

Author SHA1 Message Date
Dreaded_X ce302b148e feat: Sync printer light with room light
Build and deploy / build (push) Successful in 18m22s
Build and deploy / Deploy container (push) Successful in 39s
2026-06-20 05:22:59 +02:00
Dreaded_X fe6b3b52e1 feat: Add basic support for bambu printer 2026-06-20 05:22:57 +02:00
Dreaded_X 361d799377 feat: Build fully static binary 2026-06-20 05:22:56 +02:00
11 changed files with 19 additions and 44 deletions
Generated
+2 -4
View File
@@ -151,14 +151,12 @@ dependencies = [
"inventory",
"lua_typed",
"mlua",
"reqwest",
"rumqttc",
"serde",
"serde_json",
"thiserror",
"tokio",
"tracing",
"webpki-root-certs",
]
[[package]]
@@ -2880,9 +2878,9 @@ dependencies = [
[[package]]
name = "webpki-root-certs"
version = "1.0.8"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d46a5a140e6f7afeccd8eae97eff335163939eac8b929834875168b29b3d267"
checksum = "f31141ce3fc3e300ae89b78c0dd67f9708061d1d2eda54b8209346fd6be9a92c"
dependencies = [
"rustls-pki-types",
]
+1 -1
View File
@@ -21,7 +21,7 @@ ENV RELEASE_VERSION=${RELEASE_VERSION}
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
ENV AUTOMATION__ENTRYPOINT=/app/config/config.lua
ENV LUA_PATH="/app/?.lua;;"
+4 -6
View File
@@ -1,7 +1,6 @@
use async_trait::async_trait;
use automation_lib::config::InfoConfig;
use automation_lib::device::{Device, LuaDeviceCreate};
use automation_lib::reqwest::new_client;
use automation_macro::{Device, LuaDeviceConfig};
use google_home::device::Name;
use google_home::errors::ErrorCode;
@@ -53,21 +52,20 @@ impl AirFilter {
async fn set_fan_speed(&self, speed: air_filter_types::FanSpeed) -> Result<(), Error> {
let message = air_filter_types::SetFanSpeed::new(speed);
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(())
}
async fn get_fan_state(&self) -> Result<air_filter_types::FanState, Error> {
let url = format!("{}/state/fan", self.config.url);
let client = new_client();
Ok(client.get(url).send().await?.json().await?)
Ok(reqwest::get(url).await?.json().await?)
}
async fn get_sensor_data(&self) -> Result<air_filter_types::SensorData, Error> {
let url = format!("{}/state/sensor", self.config.url);
let client = new_client();
Ok(client.get(url).send().await?.json().await?)
Ok(reqwest::get(url).await?.json().await?)
}
}
+1 -2
View File
@@ -4,7 +4,6 @@ use std::net::SocketAddr;
use async_trait::async_trait;
use automation_lib::device::{Device, LuaDeviceCreate};
use automation_lib::lua::traits::PartialUserData;
use automation_lib::reqwest::new_client;
use automation_macro::{Device, LuaDeviceConfig};
use lua_typed::Typed;
use mlua::LuaSerdeExt;
@@ -99,7 +98,7 @@ impl HueBridge {
);
trace!(?flag, flag_id, value, "Sending request to change flag");
let res = new_client()
let res = reqwest::Client::new()
.put(url)
.json(&FlagMessage { flag: value })
.send()
+9 -4
View File
@@ -3,7 +3,6 @@ use std::net::SocketAddr;
use anyhow::Result;
use async_trait::async_trait;
use automation_lib::lua::traits::PartialUserData;
use automation_lib::reqwest::new_client;
use automation_macro::{Device, LuaDeviceConfig};
use google_home::errors::ErrorCode;
use google_home::traits::OnOff;
@@ -75,7 +74,7 @@ impl OnOff for HueGroup {
message::Action::on(false)
};
let res = new_client()
let res = reqwest::Client::new()
.put(self.url_set_action())
.json(&message)
.send()
@@ -95,7 +94,10 @@ impl OnOff for HueGroup {
}
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 {
Ok(res) => {
@@ -126,7 +128,10 @@ struct AllOn;
impl PartialUserData<HueGroup> for AllOn {
fn add_methods<M: mlua::UserDataMethods<HueGroup>>(methods: &mut M) {
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 {
Ok(res) => {
+1 -2
View File
@@ -4,7 +4,6 @@ use std::convert::Infallible;
use async_trait::async_trait;
use automation_lib::device::{Device, LuaDeviceCreate};
use automation_lib::lua::traits::PartialUserData;
use automation_lib::reqwest::new_client;
use automation_macro::{Device, LuaDeviceConfig};
use lua_typed::Typed;
use mlua::LuaSerdeExt;
@@ -144,7 +143,7 @@ impl Ntfy {
let notification = notification.finalize(&self.config.topic);
// Create the request
let res = new_client()
let res = reqwest::Client::new()
.post(self.config.url.clone())
.json(&notification)
.send()
-2
View File
@@ -4,7 +4,6 @@ version = "0.1.0"
edition = "2024"
[dependencies]
reqwest = { workspace = true }
automation_macro = { workspace = true }
async-trait = { workspace = true }
automation_cast = { workspace = true }
@@ -22,4 +21,3 @@ serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
webpki-root-certs = "1.0.8"
-1
View File
@@ -13,7 +13,6 @@ pub mod helpers;
pub mod lua;
pub mod messages;
pub mod mqtt;
pub mod reqwest;
type RegisterFn = fn(lua: &mlua::Lua) -> mlua::Result<mlua::Table>;
type DefinitionsFn = fn() -> String;
-17
View File
@@ -1,17 +0,0 @@
use reqwest::{Certificate, Client};
pub fn new_client() -> Client {
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")
}
-3
View File
@@ -12,9 +12,6 @@ local module = {}
function module.setup(mqtt_client)
local light = nil
print(secrets.printer_device_id)
print(secrets.printer_access_code)
local bambu = devices.Bambu.new({
host = "thalia.huizinga.lan",
device_id = secrets.printer_device_id,
+1 -2
View File
@@ -1,6 +1,5 @@
use std::result;
use automation_lib::reqwest::new_client;
use axum::extract::{FromRef, FromRequestParts};
use axum::http::StatusCode;
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: 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?
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
if let Some(auth) = parts.headers.get(axum::http::header::AUTHORIZATION) {