Add SmartWB template (#3282)

This commit is contained in:
andig 2022-04-30 15:29:23 +02:00 • committed by GitHub
parent 013eda537d
commit 0d5adcbcd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 37 deletions

31
charger/evse/types.go Normal file
View file

@ -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"`
}

View file

@ -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
@ -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]
@ -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

View file

@ -1,7 +1,7 @@
template: evsewifi
products:
- description:
generic: EVSE-Wifi
generic: EVSE-WiFi
params:
- name: host
render: |

View file

@ -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

View file

@ -1,5 +1,5 @@
product:
description: EVSE-Wifi
description: EVSE-WiFi
render:
- default: |
type: template

View file

@ -0,0 +1,7 @@
product:
description: smartWB
render:
- default: |
type: template
template: smartwb
host: 192.0.2.2 # IP-Adresse oder Hostname