spaxel/mothership/internal/api
jedarden eaad8f789a feat: implement home automation integration (MQTT and webhooks)
Implemented comprehensive home automation integration with MQTT support for
Home Assistant auto-discovery and a system-wide webhook for delivering all
Spaxel events.

MQTT Client (mothership/internal/mqtt/client.go):
- Extended MQTT client with proper Home Assistant auto-discovery payloads
- Added support for person presence binary sensors with device discovery
- Added zone occupancy sensors (count + binary occupied sensors)
- Added fall detection binary sensor with safety device class
- Added system health and system mode (select) entities
- Implemented retained message support for presence and occupancy states
- Added Last Will and Testament for availability topic
- Added exponential backoff reconnection (5s to 2min cap)
- Added discovery config cleanup (empty payload) on entity deletion

MQTT Event Publisher (mothership/internal/mqtt/publisher.go):
- Subscribes to internal event bus and publishes relevant events to MQTT
- Publishes zone entry/exit events updating person presence
- Publishes fall detection events with person/zone/timestamp info
- Publishes periodic system health updates (node count, quality, mode)
- Provides zone and person mapping for proper entity naming

System Webhook Integration (mothership/internal/webhook/publisher.go):
- System-wide webhook delivering ALL spaxel events to configured URL
- Event payload includes event_type, timestamp, zone, person, blob_id, severity
- Includes X-Spaxel-Event header with event type for routing
- Implements retry policy (one retry after 30s on 5xx errors)
- Supports concurrent event publishing with goroutine safety
- Provides TestWebhook method for configuration verification

Integration Settings API (mothership/internal/api/integrations.go):
- GET/POST /api/settings/integration for MQTT and webhook configuration
- MQTT settings: broker URL, username, password, TLS, discovery prefix
- Webhook settings: URL, enabled flag
- POST /api/settings/integration/test to test connections
- Returns connection status for MQTT (connected boolean)
- Validates URL formats and required fields

Tests:
- mothership/internal/mqtt/client_test.go: MQTT client tests including
  * Client creation with validation
  * Home Assistant discovery config format verification
  * MQTT topic generation and payload format validation
  * Retained message behavior tests
  * Broker URL parsing tests
- mothership/internal/webhook/publisher_test.go: Webhook tests including
  * Publisher creation and config updates
  * Event publishing with schema validation
  * Retry on 5xx server errors
  * Concurrent event publishing safety
  * All event type coverage
  * Test webhook delivery

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 21:17:07 -04:00
..
analytics.go feat: complete anomaly detection & security mode dashboard UI 2026-04-09 05:59:54 -04:00
backup.go feat: implement SQLite Online Backup API streaming endpoint 2026-04-07 02:15:51 -04:00
backup_test.go feat: implement SQLite Online Backup API streaming endpoint 2026-04-07 02:15:51 -04:00
ble_test.go feat: wire anomaly detection & security mode API endpoints 2026-04-07 15:09:34 -04:00
briefing.go feat: complete morning briefing feature with provider adapters and API fixes 2026-04-10 04:25:31 -04:00
briefing_test.go feat: implement morning briefing feature 2026-04-10 00:25:33 -04:00
diurnal.go feat: add diurnal baseline REST API endpoints 2026-04-09 08:53:31 -04:00
diurnal_test.go feat: add diurnal baseline REST API endpoints 2026-04-09 08:53:31 -04:00
events.go feat: add anomaly_detected and sleep_session_end to valid event types 2026-04-09 15:30:45 -04:00
events_test.go feat: implement POST /api/events/{id}/feedback endpoint 2026-04-09 15:17:47 -04:00
feedback.go feat: implement guided troubleshooting with proactive contextual help 2026-04-10 04:25:31 -04:00
guided.go feat: implement guided troubleshooting with proactive contextual help 2026-04-10 04:25:31 -04:00
integrations.go feat: implement home automation integration (MQTT and webhooks) 2026-04-10 21:17:07 -04:00
localization.go feat: add self-improving localization REST API 2026-04-09 10:06:06 -04:00
localization_test.go feat: add self-improving localization REST API 2026-04-09 10:06:06 -04:00
notifications.go feat: wire anomaly detection & security mode API endpoints 2026-04-07 15:09:34 -04:00
notifications_test.go feat: wire anomaly detection & security mode API endpoints 2026-04-07 15:09:34 -04:00
prediction.go feat: implement presence prediction REST API endpoints 2026-04-09 09:59:42 -04:00
prediction_test.go feat: implement presence prediction REST API endpoints 2026-04-09 09:59:42 -04:00
replay.go feat: implement time-travel debugging and CSI replay 2026-04-09 19:27:42 -04:00
replay_test.go feat: implement CSI simulator CLI with GDOP overlay 2026-04-09 12:31:13 -04:00
security.go feat: implement anomaly detection and security mode 2026-04-09 09:48:44 -04:00
security_test.go feat: wire anomaly detection & security mode API endpoints 2026-04-07 14:47:44 -04:00
settings.go feat: implement guided troubleshooting with proactive contextual help 2026-04-10 04:25:31 -04:00
settings_test.go feat: wire anomaly detection & security mode API endpoints 2026-04-07 15:09:34 -04:00
simulator.go feat: complete pre-deployment simulator implementation 2026-04-09 21:30:47 -04:00
tracks.go feat: complete anomaly detection & security mode dashboard UI 2026-04-09 05:59:54 -04:00
tracks_test.go feat: complete anomaly detection & security mode dashboard UI 2026-04-09 05:59:54 -04:00
triggers.go feat: wire anomaly detection & security mode API endpoints 2026-04-07 15:09:34 -04:00
triggers_test.go feat: wire anomaly detection & security mode API endpoints 2026-04-07 15:09:34 -04:00
utils.go feat: verify dashboard WebSocket feed supports events, alerts, BLE, triggers, health 2026-04-07 09:54:14 -04:00
volume_triggers.go feat: wire anomaly detection & security mode API endpoints 2026-04-07 15:09:34 -04:00
volume_triggers_test.go feat: wire anomaly detection & security mode API endpoints 2026-04-07 15:09:34 -04:00
zones.go feat: verify zones CRUD REST endpoints with full test coverage 2026-04-07 15:00:32 -04:00
zones_test.go feat: add missing name-required validation test for zone creation 2026-04-07 15:00:32 -04:00