1
0
Fork 0

Client update with ha domain

main v0.7.1
Jordan Hotmann 2023-11-07 16:09:10 -07:00
parent db1ac7ffd6
commit 2282efa3e9
No known key found for this signature in database
GPG Key ID: 01B504170C2A2EA3
2 changed files with 17 additions and 3 deletions

View File

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

View File

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