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,14 +99,23 @@ func setEntityStateHandler(w http.ResponseWriter, r *http.Request) {
logRequest(w, r) logRequest(w, r)
entityId := chi.URLParam(r, "entityId") entityId := chi.URLParam(r, "entityId")
service := chi.URLParam(r, "service") service := chi.URLParam(r, "service")
domain := r.URL.Query().Get("domain")
var extras map[string]any var extras map[string]any
err := render.DecodeJSON(r.Body, &extras) err := render.DecodeJSON(r.Body, &extras)
var haErr error var haErr error
if err == nil && len(extras) > 0 { if err == nil && len(extras) > 0 {
haErr = haClient.CallService(entityId, service, extras) if domain != "" {
haErr = haClient.CallServiceManual(domain, entityId, service, extras)
} else {
haErr = haClient.CallService(entityId, service, extras)
}
} else { } else {
haErr = haClient.CallService(entityId, service) if domain != "" {
haErr = haClient.CallServiceManual(domain, entityId, service)
} else {
haErr = haClient.CallService(entityId, service)
}
} }
if haErr != nil { if haErr != nil {

View File

@ -70,7 +70,12 @@ func (c *HatsClient) CallService(entityId string, service string, extras ...map[
data := map[string]interface{}{} data := map[string]interface{}{}
for _, extra := range extras { for _, extra := range extras {
for k, v := range extra { for k, v := range extra {
data[k] = v switch k {
case "domain":
req.SetQueryParam(k, fmt.Sprintf("%v", v))
default:
data[k] = v
}
} }
} }
req.SetBody(data) req.SetBody(data)