Add Tasmota timezone handling and dashboard updates
This commit is contained in:
+44
-12
@@ -39,12 +39,13 @@ type InfluxConfig struct {
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
BatchSize int `json:"batch_size"`
|
||||
BufferSize int `json:"buffer_size"`
|
||||
FlushInterval DurationValue `json:"flush_interval"`
|
||||
FlushTimeout DurationValue `json:"flush_timeout"`
|
||||
LogLevel string `json:"log_level"`
|
||||
HealthAddress string `json:"health_address"`
|
||||
BatchSize int `json:"batch_size"`
|
||||
BufferSize int `json:"buffer_size"`
|
||||
FlushInterval DurationValue `json:"flush_interval"`
|
||||
FlushTimeout DurationValue `json:"flush_timeout"`
|
||||
LogLevel string `json:"log_level"`
|
||||
HealthAddress string `json:"health_address"`
|
||||
TasmotaTimeZone string `json:"tasmota_time_zone"`
|
||||
}
|
||||
|
||||
type DurationValue struct {
|
||||
@@ -124,6 +125,9 @@ func (cfg Config) Validate() error {
|
||||
if cfg.App.FlushTimeout.Duration <= 0 {
|
||||
return errors.New("app flush_timeout must be greater than zero")
|
||||
}
|
||||
if _, err := loadConfiguredLocation(cfg.App.TasmotaTimeZone); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -145,12 +149,13 @@ func defaultConfig() Config {
|
||||
Precision: "ns",
|
||||
},
|
||||
App: AppConfig{
|
||||
BatchSize: 200,
|
||||
BufferSize: 1000,
|
||||
FlushInterval: DurationValue{Duration: 10 * time.Second},
|
||||
FlushTimeout: DurationValue{Duration: 10 * time.Second},
|
||||
LogLevel: "info",
|
||||
HealthAddress: ":8080",
|
||||
BatchSize: 200,
|
||||
BufferSize: 1000,
|
||||
FlushInterval: DurationValue{Duration: 10 * time.Second},
|
||||
FlushTimeout: DurationValue{Duration: 10 * time.Second},
|
||||
LogLevel: "info",
|
||||
HealthAddress: ":8080",
|
||||
TasmotaTimeZone: "UTC",
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -166,6 +171,7 @@ func applyEnvOverrides(cfg *Config) error {
|
||||
setString(&cfg.Influx.Precision, envPrefix+"INFLUX_PRECISION")
|
||||
setString(&cfg.App.LogLevel, envPrefix+"APP_LOG_LEVEL")
|
||||
setString(&cfg.App.HealthAddress, envPrefix+"APP_HEALTH_ADDRESS")
|
||||
setString(&cfg.App.TasmotaTimeZone, envPrefix+"APP_TASMOTA_TIME_ZONE")
|
||||
|
||||
if raw, ok := os.LookupEnv(envPrefix + "DEVICE_ALIASES"); ok {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
@@ -276,3 +282,29 @@ func normalizeDeviceKey(value string) string {
|
||||
normalized = strings.Trim(normalized, "_")
|
||||
return normalized
|
||||
}
|
||||
|
||||
func (cfg AppConfig) TasmotaLocation() *time.Location {
|
||||
location, err := loadConfiguredLocation(cfg.TasmotaTimeZone)
|
||||
if err != nil {
|
||||
return time.UTC
|
||||
}
|
||||
|
||||
return location
|
||||
}
|
||||
|
||||
func loadConfiguredLocation(name string) (*time.Location, error) {
|
||||
trimmed := strings.TrimSpace(name)
|
||||
if trimmed == "" || strings.EqualFold(trimmed, "utc") {
|
||||
return time.UTC, nil
|
||||
}
|
||||
if strings.EqualFold(trimmed, "local") {
|
||||
return time.Local, nil
|
||||
}
|
||||
|
||||
location, err := time.LoadLocation(trimmed)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("app tasmota_time_zone %q is invalid: %w", trimmed, err)
|
||||
}
|
||||
|
||||
return location, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user