Easee: fix circuit detection (#2011)
Some checks failed
Default / Build (push) Failing after 1m41s
Default / Build UI (push) Failing after 2m16s
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Publish Github & APT release (push) Has been cancelled
Some checks failed
Default / Build (push) Failing after 1m41s
Default / Build UI (push) Failing after 2m16s
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Publish Github & APT release (push) Has been cancelled
This commit is contained in:
parent
e7623fa8cf
commit
4fecb25ffd
1 changed files with 29 additions and 19 deletions
|
|
@ -64,7 +64,7 @@ func NewEaseeFromConfig(other map[string]interface{}) (api.Charger, error) {
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
Charger string
|
Charger string
|
||||||
Circuit int
|
Circuit int // deprecated
|
||||||
Cache time.Duration // deprecated
|
Cache time.Duration // deprecated
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
|
|
@ -72,11 +72,21 @@ func NewEaseeFromConfig(other map[string]interface{}) (api.Charger, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewEasee(cc.User, cc.Password, cc.Charger, cc.Circuit, cc.Cache)
|
log := util.NewLogger("easee")
|
||||||
|
|
||||||
|
if cc.Circuit > 0 {
|
||||||
|
log.WARN.Println("circuit is deprecated and will be removed in a future release")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cc.Cache > 0 {
|
||||||
|
log.WARN.Println("cache is deprecated and will be removed in a future release")
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewEasee(cc.User, cc.Password, cc.Charger, cc.Cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEasee creates Easee charger
|
// NewEasee creates Easee charger
|
||||||
func NewEasee(user, password, charger string, circuit int, cache time.Duration) (*Easee, error) {
|
func NewEasee(user, password, charger string, cache time.Duration) (*Easee, error) {
|
||||||
log := util.NewLogger("easee").Redact(user, password)
|
log := util.NewLogger("easee").Redact(user, password)
|
||||||
|
|
||||||
if !sponsor.IsAuthorized() {
|
if !sponsor.IsAuthorized() {
|
||||||
|
|
@ -114,25 +124,25 @@ func NewEasee(user, password, charger string, circuit int, cache time.Duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.charger = chargers[0].ID
|
c.charger = chargers[0].ID
|
||||||
|
}
|
||||||
|
|
||||||
// find site
|
// find site
|
||||||
site, err := c.chargerSite(c.charger)
|
site, err := c.chargerSite(c.charger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// find single charger per circuit
|
||||||
|
for _, circuit := range site.Circuits {
|
||||||
|
if len(circuit.Chargers) > 1 {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// find single charger per circuit
|
for _, charger := range circuit.Chargers {
|
||||||
for _, circuit := range site.Circuits {
|
if charger.ID == c.charger {
|
||||||
if len(circuit.Chargers) > 1 {
|
c.site = site.ID
|
||||||
continue
|
c.circuit = circuit.ID
|
||||||
}
|
break
|
||||||
|
|
||||||
for _, charger := range circuit.Chargers {
|
|
||||||
if charger.ID == c.charger {
|
|
||||||
c.site = site.ID
|
|
||||||
c.circuit = circuit.ID
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue