From 2282efa3e9b3a49c1bb9c6995931fd6131b90613 Mon Sep 17 00:00:00 2001 From: Jordan Hotmann Date: Tue, 7 Nov 2023 16:09:10 -0700 Subject: [PATCH] Client update with ha domain --- internal/api/api.go | 13 +++++++++++-- pkg/client/client.go | 7 ++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index 1a468c5..77022aa 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -99,14 +99,23 @@ 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 { - haErr = haClient.CallService(entityId, service, extras) + if domain != "" { + haErr = haClient.CallServiceManual(domain, entityId, service, extras) + } else { + haErr = haClient.CallService(entityId, service, extras) + } } else { - haErr = haClient.CallService(entityId, service) + if domain != "" { + haErr = haClient.CallServiceManual(domain, entityId, service) + } else { + haErr = haClient.CallService(entityId, service) + } } if haErr != nil { diff --git a/pkg/client/client.go b/pkg/client/client.go index f959010..3dd271f 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -70,7 +70,12 @@ func (c *HatsClient) CallService(entityId string, service string, extras ...map[ data := map[string]interface{}{} for _, extra := range extras { 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)