chore: refactor caching (#18378)

This commit is contained in:
andig 2025-01-25 13:22:10 +01:00 • committed by GitHub
parent 2410e957cf
commit fe388db66a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
60 changed files with 138 additions and 174 deletions

View file

@ -25,7 +25,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/connectiq" "github.com/evcc-io/evcc/charger/connectiq"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
) )
@ -71,7 +70,7 @@ func NewConnectIq(uri string, cache time.Duration) (api.Charger, error) {
} }
// cache meter readings // cache meter readings
wb.meterG = plugin.Cached(func() (connectiq.MeterStatus, error) { wb.meterG = util.Cached(func() (connectiq.MeterStatus, error) {
var res connectiq.MeterStatus var res connectiq.MeterStatus
uri := fmt.Sprintf("%s/meter/status", wb.uri) uri := fmt.Sprintf("%s/meter/status", wb.uri)
err := wb.GetJSON(uri, &res) err := wb.GetJSON(uri, &res)

View file

@ -8,7 +8,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/daheimladen" "github.com/evcc-io/evcc/charger/daheimladen"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"golang.org/x/oauth2" "golang.org/x/oauth2"
@ -22,8 +21,8 @@ type DaheimLaden struct {
idTag string idTag string
token string token string
transactionID int32 transactionID int32
statusG plugin.Cacheable[daheimladen.GetLatestStatus] statusG util.Cacheable[daheimladen.GetLatestStatus]
meterG plugin.Cacheable[daheimladen.GetLatestMeterValueResponse] meterG util.Cacheable[daheimladen.GetLatestMeterValueResponse]
cache time.Duration cache time.Duration
} }
@ -67,13 +66,13 @@ func NewDaheimLaden(token, stationID string, cache time.Duration) (*DaheimLaden,
Base: c.Client.Transport, Base: c.Client.Transport,
} }
c.statusG = plugin.ResettableCached(func() (daheimladen.GetLatestStatus, error) { c.statusG = util.ResettableCached(func() (daheimladen.GetLatestStatus, error) {
var res daheimladen.GetLatestStatus var res daheimladen.GetLatestStatus
err := c.GetJSON(fmt.Sprintf("%s/cs/%s/status", daheimladen.BASE_URL, c.stationID), &res) err := c.GetJSON(fmt.Sprintf("%s/cs/%s/status", daheimladen.BASE_URL, c.stationID), &res)
return res, err return res, err
}, c.cache) }, c.cache)
c.meterG = plugin.ResettableCached(func() (daheimladen.GetLatestMeterValueResponse, error) { c.meterG = util.ResettableCached(func() (daheimladen.GetLatestMeterValueResponse, error) {
var res daheimladen.GetLatestMeterValueResponse var res daheimladen.GetLatestMeterValueResponse
err := c.GetJSON(fmt.Sprintf("%s/cs/%s/metervalue", daheimladen.BASE_URL, c.stationID), &res) err := c.GetJSON(fmt.Sprintf("%s/cs/%s/metervalue", daheimladen.BASE_URL, c.stationID), &res)
return res, err return res, err

View file

@ -15,7 +15,6 @@ import (
"github.com/enbility/spine-go/model" "github.com/enbility/spine-go/model"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/core/loadpoint" "github.com/evcc-io/evcc/core/loadpoint"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/server/eebus" "github.com/evcc-io/evcc/server/eebus"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/samber/lo" "github.com/samber/lo"
@ -88,7 +87,7 @@ func NewEEBus(ski, ip string, hasMeter, hasChargedEnergy, vasVW bool) (api.Charg
} }
c.Connector = eebus.NewConnector() c.Connector = eebus.NewConnector()
c.minMaxG = plugin.Cached(c.minMax, time.Second) c.minMaxG = util.Cached(c.minMax, time.Second)
if err := eebus.Instance.RegisterDevice(ski, ip, c); err != nil { if err := eebus.Instance.RegisterDevice(ski, ip, c); err != nil {
return nil, err return nil, err

View file

@ -8,7 +8,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/evse" "github.com/evcc-io/evcc/charger/evse"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
) )
@ -20,7 +19,7 @@ type EVSEWifi struct {
alwaysActive bool alwaysActive bool
current int64 // current will always be the physical value sent to the API current int64 // current will always be the physical value sent to the API
hires bool hires bool
paramG plugin.Cacheable[evse.ListEntry] paramG util.Cacheable[evse.ListEntry]
} }
func init() { func init() {
@ -122,7 +121,7 @@ func NewEVSEWifi(uri string, cache time.Duration) (*EVSEWifi, error) {
current: 6, // 6A defined value current: 6, // 6A defined value
} }
wb.paramG = plugin.ResettableCached(func() (evse.ListEntry, error) { wb.paramG = util.ResettableCached(func() (evse.ListEntry, error) {
var res evse.ParameterResponse var res evse.ParameterResponse
uri := fmt.Sprintf("%s/getParameters", wb.uri) uri := fmt.Sprintf("%s/getParameters", wb.uri)
if err := wb.GetJSON(uri, &res); err != nil { if err := wb.GetJSON(uri, &res); err != nil {

View file

@ -30,7 +30,6 @@ import (
"github.com/evcc-io/evcc/charger/echarge" "github.com/evcc-io/evcc/charger/echarge"
"github.com/evcc-io/evcc/charger/echarge/ecb1" "github.com/evcc-io/evcc/charger/echarge/ecb1"
"github.com/evcc-io/evcc/meter/obis" "github.com/evcc-io/evcc/meter/obis"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/sponsor" "github.com/evcc-io/evcc/util/sponsor"
@ -85,7 +84,7 @@ func NewHardyBarth(uri string, chargecontrol, meter int, cache time.Duration) (a
} }
// cache meter readings // cache meter readings
wb.meterG = plugin.Cached(func() (ecb1.Meter, error) { wb.meterG = util.Cached(func() (ecb1.Meter, error) {
var res struct { var res struct {
Meter struct { Meter struct {
ecb1.Meter ecb1.Meter

View file

@ -30,7 +30,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/echarge" "github.com/evcc-io/evcc/charger/echarge"
"github.com/evcc-io/evcc/charger/echarge/salia" "github.com/evcc-io/evcc/charger/echarge/salia"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/sponsor" "github.com/evcc-io/evcc/util/sponsor"
@ -46,7 +45,7 @@ type Salia struct {
uri string uri string
current int64 current int64
fw int // 2 if fw 2.0 fw int // 2 if fw 2.0
apiG plugin.Cacheable[salia.Api] apiG util.Cacheable[salia.Api]
} }
func init() { func init() {
@ -84,7 +83,7 @@ func NewSalia(ctx context.Context, uri string, cache time.Duration) (api.Charger
current: 6, current: 6,
} }
wb.apiG = plugin.ResettableCached(func() (salia.Api, error) { wb.apiG = util.ResettableCached(func() (salia.Api, error) {
var res salia.Api var res salia.Api
err := wb.GetJSON(wb.uri, &res) err := wb.GetJSON(wb.uri, &res)
return res, err return res, err

View file

@ -6,7 +6,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/meter/mystrom" "github.com/evcc-io/evcc/meter/mystrom"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
) )
@ -21,7 +20,7 @@ func init() {
type MyStrom struct { type MyStrom struct {
*switchSocket *switchSocket
conn *mystrom.Connection conn *mystrom.Connection
reportG plugin.Cacheable[mystrom.Report] reportG util.Cacheable[mystrom.Report]
} }
// NewMyStromFromConfig creates a myStrom charger from generic config // NewMyStromFromConfig creates a myStrom charger from generic config
@ -44,7 +43,7 @@ func NewMyStromFromConfig(other map[string]interface{}) (api.Charger, error) {
} }
c.switchSocket = NewSwitchSocket(&cc.embed, c.Enabled, c.conn.CurrentPower, cc.StandbyPower) c.switchSocket = NewSwitchSocket(&cc.embed, c.Enabled, c.conn.CurrentPower, cc.StandbyPower)
c.reportG = plugin.ResettableCached(c.conn.Report, cc.Cache) c.reportG = util.ResettableCached(c.conn.Report, cc.Cache)
return c, nil return c, nil
} }

View file

@ -9,7 +9,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/nrg/connect" "github.com/evcc-io/evcc/charger/nrg/connect"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
) )
@ -23,8 +22,8 @@ type NRGKickConnect struct {
mac string mac string
password string password string
enabled bool enabled bool
settingsG plugin.Cacheable[connect.Settings] settingsG util.Cacheable[connect.Settings]
measurementsG plugin.Cacheable[connect.Measurements] measurementsG util.Cacheable[connect.Measurements]
} }
func init() { func init() {
@ -56,7 +55,7 @@ func NewNRGKickConnect(uri, mac, password string, cache time.Duration) (*NRGKick
password: password, password: password,
} }
nrg.settingsG = plugin.ResettableCached(func() (connect.Settings, error) { nrg.settingsG = util.ResettableCached(func() (connect.Settings, error) {
var res connect.Settings var res connect.Settings
err := nrg.GetJSON(nrg.apiURL(connect.SettingsPath), &res) err := nrg.GetJSON(nrg.apiURL(connect.SettingsPath), &res)
@ -67,7 +66,7 @@ func NewNRGKickConnect(uri, mac, password string, cache time.Duration) (*NRGKick
return res, err return res, err
}, cache) }, cache)
nrg.measurementsG = plugin.ResettableCached(func() (connect.Measurements, error) { nrg.measurementsG = util.ResettableCached(func() (connect.Measurements, error) {
var res connect.Measurements var res connect.Measurements
err := nrg.GetJSON(nrg.apiURL(connect.MeasurementsPath), &res) err := nrg.GetJSON(nrg.apiURL(connect.MeasurementsPath), &res)

View file

@ -10,7 +10,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/openevse" "github.com/evcc-io/evcc/charger/openevse"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport" "github.com/evcc-io/evcc/util/transport"
@ -20,7 +19,7 @@ import (
type OpenEVSE struct { type OpenEVSE struct {
*request.Helper *request.Helper
uri string uri string
statusG plugin.Cacheable[openevse.Status] statusG util.Cacheable[openevse.Status]
current int current int
enabled bool enabled bool
} }
@ -67,7 +66,7 @@ func NewOpenEVSE(uri, user, password string, cache time.Duration) (api.Charger,
c.Client.Transport = transport.BasicAuth(user, password, c.Client.Transport) c.Client.Transport = transport.BasicAuth(user, password, c.Client.Transport)
} }
c.statusG = plugin.ResettableCached(func() (openevse.Status, error) { c.statusG = util.ResettableCached(func() (openevse.Status, error) {
var res openevse.Status var res openevse.Status
uri := fmt.Sprintf("%s/status", c.uri) uri := fmt.Sprintf("%s/status", c.uri)

View file

@ -8,7 +8,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/openwb/pro" "github.com/evcc-io/evcc/charger/openwb/pro"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
) )
@ -24,7 +23,7 @@ type OpenWBPro struct {
*request.Helper *request.Helper
uri string uri string
current float64 current float64
statusG plugin.Cacheable[pro.Status] statusG util.Cacheable[pro.Status]
} }
// NewOpenWBProFromConfig creates a OpenWBPro charger from generic config // NewOpenWBProFromConfig creates a OpenWBPro charger from generic config
@ -53,7 +52,7 @@ func NewOpenWBPro(ctx context.Context, uri string, cache time.Duration) (*OpenWB
current: 6, // 6A defined value current: 6, // 6A defined value
} }
wb.statusG = plugin.ResettableCached(func() (pro.Status, error) { wb.statusG = util.ResettableCached(func() (pro.Status, error) {
var res pro.Status var res pro.Status
uri := fmt.Sprintf("%s/%s", wb.uri, "connect.php") uri := fmt.Sprintf("%s/%s", wb.uri, "connect.php")
err := wb.GetJSON(uri, &res) err := wb.GetJSON(uri, &res)

View file

@ -26,7 +26,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/smaevcharger" "github.com/evcc-io/evcc/charger/smaevcharger"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/sponsor" "github.com/evcc-io/evcc/util/sponsor"
@ -41,8 +40,8 @@ type Smaevcharger struct {
uri string // 192.168.XXX.XXX uri string // 192.168.XXX.XXX
cache time.Duration cache time.Duration
oldstate float64 oldstate float64
measurementG plugin.Cacheable[[]smaevcharger.Measurements] measurementG util.Cacheable[[]smaevcharger.Measurements]
parameterG plugin.Cacheable[[]smaevcharger.Parameters] parameterG util.Cacheable[[]smaevcharger.Parameters]
} }
func init() { func init() {
@ -95,8 +94,8 @@ func NewSmaevcharger(uri, user, password string, cache time.Duration) (api.Charg
} }
// setup cached values // setup cached values
wb.measurementG = plugin.ResettableCached(wb._measurementData, wb.cache) wb.measurementG = util.ResettableCached(wb._measurementData, wb.cache)
wb.parameterG = plugin.ResettableCached(wb._parameterData, wb.cache) wb.parameterG = util.ResettableCached(wb._parameterData, wb.cache)
ts, err := smaevcharger.TokenSource(log, wb.uri, user, password) ts, err := smaevcharger.TokenSource(log, wb.uri, user, password)
if err != nil { if err != nil {

View file

@ -9,7 +9,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/sponsor" "github.com/evcc-io/evcc/util/sponsor"
@ -43,7 +42,7 @@ type RealTimeData struct {
type Trydan struct { type Trydan struct {
*request.Helper *request.Helper
uri string uri string
statusG plugin.Cacheable[RealTimeData] statusG util.Cacheable[RealTimeData]
current int current int
enabled bool enabled bool
} }
@ -83,7 +82,7 @@ func NewTrydan(uri string, cache time.Duration) (api.Charger, error) {
uri: util.DefaultScheme(strings.TrimSuffix(uri, "/"), "http"), uri: util.DefaultScheme(strings.TrimSuffix(uri, "/"), "http"),
} }
c.statusG = plugin.ResettableCached(func() (RealTimeData, error) { c.statusG = util.ResettableCached(func() (RealTimeData, error) {
var res RealTimeData var res RealTimeData
uri := fmt.Sprintf("%s/RealTimeData", c.uri) uri := fmt.Sprintf("%s/RealTimeData", c.uri)
err := c.GetJSON(uri, &res) err := c.GetJSON(uri, &res)

View file

@ -9,7 +9,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/core/loadpoint" "github.com/evcc-io/evcc/core/loadpoint"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
) )
@ -73,7 +72,7 @@ func NewTwc3FromConfig(other map[string]interface{}) (api.Charger, error) {
client := request.NewHelper(util.NewLogger("twc3")) client := request.NewHelper(util.NewLogger("twc3"))
uri := fmt.Sprintf("%s/api/1/vitals", util.DefaultScheme(strings.TrimSuffix(cc.URI, "/"), "http")) uri := fmt.Sprintf("%s/api/1/vitals", util.DefaultScheme(strings.TrimSuffix(cc.URI, "/"), "http"))
c.vitalsG = plugin.Cached(func() (Vitals, error) { c.vitalsG = util.Cached(func() (Vitals, error) {
var res Vitals var res Vitals
err := client.GetJSON(uri, &res) err := client.GetJSON(uri, &res)
return res, err return res, err

View file

@ -26,7 +26,6 @@ import (
"github.com/WulfgarW/sensonet" "github.com/WulfgarW/sensonet"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/samber/lo" "github.com/samber/lo"
@ -127,7 +126,7 @@ func NewVaillantFromConfig(ctx context.Context, other map[string]interface{}) (a
var power func() (float64, error) var power func() (float64, error)
if devices, _ := conn.GetMpcData(systemId); len(devices) > 0 { if devices, _ := conn.GetMpcData(systemId); len(devices) > 0 {
power = plugin.Cached(func() (float64, error) { power = util.Cached(func() (float64, error) {
res, err := conn.GetMpcData(systemId) res, err := conn.GetMpcData(systemId)
return lo.SumBy(res, func(d sensonet.MpcDevice) float64 { return lo.SumBy(res, func(d sensonet.MpcDevice) float64 {
return d.CurrentPower return d.CurrentPower
@ -153,7 +152,7 @@ func NewVaillantFromConfig(ctx context.Context, other map[string]interface{}) (a
var temp func() (float64, error) var temp func() (float64, error)
if !heating || heatingTempSensor { if !heating || heatingTempSensor {
temp = plugin.Cached(func() (float64, error) { temp = util.Cached(func() (float64, error) {
system, err := conn.GetSystem(systemId) system, err := conn.GetSystem(systemId)
if err != nil { if err != nil {
return 0, err return 0, err

View file

@ -28,7 +28,6 @@ import (
"github.com/coreos/go-oidc/v3/oidc" "github.com/coreos/go-oidc/v3/oidc"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/zaptec" "github.com/evcc-io/evcc/charger/zaptec"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/sponsor" "github.com/evcc-io/evcc/util/sponsor"
@ -43,7 +42,7 @@ import (
type Zaptec struct { type Zaptec struct {
*request.Helper *request.Helper
log *util.Logger log *util.Logger
statusG plugin.Cacheable[zaptec.StateResponse] statusG util.Cacheable[zaptec.StateResponse]
id string id string
enabled bool enabled bool
priority bool priority bool
@ -91,7 +90,7 @@ func NewZaptec(user, password, id string, priority bool, cache time.Duration) (a
} }
// setup cached values // setup cached values
c.statusG = plugin.ResettableCached(func() (zaptec.StateResponse, error) { c.statusG = util.ResettableCached(func() (zaptec.StateResponse, error) {
var res zaptec.StateResponse var res zaptec.StateResponse
uri := fmt.Sprintf("%s/api/chargers/%s/state", zaptec.ApiURL, c.id) uri := fmt.Sprintf("%s/api/chargers/%s/state", zaptec.ApiURL, c.id)

View file

@ -23,7 +23,6 @@ import (
"github.com/evcc-io/evcc/core/soc" "github.com/evcc-io/evcc/core/soc"
"github.com/evcc-io/evcc/core/vehicle" "github.com/evcc-io/evcc/core/vehicle"
"github.com/evcc-io/evcc/core/wrapper" "github.com/evcc-io/evcc/core/wrapper"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/push" "github.com/evcc-io/evcc/push"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/config" "github.com/evcc-io/evcc/util/config"
@ -457,7 +456,7 @@ func (lp *Loadpoint) evChargeStopHandler() {
} }
// soc update reset // soc update reset
plugin.ResetCached() util.ResetCached()
lp.socUpdated = time.Time{} lp.socUpdated = time.Time{}
// reset pv enable/disable timer // reset pv enable/disable timer

View file

@ -13,7 +13,7 @@ import (
"github.com/evcc-io/evcc/core/session" "github.com/evcc-io/evcc/core/session"
"github.com/evcc-io/evcc/core/soc" "github.com/evcc-io/evcc/core/soc"
"github.com/evcc-io/evcc/core/vehicle" "github.com/evcc-io/evcc/core/vehicle"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
const ( const (
@ -234,7 +234,7 @@ func (lp *Loadpoint) vehicleUnidentified() bool {
select { select {
case <-lp.vehicleDetectTicker.C: case <-lp.vehicleDetectTicker.C:
lp.log.DEBUG.Println("vehicle api refresh") lp.log.DEBUG.Println("vehicle api refresh")
plugin.ResetCached() util.ResetCached()
default: default:
} }
@ -260,7 +260,7 @@ func (lp *Loadpoint) vehicleDefaultOrDetect() {
func (lp *Loadpoint) startVehicleDetection() { func (lp *Loadpoint) startVehicleDetection() {
// flush all vehicles before detection starts // flush all vehicles before detection starts
lp.log.DEBUG.Println("vehicle api refresh") lp.log.DEBUG.Println("vehicle api refresh")
plugin.ResetCached() util.ResetCached()
lp.vehicleDetect = lp.clock.Now() lp.vehicleDetect = lp.clock.Now()
lp.vehicleDetectTicker = lp.clock.Ticker(vehicleDetectInterval) lp.vehicleDetectTicker = lp.clock.Ticker(vehicleDetectInterval)

View file

@ -9,7 +9,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/core/circuit" "github.com/evcc-io/evcc/core/circuit"
"github.com/evcc-io/evcc/core/site" "github.com/evcc-io/evcc/core/site"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/server/eebus" "github.com/evcc-io/evcc/server/eebus"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
) )
@ -30,7 +29,7 @@ type EEBus struct {
failsafeLimit float64 failsafeLimit float64
failsafeDuration time.Duration failsafeDuration time.Duration
heartbeat *plugin.Value[struct{}] heartbeat *util.Value[struct{}]
} }
type Limits struct { type Limits struct {
@ -90,7 +89,7 @@ func NewEEBus(ski string, limits Limits, root api.Circuit) (*EEBus, error) {
root: root, root: root,
uc: eebus.Instance.ControllableSystem(), uc: eebus.Instance.ControllableSystem(),
Connector: eebus.NewConnector(), Connector: eebus.NewConnector(),
heartbeat: plugin.NewValue[struct{}](2 * time.Minute), // LPC-031 heartbeat: util.NewValue[struct{}](2 * time.Minute), // LPC-031
consumptionLimit: &ucapi.LoadLimit{ consumptionLimit: &ucapi.LoadLimit{
Value: limits.ConsumptionLimit, Value: limits.ConsumptionLimit,

View file

@ -6,7 +6,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/meter/discovergy" "github.com/evcc-io/evcc/meter/discovergy"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport" "github.com/evcc-io/evcc/util/transport"
@ -74,7 +73,7 @@ func NewDiscovergyFromConfig(other map[string]interface{}) (api.Meter, error) {
})) }))
} }
dataG := plugin.Cached(func() (discovergy.Reading, error) { dataG := util.Cached(func() (discovergy.Reading, error) {
var res discovergy.Reading var res discovergy.Reading
uri := fmt.Sprintf("%s/last_reading?meterId=%s", discovergy.API, meterID) uri := fmt.Sprintf("%s/last_reading?meterId=%s", discovergy.API, meterID)
err := client.GetJSON(uri, &res) err := client.GetJSON(uri, &res)

View file

@ -8,7 +8,6 @@ import (
"github.com/enbility/eebus-go/usecases/ma/mgcp" "github.com/enbility/eebus-go/usecases/ma/mgcp"
spineapi "github.com/enbility/spine-go/api" spineapi "github.com/enbility/spine-go/api"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/server/eebus" "github.com/evcc-io/evcc/server/eebus"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
) )
@ -19,8 +18,8 @@ type EEBus struct {
*eebus.Connector *eebus.Connector
uc *eebus.UseCasesCS uc *eebus.UseCasesCS
power, energy *plugin.Value[float64] power, energy *util.Value[float64]
voltages, currents *plugin.Value[[]float64] voltages, currents *util.Value[[]float64]
} }
func init() { func init() {
@ -54,10 +53,10 @@ func NewEEBus(ski, ip string, timeout time.Duration) (*EEBus, error) {
log: util.NewLogger("eebus"), log: util.NewLogger("eebus"),
uc: eebus.Instance.ControllableSystem(), uc: eebus.Instance.ControllableSystem(),
Connector: eebus.NewConnector(), Connector: eebus.NewConnector(),
power: plugin.NewValue[float64](timeout), power: util.NewValue[float64](timeout),
energy: plugin.NewValue[float64](timeout), energy: util.NewValue[float64](timeout),
voltages: plugin.NewValue[[]float64](timeout), voltages: util.NewValue[[]float64](timeout),
currents: plugin.NewValue[[]float64](timeout), currents: util.NewValue[[]float64](timeout),
} }
if err := eebus.Instance.RegisterDevice(ski, ip, c); err != nil { if err := eebus.Instance.RegisterDevice(ski, ip, c); err != nil {

View file

@ -8,7 +8,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport" "github.com/evcc-io/evcc/util/transport"
@ -29,8 +28,8 @@ type Connection struct {
log *util.Logger log *util.Logger
*request.Helper *request.Helper
*Settings *Settings
meterG plugin.Cacheable[MethodResponse] meterG util.Cacheable[MethodResponse]
switchG plugin.Cacheable[MethodResponse] switchG util.Cacheable[MethodResponse]
} }
// NewConnection creates a new Homematic device connection. // NewConnection creates a new Homematic device connection.
@ -58,11 +57,11 @@ func NewConnection(uri, device, meterchannel, switchchannel, user, password stri
conn.Client.Transport = transport.BasicAuth(user, password, conn.Client.Transport) conn.Client.Transport = transport.BasicAuth(user, password, conn.Client.Transport)
} }
conn.switchG = plugin.ResettableCached(func() (MethodResponse, error) { conn.switchG = util.ResettableCached(func() (MethodResponse, error) {
return conn.XmlCmd("getParamset", conn.SwitchChannel, Param{CCUString: "VALUES"}) return conn.XmlCmd("getParamset", conn.SwitchChannel, Param{CCUString: "VALUES"})
}, conn.Cache) }, conn.Cache)
conn.meterG = plugin.ResettableCached(func() (MethodResponse, error) { conn.meterG = util.ResettableCached(func() (MethodResponse, error) {
return conn.XmlCmd("getParamset", conn.MeterChannel, Param{CCUString: "VALUES"}) return conn.XmlCmd("getParamset", conn.MeterChannel, Param{CCUString: "VALUES"})
}, conn.Cache) }, conn.Cache)

View file

@ -7,7 +7,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport" "github.com/evcc-io/evcc/util/transport"
@ -19,8 +18,8 @@ type Connection struct {
uri string uri string
usage string usage string
ProductType string ProductType string
dataG plugin.Cacheable[DataResponse] dataG util.Cacheable[DataResponse]
stateG plugin.Cacheable[StateResponse] stateG util.Cacheable[StateResponse]
} }
// NewConnection creates a homewizard connection // NewConnection creates a homewizard connection
@ -50,13 +49,13 @@ func NewConnection(uri string, usage string, cache time.Duration) (*Connection,
c.uri = c.uri + "/" + res.ApiVersion c.uri = c.uri + "/" + res.ApiVersion
c.ProductType = res.ProductType c.ProductType = res.ProductType
c.dataG = plugin.ResettableCached(func() (DataResponse, error) { c.dataG = util.ResettableCached(func() (DataResponse, error) {
var res DataResponse var res DataResponse
err := c.GetJSON(fmt.Sprintf("%s/data", c.uri), &res) err := c.GetJSON(fmt.Sprintf("%s/data", c.uri), &res)
return res, err return res, err
}, cache) }, cache)
c.stateG = plugin.ResettableCached(func() (StateResponse, error) { c.stateG = util.ResettableCached(func() (StateResponse, error) {
var res StateResponse var res StateResponse
err := c.GetJSON(fmt.Sprintf("%s/state", c.uri), &res) err := c.GetJSON(fmt.Sprintf("%s/state", c.uri), &res)
return res, err return res, err

View file

@ -10,7 +10,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport" "github.com/evcc-io/evcc/util/transport"
@ -63,7 +62,7 @@ func GetInstance(uri, registration, password string, cache time.Duration, essTyp
// caches the data access for the "cache" time duration // caches the data access for the "cache" time duration
// sends a new request to the pcs if the cache is expired and Data() requested // sends a new request to the pcs if the cache is expired and Data() requested
instance.dataG = plugin.Cached(instance.refreshData, cache) instance.dataG = util.Cached(instance.refreshData, cache)
// do first login if no authKey exists and uri and password exist // do first login if no authKey exists and uri and password exist
if instance.authKey == "" && instance.uri != "" && instance.password != "" { if instance.authKey == "" && instance.uri != "" && instance.password != "" {

View file

@ -13,7 +13,6 @@ import (
"github.com/andig/go-powerwall" "github.com/andig/go-powerwall"
"github.com/bogosj/tesla" "github.com/bogosj/tesla"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"golang.org/x/oauth2" "golang.org/x/oauth2"
@ -90,7 +89,7 @@ func NewPowerWall(uri, usage, user, password string, cache time.Duration, refres
m := &PowerWall{ m := &PowerWall{
client: client, client: client,
usage: strings.ToLower(usage), usage: strings.ToLower(usage),
meterG: plugin.Cached(client.GetMetersAggregates, cache), meterG: util.Cached(client.GetMetersAggregates, cache),
} }
var batteryControl bool var batteryControl bool

View file

@ -7,7 +7,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport" "github.com/evcc-io/evcc/util/transport"
@ -18,8 +17,8 @@ type Connection struct {
*request.Helper *request.Helper
uri, user, password string uri, user, password string
channels []int channels []int
statusSnsG plugin.Cacheable[StatusSNSResponse] statusSnsG util.Cacheable[StatusSNSResponse]
statusStsG plugin.Cacheable[StatusSTSResponse] statusStsG util.Cacheable[StatusSTSResponse]
} }
// NewConnection creates a Tasmota connection // NewConnection creates a Tasmota connection
@ -50,7 +49,7 @@ func NewConnection(uri, user, password string, channels []int, cache time.Durati
c.Client.Transport = request.NewTripper(log, transport.Insecure()) c.Client.Transport = request.NewTripper(log, transport.Insecure())
c.statusSnsG = plugin.ResettableCached(func() (StatusSNSResponse, error) { c.statusSnsG = util.ResettableCached(func() (StatusSNSResponse, error) {
parameters := url.Values{ parameters := url.Values{
"user": {c.user}, "user": {c.user},
"password": {c.password}, "password": {c.password},
@ -61,7 +60,7 @@ func NewConnection(uri, user, password string, channels []int, cache time.Durati
return res, err return res, err
}, cache) }, cache)
c.statusStsG = plugin.ResettableCached(func() (StatusSTSResponse, error) { c.statusStsG = util.ResettableCached(func() (StatusSTSResponse, error) {
parameters := url.Values{ parameters := url.Values{
"user": {c.user}, "user": {c.user},
"password": {c.password}, "password": {c.password},

View file

@ -10,7 +10,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
) )
@ -91,7 +90,7 @@ func NewTqEmFromConfig(other map[string]interface{}) (api.Meter, error) {
return nil, errors.New("no serial") return nil, errors.New("no serial")
} }
dataG := plugin.Cached(func() (tqemData, error) { dataG := util.Cached(func() (tqemData, error) {
var res tqemData var res tqemData
uri := fmt.Sprintf("%s/mum-webservice/data.php", base) uri := fmt.Sprintf("%s/mum-webservice/data.php", base)

View file

@ -8,7 +8,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
) )
@ -115,7 +114,7 @@ func NewTqEm420FromConfig(other map[string]interface{}) (api.Meter, error) {
base := util.DefaultScheme(strings.TrimRight(cc.URI, "/"), "http") base := util.DefaultScheme(strings.TrimRight(cc.URI, "/"), "http")
dataG := plugin.Cached(func() (TqEm420Data, error) { dataG := util.Cached(func() (TqEm420Data, error) {
var res TqEm420Data var res TqEm420Data
headers := map[string]string{ headers := map[string]string{

View file

@ -57,7 +57,7 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}
return nil, fmt.Errorf("price: %w", err) return nil, fmt.Errorf("price: %w", err)
} }
if priceG != nil { if priceG != nil {
priceG = plugin.Cached(priceG, cc.Cache) priceG = util.Cached(priceG, cc.Cache)
} }
forecastG, err := cc.Forecast.StringGetter(ctx) forecastG, err := cc.Forecast.StringGetter(ctx)

View file

@ -1,4 +1,4 @@
package plugin package util
import ( import (
"errors" "errors"

View file

@ -1,4 +1,4 @@
package plugin package util
import ( import (
"errors" "errors"

View file

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
// Provider implements the vehicle api // Provider implements the vehicle api
@ -16,7 +16,7 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, user int64, vin string, cache time.Duration) *Provider { func NewProvider(api *API, user int64, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (StatusResponse, error) { statusG: util.Cached(func() (StatusResponse, error) {
return api.Status(user, vin) return api.Status(user, vin)
}, cache), }, cache),
} }

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
const refreshTimeout = 2 * time.Minute const refreshTimeout = 2 * time.Minute
@ -28,13 +28,13 @@ func NewProvider(api *API, vehicle Vehicle, expiry, cache time.Duration) *Provid
expiry: expiry, expiry: expiry,
} }
v.statusG = plugin.Cached(func() (BluelinkVehicleStatus, error) { v.statusG = util.Cached(func() (BluelinkVehicleStatus, error) {
return v.status( return v.status(
func() (BluelinkVehicleStatusLatest, error) { return api.StatusLatest(vehicle) }, func() (BluelinkVehicleStatusLatest, error) { return api.StatusLatest(vehicle) },
) )
}, cache) }, cache)
v.statusLG = plugin.Cached(func() (BluelinkVehicleStatusLatest, error) { v.statusLG = util.Cached(func() (BluelinkVehicleStatusLatest, error) {
return api.StatusLatest(vehicle) return api.StatusLatest(vehicle)
}, cache) }, cache)

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
// Provider implements the vehicle api // Provider implements the vehicle api
@ -16,7 +16,7 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, vin string, cache time.Duration) *Provider { func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (VehicleStatus, error) { statusG: util.Cached(func() (VehicleStatus, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
actionS: func(action string) error { actionS: func(action string) error {

View file

@ -8,7 +8,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/joeshaw/carwings" "github.com/joeshaw/carwings"
@ -90,8 +89,8 @@ func NewCarWingsFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, fmt.Errorf("login failed: %w", err) return nil, fmt.Errorf("login failed: %w", err)
} }
v.statusG = plugin.Cached(v.status, cc.Cache) v.statusG = util.Cached(v.status, cc.Cache)
v.climateG = plugin.Cached(v.session.ClimateControlStatus, cc.Cache) v.climateG = util.Cached(v.session.ClimateControlStatus, cc.Cache)
return v, nil return v, nil
} }

View file

@ -7,7 +7,6 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/api/proto/pb" "github.com/evcc-io/evcc/api/proto/pb"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/cloud" "github.com/evcc-io/evcc/util/cloud"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
@ -63,7 +62,7 @@ func NewCloudFromConfig(other map[string]interface{}) (api.Vehicle, error) {
err = v.prepareVehicle() err = v.prepareVehicle()
v.chargeStateG = plugin.Cached(v.chargeState, cc.Cache) v.chargeStateG = util.Cached(v.chargeState, cc.Cache)
return v, err return v, err
} }

View file

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
) )
@ -23,10 +23,10 @@ type Provider struct {
func NewProvider(api *API, vin, pin string, expiry, cache time.Duration) *Provider { func NewProvider(api *API, vin, pin string, expiry, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (StatusResponse, error) { statusG: util.Cached(func() (StatusResponse, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
locationG: plugin.Cached(func() (LocationResponse, error) { locationG: util.Cached(func() (LocationResponse, error) {
return api.Location(vin) return api.Location(vin)
}, cache), }, cache),
action: func(action, cmd string) (ActionResponse, error) { action: func(action, cmd string) (ActionResponse, error) {
@ -37,7 +37,7 @@ func NewProvider(api *API, vin, pin string, expiry, cache time.Duration) *Provid
// use pin for refreshing // use pin for refreshing
if pin != "" { if pin != "" {
impl.statusG = plugin.Cached(func() (StatusResponse, error) { impl.statusG = util.Cached(func() (StatusResponse, error) {
return impl.status( return impl.status(
func() (StatusResponse, error) { return api.Status(vin) }, func() (StatusResponse, error) { return api.Status(vin) },
) )

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
type Provider struct { type Provider struct {
@ -14,7 +14,7 @@ type Provider struct {
func NewProvider(api *API, vin string, cache time.Duration) *Provider { func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (Vehicle, error) { statusG: util.Cached(func() (Vehicle, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
// refreshG: func() error { // refreshG: func() error {

View file

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/vehicle/ford/autonomic" "github.com/evcc-io/evcc/vehicle/ford/autonomic"
) )
@ -16,7 +16,7 @@ type Provider struct {
func NewProvider(api *autonomic.API, vin string, cache time.Duration) *Provider { func NewProvider(api *autonomic.API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (autonomic.MetricsResponse, error) { statusG: util.Cached(func() (autonomic.MetricsResponse, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
refreshG: func() error { refreshG: func() error {

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
type Provider struct { type Provider struct {
@ -15,10 +15,10 @@ type Provider struct {
func NewProvider(api *API, vin, user string, cache time.Duration) *Provider { func NewProvider(api *API, vin, user string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (StatusResponse, error) { statusG: util.Cached(func() (StatusResponse, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
positionG: plugin.Cached(func() (PositionResponse, error) { positionG: util.Cached(func() (PositionResponse, error) {
return api.Position(vin) return api.Position(vin)
}, cache), }, cache),
chargeS: func(enable bool) error { chargeS: func(enable bool) error {

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
type Provider struct { type Provider struct {
@ -13,7 +13,7 @@ type Provider struct {
func NewProvider(api *API, vin string, cache time.Duration) *Provider { func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
dataG: plugin.Cached(func() (StatusResponse, error) { dataG: util.Cached(func() (StatusResponse, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
} }

View file

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
const refreshTimeout = 2 * time.Minute const refreshTimeout = 2 * time.Minute
@ -28,7 +28,7 @@ func NewProvider(api *API, vin, version string, expiry, cache time.Duration) *Pr
expiry: expiry, expiry: expiry,
} }
impl.statusG = plugin.Cached(func() (StatusResponse, error) { impl.statusG = util.Cached(func() (StatusResponse, error) {
return impl.status( return impl.status(
func() (StatusResponse, error) { return api.BatteryStatus(vin, version) }, func() (StatusResponse, error) { return api.BatteryStatus(vin, version) },
func() (ActionResponse, error) { return api.RefreshRequest(vin, "RefreshBatteryStatus") }, func() (ActionResponse, error) { return api.RefreshRequest(vin, "RefreshBatteryStatus") },

View file

@ -10,7 +10,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/vehicle/niu" "github.com/evcc-io/evcc/vehicle/niu"
@ -62,7 +61,7 @@ func NewNiuFromConfig(other map[string]interface{}) (api.Vehicle, error) {
serial: strings.ToUpper(cc.Serial), serial: strings.ToUpper(cc.Serial),
} }
v.apiG = plugin.Cached(v.batteryAPI, cc.Cache) v.apiG = util.Cached(v.batteryAPI, cc.Cache)
return v, nil return v, nil
} }

View file

@ -9,7 +9,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/vehicle/ovms" "github.com/evcc-io/evcc/vehicle/ovms"
@ -59,9 +58,9 @@ func NewOvmsFromConfig(other map[string]interface{}) (api.Vehicle, error) {
cache: cc.Cache, cache: cc.Cache,
} }
v.chargeG = plugin.Cached(v.batteryAPI, cc.Cache) v.chargeG = util.Cached(v.batteryAPI, cc.Cache)
v.statusG = plugin.Cached(v.statusAPI, cc.Cache) v.statusG = util.Cached(v.statusAPI, cc.Cache)
v.locationG = plugin.Cached(v.locationAPI, cc.Cache) v.locationG = util.Cached(v.locationAPI, cc.Cache)
v.Jar, _ = cookiejar.New(&cookiejar.Options{ v.Jar, _ = cookiejar.New(&cookiejar.Options{
PublicSuffixList: publicsuffix.List, PublicSuffixList: publicsuffix.List,

View file

@ -5,7 +5,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
) )
@ -16,12 +15,12 @@ type Provider struct {
func NewProvider(log *util.Logger, api *API, vin string, timeout, cache time.Duration) *Provider { func NewProvider(log *util.Logger, api *API, vin string, timeout, cache time.Duration) *Provider {
v := &Provider{ v := &Provider{
statusG: plugin.Cached(func() (BatteryData, error) { statusG: util.Cached(func() (BatteryData, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
return api.Status(ctx, vin) return api.Status(ctx, vin)
}, cache), }, cache),
odoG: plugin.Cached(func() (OdometerData, error) { odoG: util.Cached(func() (OdometerData, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
return api.Odometer(ctx, vin) return api.Odometer(ctx, vin)

View file

@ -5,7 +5,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
) )
@ -19,11 +18,11 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(log *util.Logger, connect *API, emobility *EmobilityAPI, vin, carModel string, cache time.Duration) *Provider { func NewProvider(log *util.Logger, connect *API, emobility *EmobilityAPI, vin, carModel string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (StatusResponse, error) { statusG: util.Cached(func() (StatusResponse, error) {
return connect.Status(vin) return connect.Status(vin)
}, cache), }, cache),
emobilityG: plugin.Cached(func() (EmobilityResponse, error) { emobilityG: util.Cached(func() (EmobilityResponse, error) {
if carModel != "" { if carModel != "" {
return emobility.Status(vin, carModel) return emobility.Status(vin, carModel)
} }

View file

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
// Provider is an api.Vehicle implementation for PSA cars // Provider is an api.Vehicle implementation for PSA cars
@ -16,7 +16,7 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, vid string, cache time.Duration) *Provider { func NewProvider(api *API, vid string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (Status, error) { statusG: util.Cached(func() (Status, error) {
return api.Status(vid) return api.Status(vid)
}, cache), }, cache),
} }

View file

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/vehicle/renault/kamereon" "github.com/evcc-io/evcc/vehicle/renault/kamereon"
) )
@ -25,13 +25,13 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *kamereon.API, accountID, vin string, alternativeWakeup bool, cache time.Duration) *Provider { func NewProvider(api *kamereon.API, accountID, vin string, alternativeWakeup bool, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
batteryG: plugin.Cached(func() (kamereon.Response, error) { batteryG: util.Cached(func() (kamereon.Response, error) {
return api.Battery(accountID, vin) return api.Battery(accountID, vin)
}, cache), }, cache),
cockpitG: plugin.Cached(func() (kamereon.Response, error) { cockpitG: util.Cached(func() (kamereon.Response, error) {
return api.Cockpit(accountID, vin) return api.Cockpit(accountID, vin)
}, cache), }, cache),
hvacG: plugin.Cached(func() (kamereon.Response, error) { hvacG: util.Cached(func() (kamereon.Response, error) {
return api.Hvac(accountID, vin) return api.Hvac(accountID, vin)
}, cache), }, cache),
wakeup: func() (kamereon.Response, error) { wakeup: func() (kamereon.Response, error) {

View file

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/vehicle/saic/requests" "github.com/evcc-io/evcc/vehicle/saic/requests"
) )
@ -25,14 +25,14 @@ var TargetSocVals = [...]int{0, 40, 50, 60, 70, 80, 90, 100}
// Provider implements the vehicle api // Provider implements the vehicle api
type Provider struct { type Provider struct {
status plugin.Cacheable[requests.ChargeStatus] status util.Cacheable[requests.ChargeStatus]
wakeup func() error wakeup func() error
} }
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, vin string, cache time.Duration) *Provider { func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
status: plugin.ResettableCached(func() (requests.ChargeStatus, error) { status: util.ResettableCached(func() (requests.ChargeStatus, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
wakeup: func() error { wakeup: func() error {

View file

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
// Provider is an api.Vehicle implementation for Seat Cupra cars // Provider is an api.Vehicle implementation for Seat Cupra cars
@ -19,13 +19,13 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, userID, vin string, cache time.Duration) *Provider { func NewProvider(api *API, userID, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (Status, error) { statusG: util.Cached(func() (Status, error) {
return api.Status(userID, vin) return api.Status(userID, vin)
}, cache), }, cache),
positionG: plugin.Cached(func() (Position, error) { positionG: util.Cached(func() (Position, error) {
return api.ParkingPosition(vin) return api.ParkingPosition(vin)
}, cache), }, cache),
milageG: plugin.Cached(func() (Mileage, error) { milageG: util.Cached(func() (Mileage, error) {
return api.Mileage(vin) return api.Mileage(vin)
}, cache), }, cache),
action: func(action, cmd string) error { action: func(action, cmd string) error {

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
// Provider implements the vehicle api // Provider implements the vehicle api
@ -20,16 +20,16 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, vin string, cache time.Duration) *Provider { func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (StatusResponse, error) { statusG: util.Cached(func() (StatusResponse, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
chargerG: plugin.Cached(func() (ChargerResponse, error) { chargerG: util.Cached(func() (ChargerResponse, error) {
return api.Charger(vin) return api.Charger(vin)
}, cache), }, cache),
climateG: plugin.Cached(func() (ClimaterResponse, error) { climateG: util.Cached(func() (ClimaterResponse, error) {
return api.Climater(vin) return api.Climater(vin)
}, cache), }, cache),
settingsG: plugin.Cached(func() (SettingsResponse, error) { settingsG: util.Cached(func() (SettingsResponse, error) {
return api.Settings(vin) return api.Settings(vin)
}, cache), }, cache),
action: func(action, value string) error { action: func(action, value string) error {

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
// Provider implements the vehicle api // Provider implements the vehicle api
@ -18,16 +18,16 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, vin string, cache time.Duration) *Provider { func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (StatusResponse, error) { statusG: util.Cached(func() (StatusResponse, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
chargerG: plugin.Cached(func() (ChargerResponse, error) { chargerG: util.Cached(func() (ChargerResponse, error) {
return api.Charger(vin) return api.Charger(vin)
}, cache), }, cache),
// climateG: plugin.Cached(func() (interface{}, error) { // climateG: util.Cached(func() (interface{}, error) {
// return api.Climater(vin) // return api.Climater(vin)
// }, cache), // }, cache),
settingsG: plugin.Cached(func() (SettingsResponse, error) { settingsG: util.Cached(func() (SettingsResponse, error) {
return api.Settings(vin) return api.Settings(vin)
}, cache), }, cache),
action: func(action, value string) error { action: func(action, value string) error {

View file

@ -4,7 +4,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
) )
@ -16,7 +15,7 @@ type Provider struct {
func NewProvider(log *util.Logger, api *API, vin string, cache time.Duration) *Provider { func NewProvider(log *util.Logger, api *API, vin string, cache time.Duration) *Provider {
v := &Provider{ v := &Provider{
statusG: plugin.Cached(func() (VehicleStatus, error) { statusG: util.Cached(func() (VehicleStatus, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
} }

View file

@ -5,7 +5,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
) )
@ -21,7 +20,7 @@ func NewProvider(log *util.Logger, api *API, vin string, expiry, cache time.Dura
expiry: expiry, expiry: expiry,
} }
v.statusG = plugin.Cached(func() (StatusResponse, error) { v.statusG = util.Cached(func() (StatusResponse, error) {
return v.status( return v.status(
func() (StatusResponse, error) { return api.Status(vin) }, func() (StatusResponse, error) { return api.Status(vin) },
func() (StatusResponse, error) { return api.Refresh(vin) }, func() (StatusResponse, error) { return api.Refresh(vin) },

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/tesla-proxy-client" "github.com/evcc-io/tesla-proxy-client"
) )
@ -15,7 +15,7 @@ type Provider struct {
func NewProvider(vehicle *tesla.Vehicle, cache time.Duration) *Provider { func NewProvider(vehicle *tesla.Vehicle, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
dataG: plugin.Cached(func() (*tesla.VehicleData, error) { dataG: util.Cached(func() (*tesla.VehicleData, error) {
res, err := vehicle.Data() res, err := vehicle.Data()
return res, apiError(err) return res, apiError(err)
}, cache), }, cache),

View file

@ -26,7 +26,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/oauth" "github.com/evcc-io/evcc/util/oauth"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
@ -120,7 +119,7 @@ func NewTronityFromConfig(other map[string]interface{}) (api.Vehicle, error) {
} }
v.vid = vehicle.ID v.vid = vehicle.ID
v.bulkG = plugin.Cached(v.bulk, cc.Cache) v.bulkG = util.Cached(v.bulk, cc.Cache)
var status func() (api.ChargeStatus, error) var status func() (api.ChargeStatus, error)
if slices.Contains(vehicle.Scopes, tronity.ReadCharge) { if slices.Contains(vehicle.Scopes, tronity.ReadCharge) {

View file

@ -5,7 +5,6 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport" "github.com/evcc-io/evcc/util/transport"
@ -64,7 +63,7 @@ func NewVolvoFromConfig(other map[string]interface{}) (api.Vehicle, error) {
}), }),
} }
v.statusG = plugin.Cached(v.StatusRequest, cc.Cache) v.statusG = util.Cached(v.StatusRequest, cc.Cache)
var err error var err error
v.vin, err = ensureVehicle(cc.VIN, v.Vehicles) v.vin, err = ensureVehicle(cc.VIN, v.Vehicles)

View file

@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
// Provider implements the vehicle api // Provider implements the vehicle api
@ -15,7 +15,7 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, vin string, cache time.Duration) *Provider { func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (RechargeStatus, error) { statusG: util.Cached(func() (RechargeStatus, error) {
return api.RechargeStatus(vin) return api.RechargeStatus(vin)
}, cache), }, cache),
} }

View file

@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
// Provider is an api.Vehicle implementation for VW ID cars // Provider is an api.Vehicle implementation for VW ID cars
@ -18,7 +18,7 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, vin string, cache time.Duration) *Provider { func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
statusG: plugin.Cached(func() (Status, error) { statusG: util.Cached(func() (Status, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
action: func(action, value string) error { action: func(action, value string) error {

View file

@ -11,7 +11,7 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
"github.com/samber/lo" "github.com/samber/lo"
) )
@ -28,16 +28,16 @@ type Provider struct {
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, vin string, cache time.Duration) *Provider { func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
chargerG: plugin.Cached(func() (ChargerResponse, error) { chargerG: util.Cached(func() (ChargerResponse, error) {
return api.Charger(vin) return api.Charger(vin)
}, cache), }, cache),
statusG: plugin.Cached(func() (StatusResponse, error) { statusG: util.Cached(func() (StatusResponse, error) {
return api.Status(vin) return api.Status(vin)
}, cache), }, cache),
climateG: plugin.Cached(func() (ClimaterResponse, error) { climateG: util.Cached(func() (ClimaterResponse, error) {
return api.Climater(vin) return api.Climater(vin)
}, cache), }, cache),
positionG: plugin.Cached(func() (PositionResponse, error) { positionG: util.Cached(func() (PositionResponse, error) {
return api.Position(vin) return api.Position(vin)
}, cache), }, cache),
action: func(action, value string) error { action: func(action, value string) error {

View file

@ -4,18 +4,18 @@ import (
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/util"
) )
// Provider implements the vehicle api // Provider implements the vehicle api
type Provider struct { type Provider struct {
status plugin.Cacheable[State] status util.Cacheable[State]
} }
// NewProvider creates a vehicle api provider // NewProvider creates a vehicle api provider
func NewProvider(api *API, unitId string, cache time.Duration) *Provider { func NewProvider(api *API, unitId string, cache time.Duration) *Provider {
impl := &Provider{ impl := &Provider{
status: plugin.ResettableCached(func() (State, error) { status: util.ResettableCached(func() (State, error) {
return api.Status(unitId) return api.Status(unitId)
}, cache), }, cache),
} }