Compare commits
No commits in common. "68684d94104fdf15ae91f556cc1a6ae23eed381d" and "47d509cec18e862beb977d2c779899c17ba8102f" have entirely different histories.
68684d9410
...
47d509cec1
3056
Cargo.lock
generated
3056
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
|
@ -64,6 +64,7 @@ tokio-util = { version = "0.7.11", features = ["full"] }
|
|||
tracing-subscriber = "0.3.16"
|
||||
uuid = "1.8.0"
|
||||
wakey = "0.3.0"
|
||||
zigbee2mqtt-types = { version = "0.4.0", features = ["debug", "philips"] }
|
||||
air_filter_types = { git = "https://git.huizinga.dev/Dreaded_X/airfilter", tag = "v0.4.4" }
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -19,6 +19,7 @@ impls = { workspace = true }
|
|||
serde = { workspace = true }
|
||||
reqwest = { workspace = true } # Use rustls, since the other packages also use rustls
|
||||
anyhow = { workspace = true }
|
||||
zigbee2mqtt-types = { workspace = true }
|
||||
axum = { workspace = true }
|
||||
bytes = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
|
|
@ -6,8 +6,8 @@ use automation_lib::event::OnMqtt;
|
|||
use automation_lib::mqtt::WrappedAsyncClient;
|
||||
use automation_macro::LuaDeviceConfig;
|
||||
use rumqttc::{matches, Publish};
|
||||
use serde::Deserialize;
|
||||
use tracing::{debug, trace, warn};
|
||||
use zigbee2mqtt_types::philips::{Zigbee929003017102, Zigbee929003017102Action};
|
||||
|
||||
#[derive(Debug, Clone, LuaDeviceConfig)]
|
||||
pub struct Config {
|
||||
|
@ -25,30 +25,6 @@ pub struct Config {
|
|||
|
||||
#[device_config(from_lua, default)]
|
||||
pub right_callback: ActionCallback<HueSwitch, ()>,
|
||||
|
||||
#[device_config(from_lua, default)]
|
||||
pub left_hold_callback: ActionCallback<HueSwitch, ()>,
|
||||
|
||||
#[device_config(from_lua, default)]
|
||||
pub right_hold_callback: ActionCallback<HueSwitch, ()>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum Action {
|
||||
LeftPress,
|
||||
LeftPressRelease,
|
||||
LeftHold,
|
||||
LeftHoldRelease,
|
||||
RightPress,
|
||||
RightPressRelease,
|
||||
RightHold,
|
||||
RightHoldRelease,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
struct State {
|
||||
action: Action,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -84,7 +60,7 @@ impl OnMqtt for HueSwitch {
|
|||
async fn on_mqtt(&self, message: Publish) {
|
||||
// Check if the message is from the device itself or from a remote
|
||||
if matches(&message.topic, &self.config.mqtt.topic) {
|
||||
let action = match serde_json::from_slice::<State>(&message.payload) {
|
||||
let action = match serde_json::from_slice::<Zigbee929003017102>(&message.payload) {
|
||||
Ok(message) => message.action,
|
||||
Err(err) => {
|
||||
warn!(id = Device::get_id(self), "Failed to parse message: {err}");
|
||||
|
@ -94,10 +70,12 @@ impl OnMqtt for HueSwitch {
|
|||
debug!(id = Device::get_id(self), "Remote action = {:?}", action);
|
||||
|
||||
match action {
|
||||
Action::LeftPressRelease => self.config.left_callback.call(self, &()).await,
|
||||
Action::LeftHold => self.config.left_hold_callback.call(self, &()).await,
|
||||
Action::RightPressRelease => self.config.right_callback.call(self, &()).await,
|
||||
Action::RightHold => self.config.right_hold_callback.call(self, &()).await,
|
||||
Zigbee929003017102Action::LeftPress => {
|
||||
self.config.left_callback.call(self, &()).await
|
||||
}
|
||||
Zigbee929003017102Action::RightPress => {
|
||||
self.config.right_callback.call(self, &()).await
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
41
config.lua
41
config.lua
|
@ -59,47 +59,6 @@ automation.device_manager:add(HueBridge.new({
|
|||
},
|
||||
}))
|
||||
|
||||
local kitchen_lights = HueGroup.new({
|
||||
identifier = "kitchen_lights",
|
||||
ip = hue_ip,
|
||||
login = hue_token,
|
||||
group_id = 7,
|
||||
scene_id = "7MJLG27RzeRAEVJ",
|
||||
})
|
||||
automation.device_manager:add(kitchen_lights)
|
||||
local living_lights = HueGroup.new({
|
||||
identifier = "living_lights",
|
||||
ip = hue_ip,
|
||||
login = hue_token,
|
||||
group_id = 1,
|
||||
scene_id = "SNZw7jUhQ3cXSjkj",
|
||||
})
|
||||
automation.device_manager:add(living_lights)
|
||||
local living_lights_relax = HueGroup.new({
|
||||
identifier = "living_lights",
|
||||
ip = hue_ip,
|
||||
login = hue_token,
|
||||
group_id = 1,
|
||||
scene_id = "eRJ3fvGHCcb6yNw",
|
||||
})
|
||||
automation.device_manager:add(living_lights_relax)
|
||||
|
||||
automation.device_manager:add(HueSwitch.new({
|
||||
name = "Switch",
|
||||
room = "Living",
|
||||
client = mqtt_client,
|
||||
topic = mqtt_z2m("living/switch"),
|
||||
left_callback = function()
|
||||
kitchen_lights:set_on(not kitchen_lights:on())
|
||||
end,
|
||||
right_callback = function()
|
||||
living_lights:set_on(not living_lights:on())
|
||||
end,
|
||||
right_hold_callback = function()
|
||||
living_lights_relax:set_on(true)
|
||||
end,
|
||||
}))
|
||||
|
||||
automation.device_manager:add(LightSensor.new({
|
||||
identifier = "living_light_sensor",
|
||||
topic = mqtt_z2m("living/light"),
|
||||
|
|
Loading…
Reference in New Issue
Block a user