diff --git a/charger/helper.go b/charger/helper.go index 69a7cfad0..a1368276d 100644 --- a/charger/helper.go +++ b/charger/helper.go @@ -8,46 +8,48 @@ import ( "github.com/evcc-io/evcc/api" ) -// ensureCharger extracts VIN from list of VINs returned from `list` function -func ensureCharger(vin string, list func() ([]string, error)) (string, error) { - vin, _, err := ensureChargerWithFeature(vin, list, func(v string) (string, string) { +// ensureCharger extracts ID from list of IDs returned from `list` function +func ensureCharger(id string, list func() ([]string, error)) (string, error) { + id, _, err := ensureChargerWithFeature(id, list, func(v string) (string, string) { return v, "" }) - return vin, err + return id, err } -// ensureChargerWithFeature extracts VIN and feature from list of chargers of type V returned from `list` function +// ensureChargerWithFeature extracts ID and feature from list of chargers of type V returned from `list` function func ensureChargerWithFeature[Charger, Feature any]( - vin string, + id string, list func() ([]Charger, error), extract func(Charger) (string, Feature), ) (string, Feature, error) { + var zero Feature + chargers, err := list() if err != nil { - return "", *new(Feature), fmt.Errorf("cannot get chargers: %w", err) + return "", zero, fmt.Errorf("cannot get chargers: %w", err) } - if vin = strings.ToUpper(vin); vin != "" { + if id = strings.ToUpper(id); id != "" { for _, charger := range chargers { - if v, res := extract(charger); strings.ToUpper(v) == vin { + if v, res := extract(charger); strings.ToUpper(v) == id { return v, res, nil } } - // vin defined but doesn't exist - err = fmt.Errorf("cannot find charger %s", vin) + // id defined but doesn't exist + err = fmt.Errorf("cannot find charger %s", id) } else { - // vin empty + // id empty if len(chargers) == 1 { - vin, res := extract(chargers[0]) - return vin, res, nil + id, res := extract(chargers[0]) + return id, res, nil } err = fmt.Errorf("cannot find charger, got: %v", chargers) } - return "", *new(Feature), err + return "", zero, err } // bytesAsString normalises a string by stripping leading 0x00 and trimming white space diff --git a/core/site_api.go b/core/site_api.go index 4832e3941..014d8b228 100644 --- a/core/site_api.go +++ b/core/site_api.go @@ -214,8 +214,8 @@ func (site *Site) GetTariff(tariff string) api.Tariff { // GetBatteryControl returns the battery control mode func (site *Site) GetBatteryDischargeControl() bool { - site.Lock() - defer site.Unlock() + site.RLock() + defer site.RUnlock() return site.batteryDischargeControl } diff --git a/server/http_site_handler.go b/server/http_site_handler.go index 651ed7152..39ffb4bd7 100644 --- a/server/http_site_handler.go +++ b/server/http_site_handler.go @@ -136,7 +136,7 @@ func boolHandler(set func(bool) error, get func() bool) http.HandlerFunc { } } -// boolGetHandler retrievs bool api values +// boolGetHandler retrieves bool api values func boolGetHandler(get func() bool) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { jsonResult(w, get()) diff --git a/tariff/edf-tempo.go b/tariff/edf-tempo.go index abe6fc9c8..48d45acf3 100644 --- a/tariff/edf-tempo.go +++ b/tariff/edf-tempo.go @@ -49,7 +49,7 @@ func NewEdfTempoFromConfig(other map[string]interface{}) (api.Tariff, error) { return nil, err } - if cc.ClientID == "" && cc.ClientSecret == "" { + if cc.ClientID == "" || cc.ClientSecret == "" { return nil, errors.New("missing credentials") }