diff --git a/.forgejo/workflows/build-and-release.yaml b/.forgejo/workflows/build-and-release.yaml index 3351bbe..6488a39 100644 --- a/.forgejo/workflows/build-and-release.yaml +++ b/.forgejo/workflows/build-and-release.yaml @@ -7,7 +7,7 @@ jobs: steps: - run: apk add --no-cache nodejs git - name: login to container registry - run: echo "${{ secrets.PACKAGE_PUBLISH_TOKEN }}" | docker login --username finn --password-stdin git.janky.solutions + run: echo "${{ secrets.PACKAGE_PUBLISH_TOKEN }}" | docker login --username ${{ secrets.PACKAGE_PUBLISH_USER }} --password-stdin git.janky.solutions - name: gather metadata for container image tags uses: https://github.com/docker/metadata-action@v5 id: meta @@ -20,7 +20,7 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: true + push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }} build-args: | VERSION_STRING=${{ env.GITHUB_REF_NAME }} - name: update hassio-addons diff --git a/Containerfile b/Containerfile index 67272bd..1ac589c 100644 --- a/Containerfile +++ b/Containerfile @@ -19,7 +19,7 @@ RUN apk add --no-cache go ADD . /go/lockserver WORKDIR /go/lockserver ARG VERSION_STRING -RUN CGO_ENABLED=0 go build -ldflags "-X git.devhack.net/devhack/member-services/config.Version=${VERSION_STRING}" ./cmd/lockserver +RUN CGO_ENABLED=0 go build -ldflags "-X git.janky.solutions/finn/lockserver/config.Version=${VERSION_STRING}" ./cmd/lockserver FROM scratch COPY --from=build /go/lockserver/lockserver /lockserver diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f62cb6 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# lockserver + +_better Z-Wave Lock management for Home Assistant_ + +## Status + +This is a work in progress. I have some ideas of where I want it to go, but I'm mostly experimenting with my own needs. + +## Install + +To add to Home Assistant, add my hassio-addons repo by clicking the button below, then search for and install the "LockServer" addon. + +[![Add to Home Assistant.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgit.janky.solutions%2Ffinn%2Fhassio-addons) + + +## Usage + +When you open the addon's web UI, it will show a list of Z-Wave locks. Clicking a lock shows all codes slots for that lock. Clicking edit on each slot allows changing the code, changing the name, enabling or disabling the slot, and seeing a log of recent uses of that code. diff --git a/config/version.go b/config/version.go index d611b7c..c718d59 100644 --- a/config/version.go +++ b/config/version.go @@ -26,5 +26,9 @@ func init() { break } } + + if Version == "" { + Version = "development" + } } } diff --git a/db/lock_log.sql.go b/db/lock_log.sql.go index 5507db2..b6c4385 100644 --- a/db/lock_log.sql.go +++ b/db/lock_log.sql.go @@ -97,7 +97,7 @@ func (q *Queries) GetLogForLock(ctx context.Context, lock int64) ([]LockLog, err } const getLogForSlot = `-- name: GetLogForSlot :many -SELECT lock, timestamp, state, code, issued_code FROM lock_log WHERE lock = ? AND code = ? ORDER BY timestamp DESC +SELECT lock, timestamp, state, code, issued_code FROM lock_log WHERE lock = ? AND code = ? ORDER BY timestamp DESC LIMIT 100 ` type GetLogForSlotParams struct { diff --git a/db/queries/lock_log.sql b/db/queries/lock_log.sql index 6fda69a..0106b03 100644 --- a/db/queries/lock_log.sql +++ b/db/queries/lock_log.sql @@ -5,7 +5,7 @@ INSERT INTO lock_log (lock, state, code) VALUES (?, ?, ?); SELECT * FROM lock_log WHERE lock = ? ORDER BY timestamp DESC; -- name: GetLogForSlot :many -SELECT * FROM lock_log WHERE lock = ? AND code = ? ORDER BY timestamp DESC; +SELECT * FROM lock_log WHERE lock = ? AND code = ? ORDER BY timestamp DESC LIMIT 100; -- name: GetLastLogForSlot :many SELECT * FROM lock_log WHERE lock = ? AND code = ? ORDER BY timestamp DESC LIMIT 1; diff --git a/frontend/frontend.go b/frontend/frontend.go index 526381c..8aa240d 100644 --- a/frontend/frontend.go +++ b/frontend/frontend.go @@ -2,7 +2,6 @@ package frontend import ( "embed" - "fmt" "html/template" "io/fs" "time" @@ -20,7 +19,7 @@ var ( Templates *template.Template funcs = template.FuncMap{ - "version": func() string { return fmt.Sprintf("better-zwave-locks %s", config.Version) }, + "version": func() string { return config.Version }, "time_since": func(t time.Time) string { return time.Since(t).Round(time.Second).String() }, } ) diff --git a/frontend/header.html b/frontend/header.html index 84d62b3..d5fcf75 100644 --- a/frontend/header.html +++ b/frontend/header.html @@ -5,7 +5,7 @@ Better Z-Wave Locks for Home Assistant - + diff --git a/frontend/index.html b/frontend/index.html index 8325a1a..725dec7 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,28 +1,11 @@ {{ template "header.html" . }}

Better Z-Wave Locks

-

-
locks
- + + {{ range .Locks }} + +

{{ if eq .Name "" }}Lock #{{ .ZwaveDeviceID }}{{ else }}{{ .Name }}{{ end }}

+
+ {{ end }} +
{{ template "footer.html" }} diff --git a/frontend/lock-code-edit.html b/frontend/lock-code-edit.html index e996ff3..12750fa 100644 --- a/frontend/lock-code-edit.html +++ b/frontend/lock-code-edit.html @@ -2,7 +2,7 @@
{{ if eq .Data.lock.Name "" }}Lock #{{ .Data.lock.ID }}{{ else }}{{ .Data.lock.Name }}{{ end }} Slot #{{ .Data.code.Slot }}

- Code:
+ Code: 🔄
Name:
Enabled:

@@ -15,4 +15,14 @@
  • {{ $entry.State }} ({{ $entry.Timestamp | time_since }} ago)
  • {{ end }} + + {{ template "footer.html" }} diff --git a/frontend/lock.html b/frontend/lock.html index 50a9dcd..38b708b 100644 --- a/frontend/lock.html +++ b/frontend/lock.html @@ -2,24 +2,18 @@
    {{ if eq .Data.lock.Name "" }}Lock #{{ .Data.lock.ID }}{{ else }}{{ .Data.lock.Name }}{{ end }}
    [ rename ]

    - - - - - - - - + + + Name + Code + {{ range $_, $code := .Data.codes }} - - - - - - - + + {{ $code.Name }} + {{ $code.Code }} + {{ end }} -
    SlotNameCodeEnabled?Actions
    {{ $code.Slot }}{{ $code.Name }}{{ $code.Code }}{{ if $code.Enabled }}enabled{{ else }}disabled{{ end }}[ edit ]
    +

    diff --git a/frontend/static/main.css b/frontend/static/main.css index dc46de5..a00ed38 100644 --- a/frontend/static/main.css +++ b/frontend/static/main.css @@ -16,6 +16,8 @@ a { flex-direction: column; row-gap: 1em; padding: 1em; + margin: auto; + max-width: 1000px; } #main { @@ -28,9 +30,24 @@ header { } .code-enabled { - background-color: #0a0; + background-color: #050; } .table { width: 100%; + display: flex; + flex-direction: column; +} + +.table-row { + border-bottom: solid #999 1px; + /* background-color: #333; */ + height: 3em; + display: flex; + flex-direction: row; + justify-content: space-around; +} + +.table-row:first { + border-top: solid #999 1px; } diff --git a/httpserver/server.go b/httpserver/server.go index f615e95..6c5e004 100644 --- a/httpserver/server.go +++ b/httpserver/server.go @@ -28,7 +28,7 @@ func ListenAndServe(zwaveClient *zwavejs.Client) { server.Use(accessLogMiddleware) server.RouteNotFound("/*", tmpl("404.html")) - server.StaticFS("/static", frontend.Static) + server.StaticFS("/static-"+config.Version, frontend.Static) server.GET("/", indexHandler) server.GET("/locks/:lock", lockHandler) server.GET("/locks/:lock/edit", lockEditHandler)