Miscellaneous cleanup

This commit is contained in:
andig 2021-05-02 11:18:28 +02:00
parent 6463e4cffd
commit 4eefe8f576
6 changed files with 11 additions and 13 deletions

View file

@ -81,13 +81,13 @@ func NewFritzDECT(uri, ain, user, password, sid string, standbypower float64, up
}
func (c *FritzDECT) execFritzDectCmd(function string) (string, error) {
// Refresh Fritzbox session id
// refresh Fritzbox session id
if time.Since(c.updated).Minutes() >= 10 {
err := c.getSessionID()
if err != nil {
return "", err
}
// Update session timestamp
// update session timestamp
c.updated = time.Now()
}
@ -104,7 +104,6 @@ func (c *FritzDECT) execFritzDectCmd(function string) (string, error) {
// Status implements the api.Charger interface
func (c *FritzDECT) Status() (api.ChargeStatus, error) {
// present 0/1 - DECT Switch connected to fritzbox (no/yes)
var present int64
resp, err := c.execFritzDectCmd("getswitchpresent")
@ -208,13 +207,13 @@ func (c *FritzDECT) ChargedEnergy() (float64, error) {
}
// unmarshal devicestats
var statsresp fritzdect.Devicestats
if err = xml.Unmarshal([]byte(resp), &statsresp); err != nil {
var stats fritzdect.Devicestats
if err = xml.Unmarshal([]byte(resp), &stats); err != nil {
return 0, err
}
// select energy value of current day
energylist := strings.Split(statsresp.Energy.Values[1], ",")
energylist := strings.Split(stats.Energy.Values[1], ",")
energy, err := strconv.ParseFloat(energylist[0], 64)
return energy / 1000, err

View file

@ -82,9 +82,9 @@ func (c *Tasmota) Enable(enable bool) error {
switch {
case err != nil:
return err
case enable && resp.POWER != "ON":
case enable && resp.Power != "ON":
return errors.New("switchOn failed")
case !enable && resp.POWER != "OFF":
case !enable && resp.Power != "OFF":
return errors.New("switchOff failed")
default:
return nil

View file

@ -47,8 +47,7 @@ type StatusSNSResponse struct {
}
// PowerResponse is the Tasmota Power command Status response
// ON, OFF, Error
// https://tasmota.github.io/docs/Commands/#with-web-requests
type PowerResponse struct {
POWER string
Power string // ON, OFF, Error
}

View file

@ -19,7 +19,7 @@ func Refresher(log *util.Logger) oauth.TokenRefresher {
}
}
// Refresh is the oauth.TokenRefresher
// RefreshToken implements oauth.TokenRefresher
func (tr *tokenRefresher) RefreshToken(token *oauth2.Token) (*oauth2.Token, error) {
uri := "https://login.apps.emea.vwapps.io/refresh/v1"

View file

@ -16,7 +16,7 @@ import (
)
const (
// IdentityURI is the VW OIDC identidy provider uri
// IdentityURI is the VW OIDC identity provider uri
IdentityURI = "https://identity.vwgroup.io"
// OauthTokenURI is used for refreshing tokens

View file

@ -23,7 +23,7 @@ func refresher(log *util.Logger, clientID string) oauth.TokenRefresher {
}
}
// Refresh is the oauth.TokenRefresher
// RefreshToken implements oauth.TokenRefresher
func (tr *tokenRefresher) RefreshToken(token *oauth2.Token) (*oauth2.Token, error) {
data := url.Values(map[string][]string{
"grant_type": {"refresh_token"},