Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easee: use start_charge when authentication required #9271

Merged
merged 11 commits into from
Sep 9, 2023
50 changes: 34 additions & 16 deletions charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Easee struct {
current float64
chargerEnabled bool
smartCharging bool
authorize bool
opMode int
reasonForNoCurrent int
phaseMode int
Expand All @@ -72,10 +73,11 @@ func init() {
// NewEaseeFromConfig creates a go-e charger from generic config
func NewEaseeFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := struct {
User string
Password string
Charger string
Timeout time.Duration
User string
Password string
Charger string
Timeout time.Duration
Authorize bool
GrimmiMeloni marked this conversation as resolved.
Show resolved Hide resolved
}{
Timeout: request.Timeout,
}
Expand All @@ -88,26 +90,27 @@ func NewEaseeFromConfig(other map[string]interface{}) (api.Charger, error) {
return nil, api.ErrMissingCredentials
}

return NewEasee(cc.User, cc.Password, cc.Charger, cc.Timeout)
return NewEasee(cc.User, cc.Password, cc.Charger, cc.Timeout, cc.Authorize)
}

// NewEasee creates Easee charger
func NewEasee(user, password, charger string, timeout time.Duration) (*Easee, error) {
func NewEasee(user, password, charger string, timeout time.Duration, authorize bool) (*Easee, error) {
log := util.NewLogger("easee").Redact(user, password)

if !sponsor.IsAuthorized() {
return nil, api.ErrSponsorRequired
}

c := &Easee{
Helper: request.NewHelper(log),
charger: charger,
log: log,
current: 6, // default current
done: make(chan struct{}),
cmdC: make(chan easee.SignalRCommandResponse),
obsC: make(chan easee.Observation),
obsTime: make(map[easee.ObservationID]time.Time),
Helper: request.NewHelper(log),
charger: charger,
authorize: authorize,
log: log,
current: 6, // default current
done: make(chan struct{}),
cmdC: make(chan easee.SignalRCommandResponse),
obsC: make(chan easee.Observation),
obsTime: make(map[easee.ObservationID]time.Time),
}

c.Client.Timeout = timeout
Expand Down Expand Up @@ -385,6 +388,7 @@ func (c *Easee) Enabled() (bool, error) {

disabled := c.opMode == easee.ModeDisconnected ||
c.opMode == easee.ModeCompleted ||
c.opMode == easee.ModeAwaitingAuthentication ||
(c.opMode == easee.ModeAwaitingStart && c.reasonForNoCurrent == 52)
return !disabled && c.dynamicChargerCurrent > 0, nil
}
Expand All @@ -407,17 +411,26 @@ func (c *Easee) Enable(enable bool) error {
}
}

// do not send pause/resume if disconnected or unauthenticated
if c.opMode == easee.ModeDisconnected || c.opMode == easee.ModeAwaitingAuthentication {
c.mux.Lock()
opMode := c.opMode
GrimmiMeloni marked this conversation as resolved.
Show resolved Hide resolved
c.mux.Unlock()
// do not send pause/resume if disconnected or unauthenticated without automatic authorization
if opMode == easee.ModeDisconnected || (opMode == easee.ModeAwaitingAuthentication && !(enable && c.authorize)) {
return nil
}

// resume/stop charger
action := easee.ChargePause
if c.authorize {
action = easee.ChargeStop
}
var expectedEnabledState bool
var targetCurrent float64
if enable {
action = easee.ChargeResume
if opMode == easee.ModeAwaitingAuthentication && c.authorize {
action = easee.ChargeStart
}
expectedEnabledState = true
targetCurrent = 32
}
Expand All @@ -431,6 +444,11 @@ func (c *Easee) Enable(enable bool) error {
if err := c.waitForChargerEnabledState(expectedEnabledState); err != nil {
return err
}

if c.authorize { // authenticating charger does not mingle with DCC, no need for below operations
return nil
}

if err := c.waitForDynamicChargerCurrent(targetCurrent); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions charger/easee/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package easee
const API = "https://api.easee.com/api"

const (
ChargeStart = "start_charging"
ChargeStop = "stop_charging"
ChargePause = "pause_charging"
ChargeResume = "resume_charging"
)
Expand Down
5 changes: 5 additions & 0 deletions templates/definition/charger/easee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ params:
example: EH______
- name: timeout
default: 10s
- name: authorize
GrimmiMeloni marked this conversation as resolved.
Show resolved Hide resolved
help:
de: Steuert ob evcc die Authentifizierung am Charger vornimmt. Vorteil ist ein kontrollierter Ladestart. Nicht kompatibel mit RFID Identifikation von Fahrzeugen.
en: Controls wether evcc shall perform authentication against charger. Benefit is a contolled start of charging. Not compatible with RFID identification of vehicles.
render: |
type: easee
user: {{ .user }}
password: {{ .password }}
charger: {{ .charger }}
timeout: {{ .timeout }}
authorize: {{ .authorize }}