Easee: add timeout (#6905)

This commit is contained in:
jheinitz 2023-03-20 22:39:28 +01:00 • committed by GitHub
parent 4fa8a2b82c
commit a216a86707
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View file

@ -66,10 +66,13 @@ func init() {
// NewEaseeFromConfig creates a go-e charger from generic config
func NewEaseeFromConfig(other map[string]interface{}) (api.Charger, error) {
var cc struct {
cc := struct {
User string
Password string
Charger string
Timeout time.Duration
}{
Timeout: request.Timeout,
}
if err := util.DecodeOther(other, &cc); err != nil {
@ -80,11 +83,11 @@ func NewEaseeFromConfig(other map[string]interface{}) (api.Charger, error) {
return nil, api.ErrMissingCredentials
}
return NewEasee(cc.User, cc.Password, cc.Charger)
return NewEasee(cc.User, cc.Password, cc.Charger, cc.Timeout)
}
// NewEasee creates Easee charger
func NewEasee(user, password, charger string) (*Easee, error) {
func NewEasee(user, password, charger string, timeout time.Duration) (*Easee, error) {
log := util.NewLogger("easee").Redact(user, password)
if !sponsor.IsAuthorized() {
@ -99,6 +102,8 @@ func NewEasee(user, password, charger string) (*Easee, error) {
current: 6, // default current
}
c.Client.Timeout = timeout
ts, err := easee.TokenSource(log, user, password)
if err != nil {
return c, err

View file

@ -15,8 +15,11 @@ params:
- name: charger
required: true
example: EH______
- name: timeout
default: 10s
render: |
type: easee
user: {{ .user }}
password: {{ .password }}
charger: {{ .charger }}
timeout: {{ .timeout }}

View file

@ -10,3 +10,10 @@ render:
user: # Benutzerkonto (bspw. E-Mail Adresse, User Id, etc.)
password: # Passwort des Benutzerkontos (bei führenden Nullen bitte in einfache Hochkommata setzen)
charger: EH______
advanced: |
type: template
template: easee
user: # Benutzerkonto (bspw. E-Mail Adresse, User Id, etc.)
password: # Passwort des Benutzerkontos (bei führenden Nullen bitte in einfache Hochkommata setzen)
charger: EH______
timeout: 10s # Optional