From 7686d0af884170c31fe6548ca7af45c846058bc5 Mon Sep 17 00:00:00 2001 From: Finn Date: Fri, 22 Nov 2024 23:01:26 -0800 Subject: [PATCH] fix disabling codes --- httpserver/lock.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/httpserver/lock.go b/httpserver/lock.go index 3c3f45f..736aac7 100644 --- a/httpserver/lock.go +++ b/httpserver/lock.go @@ -131,18 +131,21 @@ func lockCodeEditHandler(c echo.Context) error { return fmt.Errorf("error pushing enabled state to lock %s (ZWaveDeviceID=%d ID=%d): %v", lock.Name, lock.ZwaveDeviceID, lock.ID, err) } - newCode := c.FormValue("code") - err = zwaveClient.SetNodeValue(ctx, int(lock.ZwaveDeviceID), zwavejs.NodeValue{ - CCVersion: 1, - CommandClassName: zwavejs.CommandClassNameUserCode, - CommandClass: zwavejs.CommandClassUserCode, - Endpoint: 0, - Property: zwavejs.AnyType{Type: zwavejs.AnyTypeString, String: string(zwavejs.PropertyUserCode)}, - PropertyName: zwavejs.AnyType{Type: zwavejs.AnyTypeString, String: string(zwavejs.PropertyUserCode)}, - PropertyKey: zwavejs.AnyType{Type: zwavejs.AnyTypeInt, Int: int(slot)}, - }, zwavejs.AnyType{Type: zwavejs.AnyTypeString, String: newCode}) - if err != nil { - return fmt.Errorf("error pushing code to lock %s (ZWaveDeviceID=%d ID=%d): %v", lock.Name, lock.ZwaveDeviceID, lock.ID, err) + newCode := "0000" + if enabled { + newCode := c.FormValue("code") + err = zwaveClient.SetNodeValue(ctx, int(lock.ZwaveDeviceID), zwavejs.NodeValue{ + CCVersion: 1, + CommandClassName: zwavejs.CommandClassNameUserCode, + CommandClass: zwavejs.CommandClassUserCode, + Endpoint: 0, + Property: zwavejs.AnyType{Type: zwavejs.AnyTypeString, String: string(zwavejs.PropertyUserCode)}, + PropertyName: zwavejs.AnyType{Type: zwavejs.AnyTypeString, String: string(zwavejs.PropertyUserCode)}, + PropertyKey: zwavejs.AnyType{Type: zwavejs.AnyTypeInt, Int: int(slot)}, + }, zwavejs.AnyType{Type: zwavejs.AnyTypeString, String: newCode}) + if err != nil { + return fmt.Errorf("error pushing code to lock %s (ZWaveDeviceID=%d ID=%d): %v", lock.Name, lock.ZwaveDeviceID, lock.ID, err) + } } err = queries.UpdateCodeSlot(ctx, db.UpdateCodeSlotParams{