fix: Frontdoor presence is the wrong way around
All checks were successful
Build and deploy / build (push) Successful in 14m48s
Build and deploy / Deploy container (push) Successful in 1m59s

This commit is contained in:
2025-10-30 20:56:49 +01:00
parent 44f2c57819
commit f3de8e36ea

View File

@@ -59,28 +59,23 @@ function module.setup(mqtt_client)
}) })
hallway_automation.set_trash(trash) hallway_automation.set_trash(trash)
---@param duration number
---@return fun(_, open: boolean)
local function frontdoor_presence(duration)
local timeout = utils.Timeout.new() local timeout = utils.Timeout.new()
local function frontdoor_presence(_, open)
return function(_, open)
if open then if open then
timeout:cancel() timeout:cancel()
if presence.overall_presence() then if not presence.overall_presence() then
mqtt_client:send_message(helper.mqtt_automation("presence/contact/frontdoor"), { mqtt_client:send_message(helper.mqtt_automation("presence/contact/frontdoor"), {
state = true, state = true,
updated = utils.get_epoch(), updated = utils.get_epoch(),
}) })
end end
else else
timeout:start(duration, function() timeout:start(debug.debug_mode and 10 or 15 * 60, function()
mqtt_client:send_message(helper.mqtt_automation("presence/contact/frontdoor"), nil) mqtt_client:send_message(helper.mqtt_automation("presence/contact/frontdoor"), nil)
end) end)
end end
end end
end
local frontdoor = devices.ContactSensor.new({ local frontdoor = devices.ContactSensor.new({
name = "Frontdoor", name = "Frontdoor",
@@ -89,7 +84,7 @@ function module.setup(mqtt_client)
topic = helper.mqtt_z2m("hallway/frontdoor"), topic = helper.mqtt_z2m("hallway/frontdoor"),
client = mqtt_client, client = mqtt_client,
callback = { callback = {
frontdoor_presence(debug.debug_mode and 10 or 15 * 60), frontdoor_presence,
hallway_automation.door_callback, hallway_automation.door_callback,
}, },
battery_callback = battery.callback, battery_callback = battery.callback,