fix storing enabled state
This commit is contained in:
parent
7686d0af88
commit
2907ceef3d
3 changed files with 14 additions and 9 deletions
|
@ -1,9 +1,10 @@
|
||||||
{{ template "header.html" . }}
|
{{ template "header.html" . }}
|
||||||
<header>{{ if eq .Data.Name "" }}Lock #{{ .Data.ID }}{{ else }}{{ .Data.Name }}{{ end }}</header>
|
<header>{{ if eq .Data.lock.Name "" }}Lock #{{ .Data.lock.ID }}{{ else }}{{ .Data.lock.Name }}{{ end }} Slot #{{ .Data.code.Slot }}</header>
|
||||||
|
<br />
|
||||||
<form method="post">
|
<form method="post">
|
||||||
Code: <input type="text" name="code" value="{{ .Data.Code }}" /><br />
|
Code: <input type="text" name="code" value="{{ .Data.code.Code }}" /><br />
|
||||||
Name: <input type="text" name="name" value="{{ .Data.Name }}" /><br />
|
Name: <input type="text" name="name" value="{{ .Data.code.Name }}" /><br />
|
||||||
Enabled: <input type="checkbox" name="enabled" {{ if .Data.Enabled }}checked{{ end }} /><br />
|
Enabled: <input type="checkbox" name="enabled" {{ if .Data.code.Enabled }}checked{{ end }} /><br />
|
||||||
<br />
|
<br />
|
||||||
<input type="submit" value="save" />
|
<input type="submit" value="save" />
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{{ template "header.html" . }}
|
{{ template "header.html" . }}
|
||||||
<header>Rename {{ if eq .Data.Name "" }}Lock #{{ .Data.ID }}{{ else }}{{ .Data.Name }}{{ end }}</header>
|
<header>Rename {{ if eq .Data.Name "" }}Lock #{{ .Data.ID }}{{ else }}{{ .Data.Name }}{{ end }}</header>
|
||||||
|
<br />
|
||||||
<form method="post">
|
<form method="post">
|
||||||
Name: <input type="text" name="name" value="{{ .Data.Name }}" /><br />
|
Name: <input type="text" name="name" value="{{ .Data.Name }}" /><br />
|
||||||
<input type="submit" value="save" />
|
<input type="submit" value="save" />
|
||||||
|
|
|
@ -102,15 +102,18 @@ func lockCodeEditHandler(c echo.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Request().Method == http.MethodGet {
|
|
||||||
return c.Render(http.StatusFound, "lock-code-edit.html", code)
|
|
||||||
}
|
|
||||||
|
|
||||||
lock, err := queries.GetLock(ctx, lockID)
|
lock, err := queries.GetLock(ctx, lockID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Request().Method == http.MethodGet {
|
||||||
|
return c.Render(http.StatusFound, "lock-code-edit.html", map[string]interface{}{
|
||||||
|
"lock": lock,
|
||||||
|
"code": code,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
zwaveClient := c.Get(contextKeyZWaveClient).(*zwavejs.Client)
|
zwaveClient := c.Get(contextKeyZWaveClient).(*zwavejs.Client)
|
||||||
|
|
||||||
enabled := c.FormValue("enabled") == "on"
|
enabled := c.FormValue("enabled") == "on"
|
||||||
|
@ -133,7 +136,7 @@ func lockCodeEditHandler(c echo.Context) error {
|
||||||
|
|
||||||
newCode := "0000"
|
newCode := "0000"
|
||||||
if enabled {
|
if enabled {
|
||||||
newCode := c.FormValue("code")
|
newCode = c.FormValue("code")
|
||||||
err = zwaveClient.SetNodeValue(ctx, int(lock.ZwaveDeviceID), zwavejs.NodeValue{
|
err = zwaveClient.SetNodeValue(ctx, int(lock.ZwaveDeviceID), zwavejs.NodeValue{
|
||||||
CCVersion: 1,
|
CCVersion: 1,
|
||||||
CommandClassName: zwavejs.CommandClassNameUserCode,
|
CommandClassName: zwavejs.CommandClassNameUserCode,
|
||||||
|
|
Loading…
Reference in a new issue