diff --git a/README.md b/README.md index 52e266a..b2b153b 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ ## NATS Topics - `homeassistant.states.{domain}.{entity}.{state}` - Home Assistant device state changes: [payload](https://www.home-assistant.io/docs/configuration/state_object/) +- `homeassistant.attributes.{domain}.{entity}.{state}` - When a device's attributes change but the state hasn't changed: [payload](https://www.home-assistant.io/docs/configuration/state_object/) - `homeassistant.zha.{device IEEE}` - ZHA events: [payload](https://www.home-assistant.io/docs/configuration/state_object/) - `homeassistant.nfc.{tag ID}` - Home Assistant NFC tag scanned: [payload](https://www.home-assistant.io/docs/configuration/state_object/) - `homeassistant.timer.{timer name}.finished` - Home Assistant timer finished: payload is simply `"finished"` diff --git a/internal/api/api.go b/internal/api/api.go index 56c2827..28ac046 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -94,19 +94,16 @@ func Close() { func tokenAuthMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if cfg.HatsToken == "" { // No token required - logger.Debug("Skipping token auth") next.ServeHTTP(w, r) return } - logger.Debug("Checking bearer token") authHeaderParts := strings.Split(r.Header.Get("Authorization"), " ") if len(authHeaderParts) != 2 || authHeaderParts[0] != "Bearer" || authHeaderParts[1] != cfg.HatsToken { logger.Warn("Unauthorized request", "method", r.Method, "path", r.URL.Path, "address", r.RemoteAddr) http.Error(w, "Bearer authorization header doesn't match configured token", http.StatusUnauthorized) return } - logger.Debug("Token valid") next.ServeHTTP(w, r) }) } diff --git a/internal/nats/timers.go b/internal/nats/timers.go index 9f66844..5c544e9 100644 --- a/internal/nats/timers.go +++ b/internal/nats/timers.go @@ -65,12 +65,12 @@ func (t *HatsTimer) Activate(durationOverride string) { d = t.Duration } } - logger.Error("Starting timer", "duration", int(d.Seconds())) + logger.Debug("Starting timer", "name", t.Name, "duration", int(d.Seconds())) err := haClient.CallService(t.Name, homeassistant.Services.Start, map[string]any{ homeassistant.ExtraProps.Duration: int(d.Seconds()), }) if err != nil { - logger.Error("Error starting timer", "error", err) + logger.Error("Error starting timer", "name", t.Name, "error", err) } }