1
0
Fork 0

Tweak logging

main
Jordan Hotmann 2023-11-20 16:59:37 -07:00
parent 1fbce92da2
commit 1cbc04c02b
No known key found for this signature in database
GPG Key ID: 01B504170C2A2EA3
3 changed files with 3 additions and 5 deletions

View File

@ -15,6 +15,7 @@
## NATS Topics ## NATS Topics
- `homeassistant.states.{domain}.{entity}.{state}` - Home Assistant device state changes: [payload](https://www.home-assistant.io/docs/configuration/state_object/) - `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.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.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"` - `homeassistant.timer.{timer name}.finished` - Home Assistant timer finished: payload is simply `"finished"`

View File

@ -94,19 +94,16 @@ func Close() {
func tokenAuthMiddleware(next http.Handler) http.Handler { func tokenAuthMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if cfg.HatsToken == "" { // No token required if cfg.HatsToken == "" { // No token required
logger.Debug("Skipping token auth")
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
return return
} }
logger.Debug("Checking bearer token")
authHeaderParts := strings.Split(r.Header.Get("Authorization"), " ") authHeaderParts := strings.Split(r.Header.Get("Authorization"), " ")
if len(authHeaderParts) != 2 || authHeaderParts[0] != "Bearer" || authHeaderParts[1] != cfg.HatsToken { 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) 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) http.Error(w, "Bearer authorization header doesn't match configured token", http.StatusUnauthorized)
return return
} }
logger.Debug("Token valid")
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
}) })
} }

View File

@ -65,12 +65,12 @@ func (t *HatsTimer) Activate(durationOverride string) {
d = t.Duration 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{ err := haClient.CallService(t.Name, homeassistant.Services.Start, map[string]any{
homeassistant.ExtraProps.Duration: int(d.Seconds()), homeassistant.ExtraProps.Duration: int(d.Seconds()),
}) })
if err != nil { if err != nil {
logger.Error("Error starting timer", "error", err) logger.Error("Error starting timer", "name", t.Name, "error", err)
} }
} }