parent
64f800fdd0
commit
c9a1cdb50d
|
@ -156,7 +156,8 @@ func handleMessages() {
|
||||||
data, _ := json.Marshal(message.Event.Data)
|
data, _ := json.Marshal(message.Event.Data)
|
||||||
nats.Publish(fmt.Sprintf("homeassistant.zwave-scene.%s", message.Event.Data.DeviceId), data)
|
nats.Publish(fmt.Sprintf("homeassistant.zwave-scene.%s", message.Event.Data.DeviceId), data)
|
||||||
case timerFinishedEventId:
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,21 @@ func PublishString(subject, message string) {
|
||||||
Publish(subject, []byte(message))
|
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) {
|
func GetKeyValue(key string) ([]byte, error) {
|
||||||
value, err := kv.Get(ctx, key)
|
value, err := kv.Get(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -57,7 +57,7 @@ func (n *NatsConnection) GenericTimerListener(logger *slog.Logger, timerName str
|
||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
|
|
||||||
for msg := range ch {
|
for msg := range ch {
|
||||||
go msg.Ack()
|
go msg.Respond([]byte("got it"))
|
||||||
l.Debug("Timer ended", "name", timerName)
|
l.Debug("Timer ended", "name", timerName)
|
||||||
err = handler()
|
err = handler()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue