Skip to content

Commit

Permalink
chore: concistently name cache getters (evcc-io#10119)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Sep 30, 2023
1 parent ff558c3 commit c929e89
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 85 deletions.
22 changes: 11 additions & 11 deletions charger/daheimladen.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type DaheimLaden struct {
idTag string
token string
transactionID int32
statusCache provider.Cacheable[daheimladen.GetLatestStatus]
meterCache provider.Cacheable[daheimladen.GetLatestMeterValueResponse]
statusG provider.Cacheable[daheimladen.GetLatestStatus]
meterG provider.Cacheable[daheimladen.GetLatestMeterValueResponse]
cache time.Duration
}

Expand Down Expand Up @@ -67,13 +67,13 @@ func NewDaheimLaden(token, stationID string, cache time.Duration) (*DaheimLaden,
Base: c.Client.Transport,
}

c.statusCache = provider.ResettableCached(func() (daheimladen.GetLatestStatus, error) {
c.statusG = provider.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.meterCache = provider.ResettableCached(func() (daheimladen.GetLatestMeterValueResponse, error) {
c.meterG = provider.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
Expand All @@ -84,13 +84,13 @@ func NewDaheimLaden(token, stationID string, cache time.Duration) (*DaheimLaden,

// reset cache
func (c *DaheimLaden) reset() {
c.statusCache.Reset()
c.meterCache.Reset()
c.statusG.Reset()
c.meterG.Reset()
}

// Status implements the api.Charger interface
func (c *DaheimLaden) Status() (api.ChargeStatus, error) {
res, err := c.statusCache.Get()
res, err := c.statusG.Get()
if err != nil {
return api.StatusNone, err
}
Expand All @@ -112,7 +112,7 @@ func (c *DaheimLaden) Status() (api.ChargeStatus, error) {

// Enabled implements the api.Charger interface
func (c *DaheimLaden) Enabled() (bool, error) {
res, err := c.statusCache.Get()
res, err := c.statusG.Get()
return res.Status == string(daheimladen.CHARGING), err
}

Expand Down Expand Up @@ -193,22 +193,22 @@ var _ api.Meter = (*DaheimLaden)(nil)

// CurrentPower implements the api.Meter interface
func (c *DaheimLaden) CurrentPower() (float64, error) {
res, err := c.meterCache.Get()
res, err := c.meterG.Get()
return float64(res.ActivePowerImport * 1e3), err
}

var _ api.MeterEnergy = (*DaheimLaden)(nil)

// TotalEnergy implements the api.MeterMeterEnergy interface
func (c *DaheimLaden) TotalEnergy() (float64, error) {
res, err := c.meterCache.Get()
res, err := c.meterG.Get()
return float64(res.EnergyActiveImportRegister), err
}

var _ api.PhaseCurrents = (*DaheimLaden)(nil)

// Currents implements the api.PhaseCurrents interface
func (c *DaheimLaden) Currents() (float64, float64, float64, error) {
res, err := c.meterCache.Get()
res, err := c.meterG.Get()
return float64(res.CurrentImportPhaseL1), float64(res.CurrentImportPhaseL2), float64(res.CurrentImportPhaseL3), err
}
26 changes: 13 additions & 13 deletions charger/openwb-pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func init() {
// OpenWBPro charger implementation
type OpenWBPro struct {
*request.Helper
uri string
current float64
statusCache provider.Cacheable[pro.Status]
uri string
current float64
statusG provider.Cacheable[pro.Status]
}

// NewOpenWBProFromConfig creates a OpenWBPro charger from generic config
Expand Down Expand Up @@ -52,7 +52,7 @@ func NewOpenWBPro(uri string, cache time.Duration) (*OpenWBPro, error) {
current: 6, // 6A defined value
}

wb.statusCache = provider.ResettableCached(func() (pro.Status, error) {
wb.statusG = provider.ResettableCached(func() (pro.Status, error) {
var res pro.Status
uri := fmt.Sprintf("%s/%s", wb.uri, "connect.php")
err := wb.GetJSON(uri, &res)
Expand All @@ -66,7 +66,7 @@ func NewOpenWBPro(uri string, cache time.Duration) (*OpenWBPro, error) {

func (wb *OpenWBPro) heartbeat(log *util.Logger) {
for range time.Tick(30 * time.Second) {
if _, err := wb.statusCache.Get(); err != nil {
if _, err := wb.statusG.Get(); err != nil {
log.ERROR.Printf("heartbeat: %v", err)
}
}
Expand All @@ -77,15 +77,15 @@ func (wb *OpenWBPro) set(payload string) error {
resp, err := wb.Post(uri, "application/x-www-form-urlencoded", strings.NewReader(payload))
if err == nil {
resp.Body.Close()
wb.statusCache.Reset()
wb.statusG.Reset()
}

return err
}

// Status implements the api.Charger interface
func (wb *OpenWBPro) Status() (api.ChargeStatus, error) {
resp, err := wb.statusCache.Get()
resp, err := wb.statusG.Get()
if err != nil {
return api.StatusNone, err
}
Expand All @@ -103,7 +103,7 @@ func (wb *OpenWBPro) Status() (api.ChargeStatus, error) {

// Enabled implements the api.Charger interface
func (wb *OpenWBPro) Enabled() (bool, error) {
res, err := wb.statusCache.Get()
res, err := wb.statusG.Get()
return res.OfferedCurrent > 0, err
}

Expand Down Expand Up @@ -137,23 +137,23 @@ var _ api.Meter = (*OpenWBPro)(nil)

// CurrentPower implements the api.Meter interface
func (wb *OpenWBPro) CurrentPower() (float64, error) {
res, err := wb.statusCache.Get()
res, err := wb.statusG.Get()
return res.PowerAll, err
}

var _ api.MeterEnergy = (*OpenWBPro)(nil)

// TotalEnergy implements the api.MeterEnergy interface
func (wb *OpenWBPro) TotalEnergy() (float64, error) {
res, err := wb.statusCache.Get()
res, err := wb.statusG.Get()
return res.Imported / 1e3, err
}

var _ api.PhaseCurrents = (*OpenWBPro)(nil)

// Currents implements the api.PhaseCurrents interface
func (wb *OpenWBPro) Currents() (float64, float64, float64, error) {
res, err := wb.statusCache.Get()
res, err := wb.statusG.Get()
if err != nil {
return 0, 0, 0, err
}
Expand All @@ -169,7 +169,7 @@ var _ api.Battery = (*OpenWBPro)(nil)

// Soc implements the api.Battery interface
func (wb *OpenWBPro) Soc() (float64, error) {
res, err := wb.statusCache.Get()
res, err := wb.statusG.Get()
if err != nil {
return 0, err
}
Expand All @@ -192,7 +192,7 @@ var _ api.Identifier = (*OpenWBPro)(nil)

// Identify implements the api.Identifier interface
func (wb *OpenWBPro) Identify() (string, error) {
res, err := wb.statusCache.Get()
res, err := wb.statusG.Get()
if err != nil || res.VehicleID == "--" {
return "", err
}
Expand Down
24 changes: 12 additions & 12 deletions charger/smaevcharger.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ import (
// smaevchager charger implementation
type Smaevcharger struct {
*request.Helper
log *util.Logger
uri string // 192.168.XXX.XXX
cache time.Duration
oldstate float64
measurementCache provider.Cacheable[[]smaevcharger.Measurements]
parameterCache provider.Cacheable[[]smaevcharger.Parameters]
log *util.Logger
uri string // 192.168.XXX.XXX
cache time.Duration
oldstate float64
measurementG provider.Cacheable[[]smaevcharger.Measurements]
parameterG provider.Cacheable[[]smaevcharger.Parameters]
}

func init() {
Expand Down Expand Up @@ -95,8 +95,8 @@ func NewSmaevcharger(uri, user, password string, cache time.Duration) (api.Charg
}

// setup cached values
wb.measurementCache = provider.ResettableCached(wb._measurementData, wb.cache)
wb.parameterCache = provider.ResettableCached(wb._parameterData, wb.cache)
wb.measurementG = provider.ResettableCached(wb._measurementData, wb.cache)
wb.parameterG = provider.ResettableCached(wb._parameterData, wb.cache)

ts, err := smaevcharger.TokenSource(log, wb.uri, user, password)
if err != nil {
Expand Down Expand Up @@ -268,8 +268,8 @@ func (wb *Smaevcharger) Currents() (float64, float64, float64, error) {

// reset cache
func (wb *Smaevcharger) reset() {
wb.measurementCache.Reset()
wb.parameterCache.Reset()
wb.measurementG.Reset()
wb.parameterG.Reset()
}

func (wb *Smaevcharger) _measurementData() ([]smaevcharger.Measurements, error) {
Expand Down Expand Up @@ -299,7 +299,7 @@ func (wb *Smaevcharger) _parameterData() ([]smaevcharger.Parameters, error) {
}

func (wb *Smaevcharger) getMeasurement(id string) (float64, error) {
res, err := wb.measurementCache.Get()
res, err := wb.measurementG.Get()
if err != nil {
return 0, err
}
Expand All @@ -314,7 +314,7 @@ func (wb *Smaevcharger) getMeasurement(id string) (float64, error) {
}

func (wb *Smaevcharger) getParameter(id string) (string, error) {
res, err := wb.parameterCache.Get()
res, err := wb.parameterG.Get()
if err != nil {
return "", err
}
Expand Down
32 changes: 16 additions & 16 deletions charger/zaptec.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ import (
// Zaptec charger implementation
type Zaptec struct {
*request.Helper
log *util.Logger
statusCache provider.Cacheable[zaptec.StateResponse]
id string
enabled bool
priority bool
log *util.Logger
statusG provider.Cacheable[zaptec.StateResponse]
id string
enabled bool
priority bool
}

func init() {
Expand Down Expand Up @@ -91,7 +91,7 @@ func NewZaptec(user, password, id string, priority bool, cache time.Duration) (a
}

// setup cached values
c.statusCache = provider.ResettableCached(func() (zaptec.StateResponse, error) {
c.statusG = provider.ResettableCached(func() (zaptec.StateResponse, error) {
var res zaptec.StateResponse

uri := fmt.Sprintf("%s/api/chargers/%s/state", zaptec.ApiURL, c.id)
Expand Down Expand Up @@ -150,7 +150,7 @@ func (c *Zaptec) chargers() ([]string, error) {

// Status implements the api.Charger interface
func (c *Zaptec) Status() (api.ChargeStatus, error) {
res, err := c.statusCache.Get()
res, err := c.statusG.Get()
if err != nil {
return api.StatusA, err
}
Expand All @@ -172,7 +172,7 @@ func (c *Zaptec) Status() (api.ChargeStatus, error) {

// Enabled implements the api.Charger interface
func (c *Zaptec) Enabled() (bool, error) {
res, err := c.statusCache.Get()
res, err := c.statusG.Get()
return c.enabled && !res.ObservationByID(zaptec.FinalStopActive).Bool(), err
}

Expand All @@ -189,7 +189,7 @@ func (c *Zaptec) Enable(enable bool) error {
if err == nil {
_, err = c.DoBody(req)
c.enabled = enable
c.statusCache.Reset()
c.statusG.Reset()
}

return err
Expand All @@ -201,7 +201,7 @@ func (c *Zaptec) chargerUpdate(data zaptec.Update) error {
req, err := request.New(http.MethodPost, uri, request.MarshalJSON(data), request.JSONEncoding)
if err == nil {
_, err = c.DoBody(req)
c.statusCache.Reset()
c.statusG.Reset()
}

return err
Expand All @@ -213,7 +213,7 @@ func (c *Zaptec) sessionPriority(session string, data zaptec.SessionPriority) er
req, err := request.New(http.MethodPost, uri, request.MarshalJSON(data), request.JSONEncoding)
if err == nil {
_, err = c.DoBody(req)
c.statusCache.Reset()
c.statusG.Reset()
}

return err
Expand All @@ -233,7 +233,7 @@ var _ api.Meter = (*Zaptec)(nil)

// CurrentPower implements the api.Meter interface
func (c *Zaptec) CurrentPower() (float64, error) {
res, err := c.statusCache.Get()
res, err := c.statusG.Get()
if err != nil {
return 0, err
}
Expand All @@ -245,7 +245,7 @@ var _ api.ChargeRater = (*Zaptec)(nil)

// ChargedEnergy implements the api.ChargeRater interface
func (c *Zaptec) ChargedEnergy() (float64, error) {
res, err := c.statusCache.Get()
res, err := c.statusG.Get()
if err != nil {
return 0, err
}
Expand All @@ -257,7 +257,7 @@ var _ api.PhaseCurrents = (*Zaptec)(nil)

// Currents implements the api.PhaseCurrents interface
func (c *Zaptec) Currents() (float64, float64, float64, error) {
res, err := c.statusCache.Get()
res, err := c.statusG.Get()
if err != nil {
return 0, 0, 0, err
}
Expand All @@ -276,7 +276,7 @@ var _ api.PhaseSwitcher = (*Zaptec)(nil)

// Phases1p3p implements the api.ChargePhases interface
func (c *Zaptec) Phases1p3p(phases int) error {
res, err := c.statusCache.Get()
res, err := c.statusG.Get()

if err == nil {
data := zaptec.Update{
Expand Down Expand Up @@ -305,7 +305,7 @@ var _ api.Diagnosis = (*Zaptec)(nil)

// Diagnosis implements the api.ChargePhases interface
func (c *Zaptec) Diagnose() {
res, _ := c.statusCache.Get()
res, _ := c.statusG.Get()

// sort for printing
sort.Slice(res, func(i, j int) bool {
Expand Down
Loading

0 comments on commit c929e89

Please sign in to comment.