Skip to content

Commit

Permalink
Add SmartWB template (#3282)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Apr 30, 2022
1 parent 013eda5 commit 0d5adcb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 37 deletions.
31 changes: 31 additions & 0 deletions charger/evse/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package evse

const Success = "S0_"

// ParameterResponse is the getParameters response
type ParameterResponse struct {
Type string `json:"type"`
List []ListEntry `json:"list"`
}

// ListEntry is ParameterResponse.List
type ListEntry struct {
VehicleState int64 `json:"vehicleState"`
EvseState bool `json:"evseState"`
MaxCurrent int64 `json:"maxCurrent"`
ActualCurrent int64 `json:"actualCurrent"`
ActualCurrentMA *int64 `json:"actualCurrentMA"` // 1/100 A
ActualPower float64 `json:"actualPower"`
Duration int64 `json:"duration"`
AlwaysActive bool `json:"alwaysActive"`
UseMeter bool `json:"useMeter"`
LastActionUser string `json:"lastActionUser"`
LastActionUID string `json:"lastActionUID"`
Energy float64 `json:"energy"`
Mileage float64 `json:"mileage"`
MeterReading float64 `json:"meterReading"`
CurrentP1 float64 `json:"currentP1"`
CurrentP2 float64 `json:"currentP2"`
CurrentP3 float64 `json:"currentP3"`
RFIDUID *string `json:"RFIDUID"`
}
41 changes: 6 additions & 35 deletions charger/evsewifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,11 @@ import (
"time"

"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/evse"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
)

const evseSuccess = "S0_"

// EVSEParameterResponse is the getParameters response
type EVSEParameterResponse struct {
Type string `json:"type"`
List []EVSEListEntry `json:"list"`
}

// EVSEListEntry is EVSEParameterResponse.List
type EVSEListEntry struct {
VehicleState int64 `json:"vehicleState"`
EvseState bool `json:"evseState"`
MaxCurrent int64 `json:"maxCurrent"`
ActualCurrent int64 `json:"actualCurrent"`
ActualCurrentMA *int64 `json:"actualCurrentMA"` // 1/100 A
ActualPower float64 `json:"actualPower"`
Duration int64 `json:"duration"`
AlwaysActive bool `json:"alwaysActive"`
UseMeter bool `json:"useMeter"`
LastActionUser string `json:"lastActionUser"`
LastActionUID string `json:"lastActionUID"`
Energy float64 `json:"energy"`
Mileage float64 `json:"mileage"`
MeterReading float64 `json:"meterReading"`
CurrentP1 float64 `json:"currentP1"`
CurrentP2 float64 `json:"currentP2"`
CurrentP3 float64 `json:"currentP3"`
RFIDUID *string `json:"RFIDUID"`
}

// EVSEWifi charger implementation
type EVSEWifi struct {
*request.Helper
Expand Down Expand Up @@ -143,16 +114,16 @@ func NewEVSEWifi(uri string) (*EVSEWifi, error) {
}

// query evse parameters
func (wb *EVSEWifi) getParameters() (EVSEListEntry, error) {
var res EVSEParameterResponse
func (wb *EVSEWifi) getParameters() (evse.ListEntry, error) {
var res evse.ParameterResponse
uri := fmt.Sprintf("%s/getParameters", wb.uri)
err := wb.GetJSON(uri, &res)
if err != nil {
return EVSEListEntry{}, err
return evse.ListEntry{}, err
}

if len(res.List) != 1 {
return EVSEListEntry{}, fmt.Errorf("unexpected response: %s", res.Type)
return evse.ListEntry{}, fmt.Errorf("unexpected response: %s", res.Type)
}

params := res.List[0]
Expand Down Expand Up @@ -193,7 +164,7 @@ func (wb *EVSEWifi) Enabled() (bool, error) {
// get executes GET request and checks for EVSE error response
func (wb *EVSEWifi) get(uri string) error {
b, err := wb.GetBody(uri)
if err == nil && !strings.HasPrefix(string(b), evseSuccess) {
if err == nil && !strings.HasPrefix(string(b), evse.Success) {
err = errors.New(string(b))
}
return err
Expand Down
2 changes: 1 addition & 1 deletion templates/definition/charger/evsewifi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
template: evsewifi
products:
- description:
generic: EVSE-Wifi
generic: EVSE-WiFi
params:
- name: host
render: |
Expand Down
13 changes: 13 additions & 0 deletions templates/definition/charger/smartwb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
template: smartwb
products:
- description:
generic: smartWB
params:
- name: host
render: |
type: evsewifi
uri: http://{{ .host }}
meter:
power: true
energy: true
currents: true
2 changes: 1 addition & 1 deletion templates/docs/charger/evsewifi_0.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
product:
description: EVSE-Wifi
description: EVSE-WiFi
render:
- default: |
type: template
Expand Down
7 changes: 7 additions & 0 deletions templates/docs/charger/smartwb_0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
product:
description: smartWB
render:
- default: |
type: template
template: smartwb
host: 192.0.2.2 # IP-Adresse oder Hostname

0 comments on commit 0d5adcb

Please sign in to comment.