parent
db1ac7ffd6
commit
2282efa3e9
|
@ -99,15 +99,24 @@ func setEntityStateHandler(w http.ResponseWriter, r *http.Request) {
|
|||
logRequest(w, r)
|
||||
entityId := chi.URLParam(r, "entityId")
|
||||
service := chi.URLParam(r, "service")
|
||||
domain := r.URL.Query().Get("domain")
|
||||
|
||||
var extras map[string]any
|
||||
err := render.DecodeJSON(r.Body, &extras)
|
||||
var haErr error
|
||||
if err == nil && len(extras) > 0 {
|
||||
if domain != "" {
|
||||
haErr = haClient.CallServiceManual(domain, entityId, service, extras)
|
||||
} else {
|
||||
haErr = haClient.CallService(entityId, service, extras)
|
||||
}
|
||||
} else {
|
||||
if domain != "" {
|
||||
haErr = haClient.CallServiceManual(domain, entityId, service)
|
||||
} else {
|
||||
haErr = haClient.CallService(entityId, service)
|
||||
}
|
||||
}
|
||||
|
||||
if haErr != nil {
|
||||
logger.Error("Error setting state", "error", haErr)
|
||||
|
|
|
@ -70,9 +70,14 @@ func (c *HatsClient) CallService(entityId string, service string, extras ...map[
|
|||
data := map[string]interface{}{}
|
||||
for _, extra := range extras {
|
||||
for k, v := range extra {
|
||||
switch k {
|
||||
case "domain":
|
||||
req.SetQueryParam(k, fmt.Sprintf("%v", v))
|
||||
default:
|
||||
data[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
req.SetBody(data)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue