Compare commits

...

9 commits
v0.0.4 ... main

Author SHA1 Message Date
2f80b5db95
go mod tidy
All checks were successful
Build Docker image / build (push) Successful in 1m18s
Build Golang packages / release (push) Has been skipped
2024-08-14 23:19:54 +02:00
bd66af32fa
Update Go 1.22 -> 1.23
All checks were successful
Build Docker image / build (push) Successful in 1m16s
Build Golang packages / release (push) Successful in 2m8s
2024-08-14 19:32:31 +02:00
f2b74acfe9
Go dependency upgrade
All checks were successful
Build Golang packages / release (push) Has been skipped
Build Docker image / build (push) Successful in 2m15s
2024-08-10 23:45:05 +02:00
2e2205d938
Add ARG TARGETOS TARGETARCH to fix multi-platform builds. 2024-08-10 23:44:45 +02:00
022ed0e03e
Add TODOs 2024-08-10 23:44:13 +02:00
95e10766f0
ESPHome example add voltage sags and swells processing.
All checks were successful
Build Docker image / build (push) Successful in 1m16s
Build Golang packages / release (push) Has been skipped
2024-07-28 16:12:34 +02:00
21c1e08d79
Add .gitignore for esphome. 2024-07-28 14:08:49 +02:00
07986ef0b4
Upgrade Go dependencies.
All checks were successful
Build Docker image / build (push) Successful in 1m3s
Build Golang packages / release (push) Has been skipped
2024-07-26 22:38:33 +02:00
39b231b780
Small fix: migration funcs don't have to be exported.
All checks were successful
Build Docker image / build (push) Successful in 1m6s
Build Golang packages / release (push) Has been skipped
2024-07-26 22:29:05 +02:00
6 changed files with 58 additions and 23 deletions

View file

@ -1,5 +1,5 @@
# Use buildx for multi-architecture support # Use buildx for multi-architecture support
FROM --platform=${BUILDPLATFORM} golang:1.22 AS builder FROM --platform=${BUILDPLATFORM} golang:1.23 AS builder
WORKDIR /app WORKDIR /app
@ -11,6 +11,9 @@ RUN go mod download
COPY . . COPY . .
# Build the application for the specified target architecture # Build the application for the specified target architecture
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
# Declare TARGETOS and TARGETARCH in the local scope so they can be used in the build stage.
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -o p1-logger . RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -o p1-logger .
# Create a minimal runtime image # Create a minimal runtime image

5
esphome/.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
# Gitignore settings for ESPHome
# This is an example and may include too much for your use-case.
# You can modify this file to suit your needs.
/.esphome/
/secrets.yaml

View file

@ -177,6 +177,30 @@ sensor:
name: "Long Electricity Failures" name: "Long Electricity Failures"
icon: mdi:alert icon: mdi:alert
id: electricity_long_failures id: electricity_long_failures
electricity_sags_l1:
name: "Voltage sags L1"
icon: mdi:alert
id: electricity_sags_l1
electricity_sags_l2:
name: "Voltage sags L1"
icon: mdi:alert
id: electricity_sags_l2
electricity_sags_l3:
name: "Voltage sags L1"
icon: mdi:alert
id: electricity_sags_l3
electricity_swells_l1:
name: "Voltage swells L1"
icon: mdi:alert
id: electricity_swells_l1
electricity_swells_l2:
name: "Voltage swells L1"
icon: mdi:alert
id: electricity_swells_l2
electricity_swells_l3:
name: "Voltage swells L1"
icon: mdi:alert
id: electricity_swells_l3
voltage_l1: voltage_l1:
name: "Voltage Phase 1" name: "Voltage Phase 1"
id: voltage_l1 id: voltage_l1

12
go.mod
View file

@ -1,22 +1,22 @@
module git.hollander.online/energy/p1-logger module git.hollander.online/energy/p1-logger
go 1.22 go 1.23
require ( require (
github.com/eclipse/paho.mqtt.golang v1.4.3 github.com/eclipse/paho.mqtt.golang v1.5.0
github.com/lib/pq v1.10.9 github.com/lib/pq v1.10.9
github.com/pressly/goose/v3 v3.21.1 github.com/pressly/goose/v3 v3.21.1
) )
require ( require (
github.com/mfridman/interpolate v0.0.2 // indirect github.com/mfridman/interpolate v0.0.2 // indirect
github.com/sethvargo/go-retry v0.2.4 // indirect github.com/sethvargo/go-retry v0.3.0 // indirect
go.uber.org/multierr v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect
) )
require ( require (
github.com/gorilla/websocket v1.5.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
golang.org/x/net v0.23.0 // indirect golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.7.0 // indirect golang.org/x/sync v0.8.0 // indirect
) )

24
go.sum
View file

@ -2,12 +2,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik= github.com/eclipse/paho.mqtt.golang v1.5.0 h1:EH+bUVJNgttidWFkLLVKaQPGmkTUfQQqjOsyvMGvD6o=
github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE= github.com/eclipse/paho.mqtt.golang v1.5.0/go.mod h1:du/2qNQVqJf/Sqs4MEL77kR8QTqANF7XU7Fk0aOTAgk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
@ -26,18 +26,18 @@ github.com/pressly/goose/v3 v3.21.1 h1:5SSAKKWej8LVVzNLuT6KIvP1eFDuPvxa+B6H0w78b
github.com/pressly/goose/v3 v3.21.1/go.mod h1:sqthmzV8PitchEkjecFJII//l43dLOCzfWh8pHEe+vE= github.com/pressly/goose/v3 v3.21.1/go.mod h1:sqthmzV8PitchEkjecFJII//l43dLOCzfWh8pHEe+vE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/sethvargo/go-retry v0.2.4 h1:T+jHEQy/zKJf5s95UkguisicE0zuF9y7+/vgz08Ocec= github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
github.com/sethvargo/go-retry v0.2.4/go.mod h1:1afjQuvh7s4gflMObvjLPaWgluLLyhA1wmVZ6KLpICw= github.com/sethvargo/go-retry v0.3.0/go.mod h1:mNX17F0C/HguQMyMyJxcnU471gOZGxCLyYaFyAZraas=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI= modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=

11
main.go
View file

@ -1,3 +1,6 @@
// TODO: Process p1/online status.
// TODO: Add health check endpoint.
// TODO: Add multiple P1 monitoring capabilities
package main package main
import ( import (
@ -558,7 +561,7 @@ func connectToPostgreSQL(pgConnStr string) error {
} }
// Perform DB migrations // Perform DB migrations
err = MigrateFS(db, migrations.FS, ".") err = migrateFS(db, migrations.FS, ".")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -577,7 +580,7 @@ func connectToPostgreSQL(pgConnStr string) error {
return nil return nil
} }
func Migrate(db *sql.DB, dir string) error { func migrate(db *sql.DB, dir string) error {
err := goose.SetDialect("postgres") err := goose.SetDialect("postgres")
if err != nil { if err != nil {
return fmt.Errorf("migrate: %w", err) return fmt.Errorf("migrate: %w", err)
@ -590,7 +593,7 @@ func Migrate(db *sql.DB, dir string) error {
} }
func MigrateFS(db *sql.DB, migrationFS fs.FS, dir string) error { func migrateFS(db *sql.DB, migrationFS fs.FS, dir string) error {
// In case the dir is an empty string, they probably meant the current directory and goose wants a period for that. // In case the dir is an empty string, they probably meant the current directory and goose wants a period for that.
if dir == "" { if dir == "" {
dir = "." dir = "."
@ -600,5 +603,5 @@ func MigrateFS(db *sql.DB, migrationFS fs.FS, dir string) error {
// Ensure that we remove the FS on the off chance some other part of our app uses goose for migrations and doesn't want to use our FS. // Ensure that we remove the FS on the off chance some other part of our app uses goose for migrations and doesn't want to use our FS.
goose.SetBaseFS(nil) goose.SetBaseFS(nil)
}() }()
return Migrate(db, dir) return migrate(db, dir)
} }