Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/evse improve #305

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions charger/evsewifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type EVSEListEntry struct {
type EVSEWifi struct {
*util.HTTPHelper
uri string
alwaysActive bool
}

// NewEVSEWifiFromConfig creates a EVSEWifi charger from generic config
Expand All @@ -62,8 +63,9 @@ func NewEVSEWifiFromConfig(other map[string]interface{}) (api.Charger, error) {
// NewEVSEWifi creates EVSEWifi charger
func NewEVSEWifi(uri string) (api.Charger, error) {
evse := &EVSEWifi{
HTTPHelper: util.NewHTTPHelper(util.NewLogger("wifi")),
uri: strings.TrimRight(uri, "/"),
HTTPHelper: util.NewHTTPHelper(util.NewLogger("wifi")),
uri: strings.TrimRight(uri, "/"),
alwaysActive: true,
}

return evse, nil
Expand All @@ -87,10 +89,11 @@ func (evse *EVSEWifi) getParameters() (EVSEListEntry, error) {
}

params := pr.List[0]
if params.AlwaysActive {
evse.HTTPHelper.Log.WARN.Println("cannot control evse- alwaysactive is on")
if !params.AlwaysActive {
evse.HTTPHelper.Log.WARN.Println("evse should be configured to remote mode")
}

evse.alwaysActive = params.AlwaysActive
return params, nil
}

Expand Down Expand Up @@ -134,6 +137,14 @@ func (evse *EVSEWifi) checkError(b []byte, err error) error {
// Enable implements the Charger.Enable interface
func (evse *EVSEWifi) Enable(enable bool) error {
url := fmt.Sprintf("%s?active=%v", evse.apiURL(evseSetStatus), enable)

if evse.alwaysActive {
current := 0
if enable {
current = 6
}
url = fmt.Sprintf("%s?current=%d", evse.apiURL(evseSetCurrent), current)
}
return evse.checkError(evse.Get(url))
}

Expand Down