implement econet exporter
Build and Publish / go-binaries (push) Has been skipped
Build and Publish / container-images (push) Has been skipped
Build and Publish / helm-release (push) Successful in 19s
Build and Publish / check-chart (push) Successful in 52s

This commit is contained in:
2026-07-04 17:22:31 -04:00
parent 8198e8cfee
commit b2ec72352a
44 changed files with 2226 additions and 1281 deletions
+36 -11
View File
@@ -5,12 +5,30 @@
package config
import (
"time"
"github.com/caarlos0/env/v11"
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
)
// DefaultUsageInterval is used when UsageInterval is unset. Rheem's
// energy/water history only updates hourly, so polling faster is wasteful.
const DefaultUsageInterval = 5 * time.Minute
type ServiceConfig struct {
Timezone string `yaml:"timezone" json:"timezone,omitempty" default:"UTC"`
Opts *DemoOpts `yaml:"opts" json:"opts,omitempty"`
// Rheem EcoNet cloud credentials. Prefer supplying the password via
// the ECONET_PASSWORD environment variable rather than config.yaml.
EconetEmail string `yaml:"econetEmail" json:"econetEmail,omitempty" env:"ECONET_EMAIL"`
EconetPassword string `yaml:"econetPassword" json:"econetPassword,omitempty" env:"ECONET_PASSWORD"`
// CostPerKWH is the electricity price in US dollars per kWh (e.g. 0.18
// means 18 cents/kWh, NOT 18). It derives the econet_energy_cost_dollars
// metric from kWh energy usage.
CostPerKWH float64 `yaml:"costPerKWH" json:"costPerKWH,omitempty" env:"ECONET_COST_PER_KWH"`
// UsageInterval controls how often energy/water usage history is polled.
UsageInterval time.Duration `yaml:"usageInterval" json:"usageInterval,omitempty" env:"ECONET_USAGE_INTERVAL"`
// Embeds go-app config, used by go-app to
// merge custom config into go-app config, and to produce
@@ -18,14 +36,21 @@ type ServiceConfig struct {
*config.AppConfig
}
type DemoOpts struct {
FactLang string `yaml:"factLang" json:"factLang,omitempty" default:"en"`
FactType FactType `yaml:"factType" json:"factType,omitempty" default:"random" enum:"today,random"`
// LoadEnv applies environment-variable overrides to the custom ServiceConfig
// fields. go-app's MustLoadConfigInto only handles env for the embedded
// AppConfig, so the caller must apply env for custom fields. The embedded
// AppConfig is skipped here to preserve go-app's own env/yaml precedence.
func (c *ServiceConfig) LoadEnv() error {
appConfig := c.AppConfig
c.AppConfig = nil
defer func() { c.AppConfig = appConfig }()
return env.Parse(c)
}
type FactType string
const (
TypeToday FactType = "today"
TypeRandom FactType = "random"
)
// GetUsageInterval returns the configured usage poll interval or the default.
func (c *ServiceConfig) GetUsageInterval() time.Duration {
if c.UsageInterval <= 0 {
return DefaultUsageInterval
}
return c.UsageInterval
}