Skip to content

Commit

Permalink
chore(config): Move interval to advanced.fallback-interval
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed May 6, 2024
1 parent ab10cda commit 0c1f0f4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
6 changes: 3 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Config struct {
URL string `toml:"url" comment:"Nightscout URL. (required)"`
Token string `toml:"token" comment:"Nightscout token. Using an access token is recommended instead of the API secret."`
Units string `toml:"units" comment:"Blood sugar unit. (one of: mg/dL, mmol/L)"`
Interval Duration `toml:"interval" comment:"Update interval."`
Arrows Arrows `toml:"arrows" comment:"Customize the arrows."`
LocalFile LocalFile `toml:"local-file" comment:"Enables writing the latest blood sugar to a local temporary file."`
Advanced Advanced `toml:"advanced" comment:"Advanced settings."`
Expand All @@ -38,8 +37,9 @@ type LocalFile struct {
}

type Advanced struct {
FetchDelay Duration `toml:"fetch-delay" comment:"Time to wait before the next reading should be ready.\nIn testing, this seems to be about 20s behind, so the default is 30s to be safe.\nYour results may vary."`
RoundAge bool `toml:"round-age" comment:"If enabled, the reading's age will be rounded up to the nearest minute.\nNightscout rounds the age, so enable this if you want the values to match."`
FetchDelay Duration `toml:"fetch-delay" comment:"Time to wait before the next reading should be ready.\nIn testing, this seems to be about 20s behind, so the default is 30s to be safe.\nYour results may vary."`
FallbackInterval Duration `toml:"fallback-interval" comment:"Normally, readings will be fetched when ready (after ~5m).\nThis interval will be used if the next reading time cannot be estimated due to sensor warm-up, missed readings, errors, etc."`
RoundAge bool `toml:"round-age" comment:"If enabled, the reading's age will be rounded up to the nearest minute.\nNightscout rounds the age, so enable this if you want the values to match."`
}

const configDir = "nightscout-menu-bar"
Expand Down
10 changes: 5 additions & 5 deletions internal/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ const LocalFileFormatCsv = "csv"

func NewDefault() *Config {
return &Config{
Title: "Nightscout",
Units: UnitsMgdl,
Interval: Duration{30 * time.Second},
Title: "Nightscout",
Units: UnitsMgdl,
Arrows: Arrows{
DoubleUp: "⇈",
SingleUp: "↑",
Expand All @@ -27,8 +26,9 @@ func NewDefault() *Config {
Path: filepath.Join("$TMPDIR", "nightscout.csv"),
},
Advanced: Advanced{
FetchDelay: Duration{30 * time.Second},
RoundAge: true,
FetchDelay: Duration{30 * time.Second},
FallbackInterval: Duration{30 * time.Second},
RoundAge: true,
},
}
}
15 changes: 15 additions & 0 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (conf *Config) Load() error {
return err
}

if err := migrateConfig(k); err != nil {
return err
}

if err := k.UnmarshalWithConf("", &conf, koanf.UnmarshalConf{Tag: "toml"}); err != nil {
return err
}
Expand Down Expand Up @@ -155,3 +159,14 @@ func InitLog() {
TimeFormat: time.DateTime,
})
}

func migrateConfig(k *koanf.Koanf) error {
if k.Exists("interval") {
log.Info().Msg("Migrating config: interval to advanced.fallback-interval")
if err := k.Set("advanced.fallback-interval", k.Get("interval")); err != nil {
return err
}
}

return nil
}
2 changes: 1 addition & 1 deletion internal/ticker/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ func (t *Ticker) Fetch(render chan<- *nightscout.Properties) time.Duration {
}
}
}
return t.config.Interval.Duration
return t.config.Advanced.FallbackInterval.Duration
}

0 comments on commit 0c1f0f4

Please sign in to comment.