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

View file

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

View file

@ -15,7 +15,6 @@ import (
"github.com/enbility/spine-go/model"
"github.com/evcc-io/evcc/api"
"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/util"
"github.com/samber/lo"
@ -88,7 +87,7 @@ func NewEEBus(ski, ip string, hasMeter, hasChargedEnergy, vasVW bool) (api.Charg
}
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 {
return nil, err

View file

@ -8,7 +8,6 @@ import (
"github.com/evcc-io/evcc/api"
"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/request"
)
@ -20,7 +19,7 @@ type EVSEWifi struct {
alwaysActive bool
current int64 // current will always be the physical value sent to the API
hires bool
paramG plugin.Cacheable[evse.ListEntry]
paramG util.Cacheable[evse.ListEntry]
}
func init() {
@ -122,7 +121,7 @@ func NewEVSEWifi(uri string, cache time.Duration) (*EVSEWifi, error) {
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
uri := fmt.Sprintf("%s/getParameters", wb.uri)
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/ecb1"
"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/request"
"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
wb.meterG = plugin.Cached(func() (ecb1.Meter, error) {
wb.meterG = util.Cached(func() (ecb1.Meter, error) {
var res struct {
Meter struct {
ecb1.Meter

View file

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

View file

@ -6,7 +6,6 @@ import (
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/meter/mystrom"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util"
)
@ -21,7 +20,7 @@ func init() {
type MyStrom struct {
*switchSocket
conn *mystrom.Connection
reportG plugin.Cacheable[mystrom.Report]
reportG util.Cacheable[mystrom.Report]
}
// 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.reportG = plugin.ResettableCached(c.conn.Report, cc.Cache)
c.reportG = util.ResettableCached(c.conn.Report, cc.Cache)
return c, nil
}

View file

@ -9,7 +9,6 @@ import (
"github.com/evcc-io/evcc/api"
"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/request"
)
@ -23,8 +22,8 @@ type NRGKickConnect struct {
mac string
password string
enabled bool
settingsG plugin.Cacheable[connect.Settings]
measurementsG plugin.Cacheable[connect.Measurements]
settingsG util.Cacheable[connect.Settings]
measurementsG util.Cacheable[connect.Measurements]
}
func init() {
@ -56,7 +55,7 @@ func NewNRGKickConnect(uri, mac, password string, cache time.Duration) (*NRGKick
password: password,
}
nrg.settingsG = plugin.ResettableCached(func() (connect.Settings, error) {
nrg.settingsG = util.ResettableCached(func() (connect.Settings, error) {
var res connect.Settings
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
}, cache)
nrg.measurementsG = plugin.ResettableCached(func() (connect.Measurements, error) {
nrg.measurementsG = util.ResettableCached(func() (connect.Measurements, error) {
var res connect.Measurements
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/charger/openevse"
"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/transport"
@ -20,7 +19,7 @@ import (
type OpenEVSE struct {
*request.Helper
uri string
statusG plugin.Cacheable[openevse.Status]
statusG util.Cacheable[openevse.Status]
current int
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.statusG = plugin.ResettableCached(func() (openevse.Status, error) {
c.statusG = util.ResettableCached(func() (openevse.Status, error) {
var res openevse.Status
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/charger/openwb/pro"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
)
@ -24,7 +23,7 @@ type OpenWBPro struct {
*request.Helper
uri string
current float64
statusG plugin.Cacheable[pro.Status]
statusG util.Cacheable[pro.Status]
}
// 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
}
wb.statusG = plugin.ResettableCached(func() (pro.Status, error) {
wb.statusG = util.ResettableCached(func() (pro.Status, error) {
var res pro.Status
uri := fmt.Sprintf("%s/%s", wb.uri, "connect.php")
err := wb.GetJSON(uri, &res)

View file

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

View file

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

View file

@ -9,7 +9,6 @@ import (
"github.com/evcc-io/evcc/api"
"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/request"
)
@ -73,7 +72,7 @@ func NewTwc3FromConfig(other map[string]interface{}) (api.Charger, error) {
client := request.NewHelper(util.NewLogger("twc3"))
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
err := client.GetJSON(uri, &res)
return res, err

View file

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

View file

@ -28,7 +28,6 @@ import (
"github.com/coreos/go-oidc/v3/oidc"
"github.com/evcc-io/evcc/api"
"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/request"
"github.com/evcc-io/evcc/util/sponsor"
@ -43,7 +42,7 @@ import (
type Zaptec struct {
*request.Helper
log *util.Logger
statusG plugin.Cacheable[zaptec.StateResponse]
statusG util.Cacheable[zaptec.StateResponse]
id string
enabled bool
priority bool
@ -91,7 +90,7 @@ func NewZaptec(user, password, id string, priority bool, cache time.Duration) (a
}
// setup cached values
c.statusG = plugin.ResettableCached(func() (zaptec.StateResponse, error) {
c.statusG = util.ResettableCached(func() (zaptec.StateResponse, error) {
var res zaptec.StateResponse
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/vehicle"
"github.com/evcc-io/evcc/core/wrapper"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/push"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/config"
@ -457,7 +456,7 @@ func (lp *Loadpoint) evChargeStopHandler() {
}
// soc update reset
plugin.ResetCached()
util.ResetCached()
lp.socUpdated = time.Time{}
// 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/soc"
"github.com/evcc-io/evcc/core/vehicle"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util"
)
const (
@ -234,7 +234,7 @@ func (lp *Loadpoint) vehicleUnidentified() bool {
select {
case <-lp.vehicleDetectTicker.C:
lp.log.DEBUG.Println("vehicle api refresh")
plugin.ResetCached()
util.ResetCached()
default:
}
@ -260,7 +260,7 @@ func (lp *Loadpoint) vehicleDefaultOrDetect() {
func (lp *Loadpoint) startVehicleDetection() {
// flush all vehicles before detection starts
lp.log.DEBUG.Println("vehicle api refresh")
plugin.ResetCached()
util.ResetCached()
lp.vehicleDetect = lp.clock.Now()
lp.vehicleDetectTicker = lp.clock.Ticker(vehicleDetectInterval)

View file

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

View file

@ -6,7 +6,6 @@ import (
"github.com/evcc-io/evcc/api"
"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/request"
"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
uri := fmt.Sprintf("%s/last_reading?meterId=%s", discovergy.API, meterID)
err := client.GetJSON(uri, &res)

View file

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

View file

@ -8,7 +8,6 @@ import (
"strings"
"time"
"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/transport"
@ -29,8 +28,8 @@ type Connection struct {
log *util.Logger
*request.Helper
*Settings
meterG plugin.Cacheable[MethodResponse]
switchG plugin.Cacheable[MethodResponse]
meterG util.Cacheable[MethodResponse]
switchG util.Cacheable[MethodResponse]
}
// 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.switchG = plugin.ResettableCached(func() (MethodResponse, error) {
conn.switchG = util.ResettableCached(func() (MethodResponse, error) {
return conn.XmlCmd("getParamset", conn.SwitchChannel, Param{CCUString: "VALUES"})
}, 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"})
}, conn.Cache)

View file

@ -7,7 +7,6 @@ import (
"strings"
"time"
"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/transport"
@ -19,8 +18,8 @@ type Connection struct {
uri string
usage string
ProductType string
dataG plugin.Cacheable[DataResponse]
stateG plugin.Cacheable[StateResponse]
dataG util.Cacheable[DataResponse]
stateG util.Cacheable[StateResponse]
}
// 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.ProductType = res.ProductType
c.dataG = plugin.ResettableCached(func() (DataResponse, error) {
c.dataG = util.ResettableCached(func() (DataResponse, error) {
var res DataResponse
err := c.GetJSON(fmt.Sprintf("%s/data", c.uri), &res)
return res, err
}, cache)
c.stateG = plugin.ResettableCached(func() (StateResponse, error) {
c.stateG = util.ResettableCached(func() (StateResponse, error) {
var res StateResponse
err := c.GetJSON(fmt.Sprintf("%s/state", c.uri), &res)
return res, err

View file

@ -10,7 +10,6 @@ import (
"sync"
"time"
"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/transport"
@ -63,7 +62,7 @@ func GetInstance(uri, registration, password string, cache time.Duration, essTyp
// caches the data access for the "cache" time duration
// 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
if instance.authKey == "" && instance.uri != "" && instance.password != "" {

View file

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

View file

@ -7,7 +7,6 @@ import (
"strings"
"time"
"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/transport"
@ -18,8 +17,8 @@ type Connection struct {
*request.Helper
uri, user, password string
channels []int
statusSnsG plugin.Cacheable[StatusSNSResponse]
statusStsG plugin.Cacheable[StatusSTSResponse]
statusSnsG util.Cacheable[StatusSNSResponse]
statusStsG util.Cacheable[StatusSTSResponse]
}
// 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.statusSnsG = plugin.ResettableCached(func() (StatusSNSResponse, error) {
c.statusSnsG = util.ResettableCached(func() (StatusSNSResponse, error) {
parameters := url.Values{
"user": {c.user},
"password": {c.password},
@ -61,7 +60,7 @@ func NewConnection(uri, user, password string, channels []int, cache time.Durati
return res, err
}, cache)
c.statusStsG = plugin.ResettableCached(func() (StatusSTSResponse, error) {
c.statusStsG = util.ResettableCached(func() (StatusSTSResponse, error) {
parameters := url.Values{
"user": {c.user},
"password": {c.password},

View file

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

View file

@ -8,7 +8,6 @@ import (
"time"
"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"
)
@ -115,7 +114,7 @@ func NewTqEm420FromConfig(other map[string]interface{}) (api.Meter, error) {
base := util.DefaultScheme(strings.TrimRight(cc.URI, "/"), "http")
dataG := plugin.Cached(func() (TqEm420Data, error) {
dataG := util.Cached(func() (TqEm420Data, error) {
var res TqEm420Data
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)
}
if priceG != nil {
priceG = plugin.Cached(priceG, cc.Cache)
priceG = util.Cached(priceG, cc.Cache)
}
forecastG, err := cc.Forecast.StringGetter(ctx)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,7 +7,7 @@ import (
"time"
"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"
)
@ -23,10 +23,10 @@ type Provider struct {
func NewProvider(api *API, vin, pin string, expiry, cache time.Duration) *Provider {
impl := &Provider{
statusG: plugin.Cached(func() (StatusResponse, error) {
statusG: util.Cached(func() (StatusResponse, error) {
return api.Status(vin)
}, cache),
locationG: plugin.Cached(func() (LocationResponse, error) {
locationG: util.Cached(func() (LocationResponse, error) {
return api.Location(vin)
}, cache),
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
if pin != "" {
impl.statusG = plugin.Cached(func() (StatusResponse, error) {
impl.statusG = util.Cached(func() (StatusResponse, error) {
return impl.status(
func() (StatusResponse, error) { return api.Status(vin) },
)

View file

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

View file

@ -5,7 +5,7 @@ import (
"time"
"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"
)
@ -16,7 +16,7 @@ type Provider struct {
func NewProvider(api *autonomic.API, vin string, cache time.Duration) *Provider {
impl := &Provider{
statusG: plugin.Cached(func() (autonomic.MetricsResponse, error) {
statusG: util.Cached(func() (autonomic.MetricsResponse, error) {
return api.Status(vin)
}, cache),
refreshG: func() error {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,7 +5,6 @@ import (
"time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"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 {
v := &Provider{
statusG: plugin.Cached(func() (BatteryData, error) {
statusG: util.Cached(func() (BatteryData, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return api.Status(ctx, vin)
}, cache),
odoG: plugin.Cached(func() (OdometerData, error) {
odoG: util.Cached(func() (OdometerData, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return api.Odometer(ctx, vin)

View file

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

View file

@ -5,7 +5,7 @@ import (
"time"
"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
@ -16,7 +16,7 @@ type Provider struct {
// NewProvider creates a vehicle api provider
func NewProvider(api *API, vid string, cache time.Duration) *Provider {
impl := &Provider{
statusG: plugin.Cached(func() (Status, error) {
statusG: util.Cached(func() (Status, error) {
return api.Status(vid)
}, cache),
}

View file

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

View file

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

View file

@ -5,7 +5,7 @@ import (
"time"
"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
@ -19,13 +19,13 @@ type Provider struct {
// NewProvider creates a vehicle api provider
func NewProvider(api *API, userID, vin string, cache time.Duration) *Provider {
impl := &Provider{
statusG: plugin.Cached(func() (Status, error) {
statusG: util.Cached(func() (Status, error) {
return api.Status(userID, vin)
}, cache),
positionG: plugin.Cached(func() (Position, error) {
positionG: util.Cached(func() (Position, error) {
return api.ParkingPosition(vin)
}, cache),
milageG: plugin.Cached(func() (Mileage, error) {
milageG: util.Cached(func() (Mileage, error) {
return api.Mileage(vin)
}, cache),
action: func(action, cmd string) error {

View file

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

View file

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

View file

@ -4,7 +4,6 @@ import (
"time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"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 {
v := &Provider{
statusG: plugin.Cached(func() (VehicleStatus, error) {
statusG: util.Cached(func() (VehicleStatus, error) {
return api.Status(vin)
}, cache),
}

View file

@ -5,7 +5,6 @@ import (
"time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"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,
}
v.statusG = plugin.Cached(func() (StatusResponse, error) {
v.statusG = util.Cached(func() (StatusResponse, error) {
return v.status(
func() (StatusResponse, error) { return api.Status(vin) },
func() (StatusResponse, error) { return api.Refresh(vin) },

View file

@ -4,7 +4,7 @@ import (
"time"
"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"
)
@ -15,7 +15,7 @@ type Provider struct {
func NewProvider(vehicle *tesla.Vehicle, cache time.Duration) *Provider {
impl := &Provider{
dataG: plugin.Cached(func() (*tesla.VehicleData, error) {
dataG: util.Cached(func() (*tesla.VehicleData, error) {
res, err := vehicle.Data()
return res, apiError(err)
}, cache),

View file

@ -26,7 +26,6 @@ import (
"time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/plugin"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/oauth"
"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.bulkG = plugin.Cached(v.bulk, cc.Cache)
v.bulkG = util.Cached(v.bulk, cc.Cache)
var status func() (api.ChargeStatus, error)
if slices.Contains(vehicle.Scopes, tronity.ReadCharge) {

View file

@ -5,7 +5,6 @@ import (
"time"
"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/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
v.vin, err = ensureVehicle(cc.VIN, v.Vehicles)

View file

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

View file

@ -6,7 +6,7 @@ import (
"time"
"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
@ -18,7 +18,7 @@ type Provider struct {
// NewProvider creates a vehicle api provider
func NewProvider(api *API, vin string, cache time.Duration) *Provider {
impl := &Provider{
statusG: plugin.Cached(func() (Status, error) {
statusG: util.Cached(func() (Status, error) {
return api.Status(vin)
}, cache),
action: func(action, value string) error {

View file

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

View file

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