diff --git a/internal/homeassistant/subscriber.go b/internal/homeassistant/subscriber.go index 4d9c3d2..bdddd4f 100644 --- a/internal/homeassistant/subscriber.go +++ b/internal/homeassistant/subscriber.go @@ -156,7 +156,8 @@ func handleMessages() { data, _ := json.Marshal(message.Event.Data) nats.Publish(fmt.Sprintf("homeassistant.zwave-scene.%s", message.Event.Data.DeviceId), data) case timerFinishedEventId: - nats.PublishString(fmt.Sprintf("homeassistant.%s.finished", message.Event.Data.EntityId), "finished") + // nats.PublishString(fmt.Sprintf("homeassistant.%s.finished", message.Event.Data.EntityId), "finished") + nats.PublishRequest(fmt.Sprintf("homeassistant.%s.finished", message.Event.Data.EntityId), []byte("finished"), 500*time.Millisecond, 3) } } } diff --git a/internal/nats/client.go b/internal/nats/client.go index 6fc0fee..2bc6c2b 100644 --- a/internal/nats/client.go +++ b/internal/nats/client.go @@ -83,6 +83,21 @@ func PublishString(subject, message string) { Publish(subject, []byte(message)) } +func PublishRequest(subject string, message []byte, timeout time.Duration, retries int) { + attempts := 0 + for { + attempts += 1 + if attempts > retries { + logger.Error("Request retries exceeded", "subject", subject) + } + resp, err := client.Conn.Request(subject, message, timeout) + + if err == nil { + logger.Debug("Request response received", "response", string(resp.Data)) + } + } +} + func GetKeyValue(key string) ([]byte, error) { value, err := kv.Get(ctx, key) if err != nil { diff --git a/pkg/nats/subscribers.go b/pkg/nats/subscribers.go index 0d5a0c5..b5a685e 100644 --- a/pkg/nats/subscribers.go +++ b/pkg/nats/subscribers.go @@ -57,7 +57,7 @@ func (n *NatsConnection) GenericTimerListener(logger *slog.Logger, timerName str defer sub.Unsubscribe() for msg := range ch { - go msg.Ack() + go msg.Respond([]byte("got it")) l.Debug("Timer ended", "name", timerName) err = handler() if err != nil {