config for kiosk handler
This commit is contained in:
parent
f085312e13
commit
85abccf14a
@ -104,10 +104,16 @@ func initConfig() {
|
||||
"image_dir",
|
||||
"version",
|
||||
"webserver_port",
|
||||
"mqtt_broker_url",
|
||||
"mqtt_broker_user",
|
||||
"mqtt_broker_password",
|
||||
"mqtt_presence_topic",
|
||||
"kiosk_cmd_screen_on",
|
||||
"kiosk_cmd_screen_off",
|
||||
}
|
||||
for _, key := range expected_config {
|
||||
if !viper.IsSet(key) {
|
||||
fmt.Fprintf(os.Stderr, "Missing configuration value: %s\n", key)
|
||||
log.Fatalf("Missing configuration value: %s\n", key)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,12 @@ func TestInitConfig(t *testing.T) {
|
||||
viper.Set("deployment", "testing")
|
||||
viper.Set("image_dir", "/tmp")
|
||||
viper.Set("webserver_port", "8080")
|
||||
viper.Set("mqtt_broker_url", "mqtt://example.com:1883")
|
||||
viper.Set("mqtt_broker_user", "testuser")
|
||||
viper.Set("mqtt_broker_password", "testpass")
|
||||
viper.Set("mqtt_presence_topic", "home/foo/test")
|
||||
viper.Set("kiosk_cmd_screen_on", "echo screen on")
|
||||
viper.Set("kiosk_cmd_screen_off", "echo screen off")
|
||||
|
||||
initConfig()
|
||||
assert.Equal(t, gitVersion, viper.GetString("version"), "config version mismatch")
|
||||
@ -25,6 +31,12 @@ func TestInitConfigMissingImageDir(t *testing.T) {
|
||||
viper.Set("deployment", "testing")
|
||||
viper.Set("version", "vTest")
|
||||
viper.Set("webserver_port", "8080")
|
||||
viper.Set("mqtt_broker_url", "mqtt://example.com:1883")
|
||||
viper.Set("mqtt_broker_user", "testuser")
|
||||
viper.Set("mqtt_broker_password", "testpass")
|
||||
viper.Set("mqtt_presence_topic", "home/foo/test")
|
||||
viper.Set("kiosk_cmd_screen_on", "echo screen on")
|
||||
viper.Set("kiosk_cmd_screen_off", "echo screen off")
|
||||
|
||||
initConfig()
|
||||
return
|
||||
|
||||
@ -10,11 +10,13 @@ import (
|
||||
type handler func(area string, present bool)
|
||||
|
||||
type configObj struct {
|
||||
logger *slog.Logger
|
||||
broker string
|
||||
username string
|
||||
password string
|
||||
presenceTopic string
|
||||
logger *slog.Logger
|
||||
broker string
|
||||
username string
|
||||
password string
|
||||
presenceTopic string
|
||||
screen_on_cmd string
|
||||
screen_off_cmd string
|
||||
}
|
||||
|
||||
var config = configObj{}
|
||||
@ -25,6 +27,8 @@ func Run(rootLogger *slog.Logger, exitch chan bool, ctx context.Context) {
|
||||
config.username = viper.GetString("mqtt_broker_user")
|
||||
config.password = viper.GetString("mqtt_broker_password")
|
||||
config.presenceTopic = viper.GetString("mqtt_presence_topic")
|
||||
config.screen_on_cmd = viper.GetString("kiosk_cmd_screen_on")
|
||||
config.screen_off_cmd = viper.GetString("kiosk_cmd_screen_off")
|
||||
config.logger.Info("starting MQTT broker client")
|
||||
brokerConsume(ctx)
|
||||
exitch <- true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user