Add Tasmota timezone handling and dashboard updates
This commit is contained in:
@@ -7,8 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func TestLoadNormalizesDeviceAliases(t *testing.T) {
|
||||
t.Setenv("MQTT_SCRUBBER_DEVICE_ALIASES", "")
|
||||
|
||||
configPath := filepath.Join(t.TempDir(), "config.json")
|
||||
contents := `{
|
||||
"mqtt": {
|
||||
@@ -105,3 +103,76 @@ func TestLoadOverridesDeviceAliasesFromEnv(t *testing.T) {
|
||||
t.Fatalf("unexpected desk alias: got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadSupportsTasmotaTimeZone(t *testing.T) {
|
||||
configPath := filepath.Join(t.TempDir(), "config.json")
|
||||
contents := `{
|
||||
"mqtt": {
|
||||
"broker": "tcp://127.0.0.1:1883",
|
||||
"client_id": "mqqt-scrubber",
|
||||
"topics": ["tele/+/STATE"],
|
||||
"qos": 0
|
||||
},
|
||||
"influx": {
|
||||
"url": "http://127.0.0.1:8181",
|
||||
"database": "home",
|
||||
"precision": "ns"
|
||||
},
|
||||
"app": {
|
||||
"batch_size": 200,
|
||||
"buffer_size": 1000,
|
||||
"flush_interval": "10s",
|
||||
"flush_timeout": "10s",
|
||||
"log_level": "info",
|
||||
"health_address": ":8080",
|
||||
"tasmota_time_zone": "Europe/Prague"
|
||||
}
|
||||
}`
|
||||
|
||||
if err := os.WriteFile(configPath, []byte(contents), 0o644); err != nil {
|
||||
t.Fatalf("write config file: %v", err)
|
||||
}
|
||||
|
||||
cfg, err := Load(configPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Load returned error: %v", err)
|
||||
}
|
||||
|
||||
if got := cfg.App.TasmotaLocation().String(); got != "Europe/Prague" {
|
||||
t.Fatalf("unexpected tasmota timezone: got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRejectsInvalidTasmotaTimeZone(t *testing.T) {
|
||||
configPath := filepath.Join(t.TempDir(), "config.json")
|
||||
contents := `{
|
||||
"mqtt": {
|
||||
"broker": "tcp://127.0.0.1:1883",
|
||||
"client_id": "mqqt-scrubber",
|
||||
"topics": ["tele/+/STATE"],
|
||||
"qos": 0
|
||||
},
|
||||
"influx": {
|
||||
"url": "http://127.0.0.1:8181",
|
||||
"database": "home",
|
||||
"precision": "ns"
|
||||
},
|
||||
"app": {
|
||||
"batch_size": 200,
|
||||
"buffer_size": 1000,
|
||||
"flush_interval": "10s",
|
||||
"flush_timeout": "10s",
|
||||
"log_level": "info",
|
||||
"health_address": ":8080",
|
||||
"tasmota_time_zone": "Not/AZone"
|
||||
}
|
||||
}`
|
||||
|
||||
if err := os.WriteFile(configPath, []byte(contents), 0o644); err != nil {
|
||||
t.Fatalf("write config file: %v", err)
|
||||
}
|
||||
|
||||
if _, err := Load(configPath); err == nil {
|
||||
t.Fatal("expected Load to reject invalid tasmota_time_zone")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user