Add vehicle api (#2743)

This commit is contained in:
andig 2022-03-02 13:00:24 +01:00 • committed by GitHub
parent 89efcb6e64
commit 0ff07da905
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 0 deletions

View file

@ -48,6 +48,8 @@ type API interface {
// SetTargetCharge sets the charge targetSoC
SetTargetCharge(time.Time, int)
// SetVehicle sets the active vehicle
SetVehicle(vehicle api.Vehicle)
// RemoteControl sets remote status demand
RemoteControl(string, RemoteDemand)

View file

@ -139,6 +139,14 @@ func (lp *LoadPoint) SetTargetCharge(finishAt time.Time, soc int) {
}
}
// SetVehicle sets the active vehicle
func (lp *LoadPoint) SetVehicle(vehicle api.Vehicle) {
lp.Lock()
defer lp.Unlock()
lp.setActiveVehicle(vehicle)
}
// RemoteControl sets remote status demand
func (lp *LoadPoint) RemoteControl(source string, demand loadpoint.RemoteDemand) {
lp.Lock()

View file

@ -87,6 +87,7 @@ func NewHTTPd(url string, site site.API, hub *SocketHub, cache *util.Cache) *HTT
"phases": {[]string{"POST", "OPTIONS"}, "/phases/{value:[0-9]+}", phasesHandler(lp)},
"targetcharge": {[]string{"POST", "OPTIONS"}, "/targetcharge/{soc:[0-9]+}/{time:[0-9TZ:-]+}", targetChargeHandler(lp)},
"targetcharge2": {[]string{"DELETE", "OPTIONS"}, "/targetcharge", targetChargeRemoveHandler(lp)},
"vehicle": {[]string{"DELETE", "OPTIONS"}, "/vehicle", vehicleRemoveHandler(lp)},
"remotedemand": {[]string{"POST", "OPTIONS"}, "/remotedemand/{demand:[a-z]+}/{source::[0-9a-zA-Z_-]+}", remoteDemandHandler(lp)},
}

View file

@ -274,6 +274,15 @@ func targetChargeRemoveHandler(loadpoint loadpoint.API) http.HandlerFunc {
}
}
// vehicleRemoveHandler removes vehicle
func vehicleRemoveHandler(loadpoint loadpoint.API) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
loadpoint.SetVehicle(nil)
res := struct{}{}
jsonResult(w, res)
}
}
// socketHandler attaches websocket handler to uri
func socketHandler(hub *SocketHub) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {