Add vehicle api (#2743)
This commit is contained in:
parent
89efcb6e64
commit
0ff07da905
4 changed files with 20 additions and 0 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue