Compare commits
2 Commits
1d6f95e0a0
...
b327d32177
| Author | SHA1 | Date | |
|---|---|---|---|
|
b327d32177
|
|||
|
d3d9a19f52
|
@@ -87,14 +87,6 @@ repos:
|
|||||||
files: (\.rs|Cargo.lock)$
|
files: (\.rs|Cargo.lock)$
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
|
|
||||||
- id: generate_definitions
|
|
||||||
name: generate definitions
|
|
||||||
description: Generate lua definitions
|
|
||||||
entry: cargo run --bin generate_definitions
|
|
||||||
language: system
|
|
||||||
types: [rust]
|
|
||||||
pass_filenames: false
|
|
||||||
|
|
||||||
- repo: https://github.com/hadolint/hadolint
|
- repo: https://github.com/hadolint/hadolint
|
||||||
rev: v2.13.1
|
rev: v2.13.1
|
||||||
hooks:
|
hooks:
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
name = "automation"
|
name = "automation"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
default-run = "automation"
|
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#![allow(incomplete_features)]
|
||||||
#![feature(iterator_try_collect)]
|
#![feature(iterator_try_collect)]
|
||||||
#![feature(with_negative_coherence)]
|
#![feature(with_negative_coherence)]
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use crate::Module;
|
|||||||
fn create_module(lua: &mlua::Lua) -> mlua::Result<mlua::Table> {
|
fn create_module(lua: &mlua::Lua) -> mlua::Result<mlua::Table> {
|
||||||
let utils = lua.create_table()?;
|
let utils = lua.create_table()?;
|
||||||
|
|
||||||
utils.set(Timeout::type_name(), lua.create_proxy::<Timeout>()?)?;
|
utils.set("Timeout", lua.create_proxy::<Timeout>()?)?;
|
||||||
|
|
||||||
let get_hostname = lua.create_function(|_lua, ()| {
|
let get_hostname = lua.create_function(|_lua, ()| {
|
||||||
hostname::get()
|
hostname::get()
|
||||||
|
|||||||
@@ -1,337 +0,0 @@
|
|||||||
-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED
|
|
||||||
---@meta
|
|
||||||
|
|
||||||
local devices
|
|
||||||
|
|
||||||
---@class KasaOutletConfig
|
|
||||||
---@field identifier string
|
|
||||||
---@field ip string
|
|
||||||
local KasaOutletConfig
|
|
||||||
|
|
||||||
---@class KasaOutlet: DeviceInterface, OnOffInterface
|
|
||||||
local KasaOutlet
|
|
||||||
devices.KasaOutlet = {}
|
|
||||||
---@param config KasaOutletConfig
|
|
||||||
---@return KasaOutlet
|
|
||||||
function devices.KasaOutlet.new(config) end
|
|
||||||
|
|
||||||
---@class AirFilter: DeviceInterface, OnOffInterface
|
|
||||||
local AirFilter
|
|
||||||
devices.AirFilter = {}
|
|
||||||
---@param config AirFilterConfig
|
|
||||||
---@return AirFilter
|
|
||||||
function devices.AirFilter.new(config) end
|
|
||||||
|
|
||||||
---@class AirFilterConfig
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field url string
|
|
||||||
local AirFilterConfig
|
|
||||||
|
|
||||||
---@class Presence: DeviceInterface
|
|
||||||
local Presence
|
|
||||||
devices.Presence = {}
|
|
||||||
---@param config PresenceConfig
|
|
||||||
---@return Presence
|
|
||||||
function devices.Presence.new(config) end
|
|
||||||
---@async
|
|
||||||
---@return boolean
|
|
||||||
function Presence:overall_presence() end
|
|
||||||
|
|
||||||
---@class PresenceConfig
|
|
||||||
---@field topic string
|
|
||||||
---@field callback fun(_: Presence, _: boolean) | fun(_: Presence, _: boolean)[]?
|
|
||||||
---@field client AsyncClient
|
|
||||||
local PresenceConfig
|
|
||||||
|
|
||||||
---@class HueBridge: DeviceInterface
|
|
||||||
local HueBridge
|
|
||||||
devices.HueBridge = {}
|
|
||||||
---@param config HueBridgeConfig
|
|
||||||
---@return HueBridge
|
|
||||||
function devices.HueBridge.new(config) end
|
|
||||||
---@async
|
|
||||||
---@param flag Flag
|
|
||||||
---@param value boolean
|
|
||||||
function HueBridge:set_flag(flag, value) end
|
|
||||||
|
|
||||||
---@class FlagIDs
|
|
||||||
---@field presence integer
|
|
||||||
---@field darkness integer
|
|
||||||
local FlagIDs
|
|
||||||
|
|
||||||
---@class HueBridgeConfig
|
|
||||||
---@field identifier string
|
|
||||||
---@field ip string
|
|
||||||
---@field login string
|
|
||||||
---@field flags FlagIDs
|
|
||||||
local HueBridgeConfig
|
|
||||||
|
|
||||||
---@alias Flag
|
|
||||||
---| "presence"
|
|
||||||
---| "darkness"
|
|
||||||
|
|
||||||
---@class WasherConfig
|
|
||||||
---@field identifier string
|
|
||||||
---@field topic string
|
|
||||||
---@field threshold number
|
|
||||||
---@field done_callback fun(_: Washer) | fun(_: Washer)[]?
|
|
||||||
---@field client AsyncClient
|
|
||||||
local WasherConfig
|
|
||||||
|
|
||||||
---@class Washer: DeviceInterface
|
|
||||||
local Washer
|
|
||||||
devices.Washer = {}
|
|
||||||
---@param config WasherConfig
|
|
||||||
---@return Washer
|
|
||||||
function devices.Washer.new(config) end
|
|
||||||
|
|
||||||
---@class LightSensor: DeviceInterface
|
|
||||||
local LightSensor
|
|
||||||
devices.LightSensor = {}
|
|
||||||
---@param config LightSensorConfig
|
|
||||||
---@return LightSensor
|
|
||||||
function devices.LightSensor.new(config) end
|
|
||||||
|
|
||||||
---@class LightSensorConfig
|
|
||||||
---@field identifier string
|
|
||||||
---@field topic string
|
|
||||||
---@field min integer
|
|
||||||
---@field max integer
|
|
||||||
---@field callback fun(_: LightSensor, _: boolean) | fun(_: LightSensor, _: boolean)[]?
|
|
||||||
---@field client AsyncClient
|
|
||||||
local LightSensorConfig
|
|
||||||
|
|
||||||
---@class HueGroupConfig
|
|
||||||
---@field identifier string
|
|
||||||
---@field ip string
|
|
||||||
---@field login string
|
|
||||||
---@field group_id integer
|
|
||||||
---@field scene_id string
|
|
||||||
local HueGroupConfig
|
|
||||||
|
|
||||||
---@class HueGroup: DeviceInterface, OnOffInterface
|
|
||||||
local HueGroup
|
|
||||||
devices.HueGroup = {}
|
|
||||||
---@param config HueGroupConfig
|
|
||||||
---@return HueGroup
|
|
||||||
function devices.HueGroup.new(config) end
|
|
||||||
|
|
||||||
---@class IkeaRemote: DeviceInterface
|
|
||||||
local IkeaRemote
|
|
||||||
devices.IkeaRemote = {}
|
|
||||||
---@param config IkeaRemoteConfig
|
|
||||||
---@return IkeaRemote
|
|
||||||
function devices.IkeaRemote.new(config) end
|
|
||||||
|
|
||||||
---@class IkeaRemoteConfig
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field single_button boolean?
|
|
||||||
---@field topic string
|
|
||||||
---@field client AsyncClient
|
|
||||||
---@field callback fun(_: IkeaRemote, _: boolean) | fun(_: IkeaRemote, _: boolean)[]?
|
|
||||||
---@field battery_callback fun(_: IkeaRemote, _: number) | fun(_: IkeaRemote, _: number)[]?
|
|
||||||
local IkeaRemoteConfig
|
|
||||||
|
|
||||||
---@class WolConfig
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field topic string
|
|
||||||
---@field mac_address string
|
|
||||||
---@field broadcast_ip string?
|
|
||||||
---@field client AsyncClient
|
|
||||||
local WolConfig
|
|
||||||
|
|
||||||
---@class WakeOnLAN: DeviceInterface
|
|
||||||
local WakeOnLAN
|
|
||||||
devices.WakeOnLAN = {}
|
|
||||||
---@param config WolConfig
|
|
||||||
---@return WakeOnLAN
|
|
||||||
function devices.WakeOnLAN.new(config) end
|
|
||||||
|
|
||||||
---@class ConfigOutletOutletStateOnOff
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field topic string
|
|
||||||
---@field outlet_type OutletType?
|
|
||||||
---@field callback fun(_: OutletOnOff, _: OutletStateOnOff) | fun(_: OutletOnOff, _: OutletStateOnOff)[]?
|
|
||||||
---@field client AsyncClient
|
|
||||||
local ConfigOutletOutletStateOnOff
|
|
||||||
|
|
||||||
---@class OutletStatePower
|
|
||||||
---@field state boolean
|
|
||||||
---@field power number
|
|
||||||
local OutletStatePower
|
|
||||||
|
|
||||||
---@class ConfigOutletOutletStatePower
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field topic string
|
|
||||||
---@field outlet_type OutletType?
|
|
||||||
---@field callback fun(_: OutletPower, _: OutletStatePower) | fun(_: OutletPower, _: OutletStatePower)[]?
|
|
||||||
---@field client AsyncClient
|
|
||||||
local ConfigOutletOutletStatePower
|
|
||||||
|
|
||||||
---@alias OutletType
|
|
||||||
---| "Outlet"
|
|
||||||
---| "Kettle"
|
|
||||||
|
|
||||||
---@class OutletStateOnOff
|
|
||||||
---@field state boolean
|
|
||||||
local OutletStateOnOff
|
|
||||||
|
|
||||||
---@class OutletOnOff: DeviceInterface, OnOffInterface
|
|
||||||
local OutletOnOff
|
|
||||||
devices.OutletOnOff = {}
|
|
||||||
---@param config ConfigOutletOutletStateOnOff
|
|
||||||
---@return OutletOnOff
|
|
||||||
function devices.OutletOnOff.new(config) end
|
|
||||||
|
|
||||||
---@class OutletPower: DeviceInterface, OnOffInterface
|
|
||||||
local OutletPower
|
|
||||||
devices.OutletPower = {}
|
|
||||||
---@param config ConfigOutletOutletStatePower
|
|
||||||
---@return OutletPower
|
|
||||||
function devices.OutletPower.new(config) end
|
|
||||||
|
|
||||||
---@class ContactSensorConfig
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field topic string
|
|
||||||
---@field sensor_type SensorType?
|
|
||||||
---@field callback fun(_: ContactSensor, _: boolean) | fun(_: ContactSensor, _: boolean)[]?
|
|
||||||
---@field battery_callback fun(_: ContactSensor, _: number) | fun(_: ContactSensor, _: number)[]?
|
|
||||||
---@field client AsyncClient?
|
|
||||||
local ContactSensorConfig
|
|
||||||
|
|
||||||
---@alias SensorType
|
|
||||||
---| "Door"
|
|
||||||
---| "Drawer"
|
|
||||||
---| "Window"
|
|
||||||
|
|
||||||
---@class ContactSensor: DeviceInterface, OpenCloseInterface
|
|
||||||
local ContactSensor
|
|
||||||
devices.ContactSensor = {}
|
|
||||||
---@param config ContactSensorConfig
|
|
||||||
---@return ContactSensor
|
|
||||||
function devices.ContactSensor.new(config) end
|
|
||||||
|
|
||||||
---@class LightStateOnOff
|
|
||||||
---@field state boolean
|
|
||||||
local LightStateOnOff
|
|
||||||
|
|
||||||
---@class ConfigLightLightStateColorTemperature
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field topic string
|
|
||||||
---@field callback fun(_: LightColorTemperature, _: LightStateColorTemperature) | fun(_: LightColorTemperature, _: LightStateColorTemperature)[]?
|
|
||||||
---@field client AsyncClient?
|
|
||||||
local ConfigLightLightStateColorTemperature
|
|
||||||
|
|
||||||
---@class LightStateBrightness
|
|
||||||
---@field state boolean
|
|
||||||
---@field brightness number
|
|
||||||
local LightStateBrightness
|
|
||||||
|
|
||||||
---@class LightStateColorTemperature
|
|
||||||
---@field state boolean
|
|
||||||
---@field brightness number
|
|
||||||
---@field color_temp integer
|
|
||||||
local LightStateColorTemperature
|
|
||||||
|
|
||||||
---@class LightBrightness: DeviceInterface, OnOffInterface, BrightnessInterface
|
|
||||||
local LightBrightness
|
|
||||||
devices.LightBrightness = {}
|
|
||||||
---@param config ConfigLightLightStateBrightness
|
|
||||||
---@return LightBrightness
|
|
||||||
function devices.LightBrightness.new(config) end
|
|
||||||
|
|
||||||
---@class LightColorTemperature: DeviceInterface, OnOffInterface, BrightnessInterface, ColorSettingInterface
|
|
||||||
local LightColorTemperature
|
|
||||||
devices.LightColorTemperature = {}
|
|
||||||
---@param config ConfigLightLightStateColorTemperature
|
|
||||||
---@return LightColorTemperature
|
|
||||||
function devices.LightColorTemperature.new(config) end
|
|
||||||
|
|
||||||
---@class ConfigLightLightStateOnOff
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field topic string
|
|
||||||
---@field callback fun(_: LightOnOff, _: LightStateOnOff) | fun(_: LightOnOff, _: LightStateOnOff)[]?
|
|
||||||
---@field client AsyncClient?
|
|
||||||
local ConfigLightLightStateOnOff
|
|
||||||
|
|
||||||
---@class ConfigLightLightStateBrightness
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field topic string
|
|
||||||
---@field callback fun(_: LightBrightness, _: LightStateBrightness) | fun(_: LightBrightness, _: LightStateBrightness)[]?
|
|
||||||
---@field client AsyncClient?
|
|
||||||
local ConfigLightLightStateBrightness
|
|
||||||
|
|
||||||
---@class LightOnOff: DeviceInterface, OnOffInterface
|
|
||||||
local LightOnOff
|
|
||||||
devices.LightOnOff = {}
|
|
||||||
---@param config ConfigLightLightStateOnOff
|
|
||||||
---@return LightOnOff
|
|
||||||
function devices.LightOnOff.new(config) end
|
|
||||||
|
|
||||||
---@class Action
|
|
||||||
---@field action
|
|
||||||
---| "broadcast"
|
|
||||||
---@field extras table<string, string>?
|
|
||||||
---@field label string
|
|
||||||
---@field clear boolean?
|
|
||||||
local Action
|
|
||||||
|
|
||||||
---@class NtfyConfig
|
|
||||||
---@field url string?
|
|
||||||
---@field topic string
|
|
||||||
local NtfyConfig
|
|
||||||
|
|
||||||
---@class Notification
|
|
||||||
---@field title string
|
|
||||||
---@field message string?
|
|
||||||
---@field tags string[]?
|
|
||||||
---@field priority Priority?
|
|
||||||
---@field actions Action[]?
|
|
||||||
local Notification
|
|
||||||
|
|
||||||
---@alias Priority
|
|
||||||
---| "min"
|
|
||||||
---| "low"
|
|
||||||
---| "default"
|
|
||||||
---| "high"
|
|
||||||
---| "max"
|
|
||||||
|
|
||||||
---@class Ntfy: DeviceInterface
|
|
||||||
local Ntfy
|
|
||||||
devices.Ntfy = {}
|
|
||||||
---@param config NtfyConfig
|
|
||||||
---@return Ntfy
|
|
||||||
function devices.Ntfy.new(config) end
|
|
||||||
---@async
|
|
||||||
---@param notification Notification
|
|
||||||
function Ntfy:send_notification(notification) end
|
|
||||||
|
|
||||||
---@class HueSwitch: DeviceInterface
|
|
||||||
local HueSwitch
|
|
||||||
devices.HueSwitch = {}
|
|
||||||
---@param config HueSwitchConfig
|
|
||||||
---@return HueSwitch
|
|
||||||
function devices.HueSwitch.new(config) end
|
|
||||||
|
|
||||||
---@class HueSwitchConfig
|
|
||||||
---@field name string
|
|
||||||
---@field room string?
|
|
||||||
---@field topic string
|
|
||||||
---@field client AsyncClient
|
|
||||||
---@field left_callback fun(_: HueSwitch) | fun(_: HueSwitch)[]?
|
|
||||||
---@field right_callback fun(_: HueSwitch) | fun(_: HueSwitch)[]?
|
|
||||||
---@field left_hold_callback fun(_: HueSwitch) | fun(_: HueSwitch)[]?
|
|
||||||
---@field right_hold_callback fun(_: HueSwitch) | fun(_: HueSwitch)[]?
|
|
||||||
---@field battery_callback fun(_: HueSwitch, _: number) | fun(_: HueSwitch, _: number)[]?
|
|
||||||
local HueSwitchConfig
|
|
||||||
|
|
||||||
return devices
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED
|
|
||||||
---@meta
|
|
||||||
|
|
||||||
local mqtt
|
|
||||||
|
|
||||||
---@class MqttConfig
|
|
||||||
---@field host string
|
|
||||||
---@field port integer
|
|
||||||
---@field client_name string
|
|
||||||
---@field username string
|
|
||||||
---@field password string
|
|
||||||
---@field tls boolean
|
|
||||||
local MqttConfig
|
|
||||||
|
|
||||||
---@class AsyncClient
|
|
||||||
local AsyncClient
|
|
||||||
---@async
|
|
||||||
---@param topic string
|
|
||||||
---@param message table?
|
|
||||||
function AsyncClient:send_message(topic, message) end
|
|
||||||
mqtt.AsyncClient = {}
|
|
||||||
---@param device_manager DeviceManager
|
|
||||||
---@param config MqttConfig
|
|
||||||
---@return AsyncClient
|
|
||||||
function mqtt.new(device_manager, config) end
|
|
||||||
|
|
||||||
return mqtt
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
---@meta
|
|
||||||
|
|
||||||
---@type table<string, string?>
|
|
||||||
local secrets
|
|
||||||
|
|
||||||
return secrets
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED
|
|
||||||
---@meta
|
|
||||||
|
|
||||||
local utils
|
|
||||||
|
|
||||||
---@class Timeout
|
|
||||||
local Timeout
|
|
||||||
---@async
|
|
||||||
---@param timeout number
|
|
||||||
---@param callback fun() | fun()[]
|
|
||||||
function Timeout:start(timeout, callback) end
|
|
||||||
---@async
|
|
||||||
function Timeout:cancel() end
|
|
||||||
---@async
|
|
||||||
---@return boolean
|
|
||||||
function Timeout:is_waiting() end
|
|
||||||
utils.Timeout = {}
|
|
||||||
---@return Timeout
|
|
||||||
function utils.Timeout.new() end
|
|
||||||
|
|
||||||
---@return string
|
|
||||||
function utils.get_hostname() end
|
|
||||||
|
|
||||||
---@return integer
|
|
||||||
function utils.get_epoch() end
|
|
||||||
|
|
||||||
return utils
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
---@meta
|
|
||||||
|
|
||||||
---@type table<string, string?>
|
|
||||||
local variables
|
|
||||||
|
|
||||||
return variables
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
use std::fs::{self, File};
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
use automation_lib::Module;
|
|
||||||
use tracing::{info, warn};
|
|
||||||
|
|
||||||
extern crate automation_devices;
|
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
|
||||||
tracing_subscriber::fmt::init();
|
|
||||||
|
|
||||||
let definitions_directory =
|
|
||||||
std::path::Path::new(std::env!("CARGO_MANIFEST_DIR")).join("definitions");
|
|
||||||
fs::create_dir_all(&definitions_directory)?;
|
|
||||||
|
|
||||||
for module in inventory::iter::<Module> {
|
|
||||||
if let Some(definitions) = module.definitions() {
|
|
||||||
info!(name = module.get_name(), "Generating definitions");
|
|
||||||
|
|
||||||
let filename = format!("{}.lua", module.get_name());
|
|
||||||
let mut file = File::create(definitions_directory.join(filename))?;
|
|
||||||
|
|
||||||
file.write_all(b"-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED\n")?;
|
|
||||||
file.write_all(definitions.as_bytes())?;
|
|
||||||
file.write_all(b"\n")?;
|
|
||||||
} else {
|
|
||||||
warn!(name = module.get_name(), "No definitions");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
// automation_devices::generate_definitions()
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user