Skip to content

Commit

Permalink
Easee: use start_charge when authentication required (evcc-io#9271)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimmiMeloni authored Sep 9, 2023
1 parent 5ef8825 commit 68ec274
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
48 changes: 32 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
}{
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 @@ -372,6 +375,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 @@ -380,6 +384,7 @@ func (c *Easee) Enabled() (bool, error) {
func (c *Easee) Enable(enable bool) error {
c.mux.Lock()
enablingRequired := enable && !c.chargerEnabled
opMode := c.opMode
c.mux.Unlock()

// enable charger once if it's switched off
Expand All @@ -394,17 +399,23 @@ 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 {
// 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 @@ -418,6 +429,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
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 }}

0 comments on commit 68ec274

Please sign in to comment.