add support for barometric pressure
This commit is contained in:
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -12,12 +13,13 @@ type Config struct {
|
||||
LogLevel string `yaml:"log_level"`
|
||||
|
||||
MQTT struct {
|
||||
Broker string `yaml:"broker"`
|
||||
ClientID string `yaml:"client_id"`
|
||||
Username string `yaml:"username"`
|
||||
Password string `yaml:"password"`
|
||||
Topic string `yaml:"topic"`
|
||||
QoS byte `yaml:"qos"`
|
||||
Broker string `yaml:"broker"`
|
||||
ClientID string `yaml:"client_id"`
|
||||
Username string `yaml:"username"`
|
||||
Password string `yaml:"password"`
|
||||
Topic string `yaml:"topic"`
|
||||
QoS byte `yaml:"qos"`
|
||||
Topics []MQTTTopic `yaml:"topics"`
|
||||
} `yaml:"mqtt"`
|
||||
|
||||
DB struct {
|
||||
@@ -52,6 +54,13 @@ type Config struct {
|
||||
} `yaml:"wunderground"`
|
||||
}
|
||||
|
||||
type MQTTTopic struct {
|
||||
Name string `yaml:"name"`
|
||||
Topic string `yaml:"topic"`
|
||||
Type string `yaml:"type"`
|
||||
QoS *byte `yaml:"qos"`
|
||||
}
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -64,8 +73,31 @@ func Load(path string) (*Config, error) {
|
||||
}
|
||||
|
||||
// Minimal validation
|
||||
if c.MQTT.Broker == "" || c.MQTT.Topic == "" {
|
||||
return nil, errors.New("mqtt broker and topic are required")
|
||||
if c.MQTT.Broker == "" {
|
||||
return nil, errors.New("mqtt broker is required")
|
||||
}
|
||||
if len(c.MQTT.Topics) == 0 && c.MQTT.Topic != "" {
|
||||
qos := c.MQTT.QoS
|
||||
c.MQTT.Topics = []MQTTTopic{{
|
||||
Name: "ws90",
|
||||
Topic: c.MQTT.Topic,
|
||||
Type: "ws90",
|
||||
QoS: &qos,
|
||||
}}
|
||||
}
|
||||
if len(c.MQTT.Topics) == 0 {
|
||||
return nil, errors.New("mqtt topic(s) are required")
|
||||
}
|
||||
for i := range c.MQTT.Topics {
|
||||
t := c.MQTT.Topics[i]
|
||||
if t.Topic == "" {
|
||||
return nil, errors.New("mqtt topics must include topic")
|
||||
}
|
||||
if t.Type == "" {
|
||||
t.Type = "ws90"
|
||||
}
|
||||
t.Type = strings.ToLower(t.Type)
|
||||
c.MQTT.Topics[i] = t
|
||||
}
|
||||
if c.DB.ConnString == "" {
|
||||
return nil, errors.New("db conn_string is required")
|
||||
|
||||
Reference in New Issue
Block a user