Skip to content

Commit

Permalink
Plugins: add timeseries (#18049)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Jan 5, 2025
1 parent b728e23 commit 927cd39
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions provider/timeseries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package provider

import (
"context"
"encoding/json"
"time"

"github.com/evcc-io/evcc/api"
"github.com/jinzhu/now"
)

type timeseriesProvider struct{}

func init() {
registry.AddCtx("timeseries", TimeSeriesFromConfig)
}

// TimeSeriesFromConfig creates timeseries provider
func TimeSeriesFromConfig(_ context.Context, _ map[string]interface{}) (Provider, error) {
return new(timeseriesProvider), nil
}

var _ StringProvider = (*timeseriesProvider)(nil)

func (p *timeseriesProvider) StringGetter() (func() (string, error), error) {
return func() (string, error) {
res := make(api.Rates, 48)
ts := now.BeginningOfHour()
for i := 0; i < 48; i++ {
res[i] = api.Rate{
Start: ts,
End: ts.Add(time.Hour),
}
ts = ts.Add(time.Hour)
}

b, err := json.Marshal(res)
return string(b), err
}, nil
}

0 comments on commit 927cd39

Please sign in to comment.