Add brew UUID to DWIngest

This commit is contained in:
Søren Rasmussen 2022-08-03 15:51:40 +02:00
parent c38b8e1ae6
commit 1366730593
5 changed files with 43 additions and 15 deletions

View file

@ -32,6 +32,10 @@ func main() {
configuration.Initialize()
config := configuration.LoadConfiguration()
if config.Brew.UUID.IsNil() {
log.Fatal("Brew ID is not configured -- terminating")
}
// NATS
servers := strings.Join(config.NATS.Servers, ",")
userInfo := nats.UserInfo(config.NATS.Username, config.NATS.Password)

View file

@ -1,8 +1,15 @@
package configuration
import "github.com/spf13/viper"
import (
"github.com/gofrs/uuid"
"github.com/spf13/viper"
)
type Configuration struct {
Brew struct {
UUID uuid.UUID `mapstructure:"uuid"`
} `mapstructure:"brew"`
NATS struct {
Servers []string `mapstructure:"servers"`
Username string `mapstructure:"username"`

View file

@ -135,6 +135,7 @@ func (p *DWIngest) publish(subject string, reading any) error {
func (p *DWIngest) publishTilt(t tilt.Tilt) error {
ev := Tilt{
Time: time.Now().UTC(),
BrewUUID: p.config.Brew.UUID,
Color: string(t.Color()),
Gravity: t.Gravity(),
Temperature: t.Celsius(),
@ -144,12 +145,15 @@ func (p *DWIngest) publishTilt(t tilt.Tilt) error {
}
func (p *DWIngest) publishTemperatureReading(reading temperature.TemperatureReading) error {
reading.BrewUUID = p.config.Brew.UUID
return p.publish(p.config.NATS.Subject.Temp, reading)
}
func (p *DWIngest) publishState(state controllers.ChamberState) error {
st := State{
Time: time.Now().UTC(),
BrewUUID: p.config.Brew.UUID,
State: controllers.ChamberStateMap[state],
}
@ -159,6 +163,7 @@ func (p *DWIngest) publishState(state controllers.ChamberState) error {
func (p *DWIngest) publishEvent(event string) error {
ev := Event{
Time: time.Now().UTC(),
BrewUUID: p.config.Brew.UUID,
Event: event,
}

View file

@ -1,14 +1,20 @@
package dwingest
import "time"
import (
"time"
"github.com/gofrs/uuid"
)
type State struct {
Time time.Time `json:"time"`
BrewUUID uuid.UUID `json:"brew_uuid"`
State string `json:"state"`
}
type Tilt struct {
Time time.Time `json:"time"`
BrewUUID uuid.UUID `json:"brew_uuid"`
Color string `json:"color"`
Gravity float64 `json:"gravity"`
Temperature float64 `json:"temperature"`
@ -16,5 +22,6 @@ type Tilt struct {
type Event struct {
Time time.Time `json:"time"`
BrewUUID uuid.UUID `json:"brew_uuid"`
Event string `json:"event"`
}

View file

@ -1,9 +1,14 @@
package temperature
import "time"
import (
"time"
"github.com/gofrs/uuid"
)
type TemperatureReading struct {
Time time.Time `json:"time"`
BrewUUID uuid.UUID `json:"brew_uuid"`
Ambient float64 `json:"ambient"`
Chamber float64 `json:"chamber"`
Wort float64 `json:"wort"`