chore: add hems-pro platform (#25835)
This commit is contained in:
parent
d44bc7f8fc
commit
4d53782b6c
7 changed files with 70 additions and 6 deletions
2
go.mod
2
go.mod
|
|
@ -25,6 +25,7 @@ require (
|
|||
github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
|
||||
github.com/coder/websocket v1.8.14
|
||||
github.com/coreos/go-oidc/v3 v3.17.0
|
||||
github.com/d2r2/go-i2c v0.0.0-20191123181816-73a8a799d6bc
|
||||
github.com/denisbrodbeck/machineid v1.0.1
|
||||
github.com/dylanmei/iso8601 v0.1.0
|
||||
github.com/eclipse/paho.mqtt.golang v1.5.1
|
||||
|
|
@ -145,6 +146,7 @@ require (
|
|||
github.com/creack/goselect v0.1.2 // indirect
|
||||
github.com/cronokirby/saferith v0.33.0 // indirect
|
||||
github.com/cstockton/go-conv v1.0.0 // indirect
|
||||
github.com/d2r2/go-logger v0.0.0-20210606094344-60e9d1233e22 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/dmarkham/enumer v1.6.1 // indirect
|
||||
github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0 // indirect
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -148,6 +148,10 @@ github.com/cronokirby/saferith v0.33.0 h1:TgoQlfsD4LIwx71+ChfRcIpjkw+RPOapDEVxa+
|
|||
github.com/cronokirby/saferith v0.33.0/go.mod h1:QKJhjoqUtBsXCAVEjw38mFqoi7DebT7kthcD7UzbnoA=
|
||||
github.com/cstockton/go-conv v1.0.0 h1:zj/q/0MpQ/97XfiC9glWiohO8lhgR4TTnHYZifLTv6I=
|
||||
github.com/cstockton/go-conv v1.0.0/go.mod h1:HuiHkkRgOA0IoBNPC7ysG7kNpjDYlgM7Kj62yQPxjy4=
|
||||
github.com/d2r2/go-i2c v0.0.0-20191123181816-73a8a799d6bc h1:HLRSIWzUGMLCq4ldt0W1GLs3nnAxa5EGoP+9qHgh6j0=
|
||||
github.com/d2r2/go-i2c v0.0.0-20191123181816-73a8a799d6bc/go.mod h1:AwxDPnsgIpy47jbGXZHA9Rv7pDkOJvQbezPuK1Y+nNk=
|
||||
github.com/d2r2/go-logger v0.0.0-20210606094344-60e9d1233e22 h1:nO+SY4KOMsF/LsZ5EtbSKhiT3M6sv/igo2PEru/xEHI=
|
||||
github.com/d2r2/go-logger v0.0.0-20210606094344-60e9d1233e22/go.mod h1:eSx+YfcVy5vCjRZBNIhpIpfCGFMQ6XSOSQkDk7+VCpg=
|
||||
github.com/dave/jennifer v1.7.1 h1:B4jJJDHelWcDhlRQxWeo0Npa/pYKBLrirAQoTN45txo=
|
||||
github.com/dave/jennifer v1.7.1/go.mod h1:nXbxhEmQfOZhWml3D1cDK5M1FLnMSozpbFN/m3RmGZc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package sponsor
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -36,10 +37,7 @@ var (
|
|||
ExpiresAt time.Time
|
||||
)
|
||||
|
||||
const (
|
||||
unavailable = "sponsorship unavailable"
|
||||
victron = "victron"
|
||||
)
|
||||
const unavailable = "sponsorship unavailable"
|
||||
|
||||
func IsAuthorized() bool {
|
||||
mu.RLock()
|
||||
|
|
@ -64,8 +62,15 @@ func ConfigureSponsorship(token string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if os.Getenv("HEMSPRO") != "" {
|
||||
if sub := checkHemsPro(); sub != "" {
|
||||
Subject = sub
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
if token, err = readSerial(); token == "" || err != nil {
|
||||
if token, err = checkPulsares(); token == "" || err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
35
util/sponsor/hemspro.go
Normal file
35
util/sponsor/hemspro.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//go:build !linux
|
||||
|
||||
package sponsor
|
||||
|
||||
import (
|
||||
i2c "github.com/d2r2/go-i2c"
|
||||
)
|
||||
|
||||
const hemspro = "hemspro"
|
||||
|
||||
// checkHemsPro checks if the hardware is a supported HEMS Pro device and returns sponsor subject
|
||||
func checkHemsPro() string {
|
||||
const (
|
||||
ADDR = 0b1101000 // 0x68 DS1307
|
||||
REG_TIMEDATE = 0x00
|
||||
)
|
||||
|
||||
// Create new connection to I2C bus 1
|
||||
i2c, err := i2c.NewI2C(ADDR, 1)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
defer i2c.Close()
|
||||
|
||||
if _, err := i2c.WriteBytes([]byte{REG_TIMEDATE}); err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
buf := make([]byte, 7)
|
||||
if n, err := i2c.ReadBytes(buf); err != nil || n != 7 {
|
||||
return ""
|
||||
}
|
||||
|
||||
return hemspro
|
||||
}
|
||||
16
util/sponsor/hemspro_linux.go
Normal file
16
util/sponsor/hemspro_linux.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
//go:build linux
|
||||
|
||||
package sponsor
|
||||
|
||||
const hemspro = "hemspro"
|
||||
|
||||
// checkHemsPro checks if the hardware is a supported HEMS Pro device and returns sponsor subject
|
||||
func checkHemsPro() string {
|
||||
// TODO i2c validation
|
||||
|
||||
if false {
|
||||
return hemspro
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func readSerial() (string, error) {
|
||||
func checkPulsares() (string, error) {
|
||||
f, err := os.OpenFile("/dev/PulsaresSerial", os.O_RDWR, 0o644)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ import (
|
|||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
const victron = "victron"
|
||||
|
||||
// checkVictron checks if the hardware is a supported victron device and returns sponsor subject
|
||||
func checkVictron() string {
|
||||
vd, err := victronDeviceInfo()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue