Commit Graph

6 Commits

Author SHA1 Message Date
59539e0201 WIP: MQTT Tests - Mocked approach created but needs better testing strategy
- Created test_mqtt_mocked.py with unittest.mock (following OCA patterns)
- Old tests with real MQTT broker hang in TransactionCase tearDown
- Created run-tests.sh following OCA/oca-ci best practices
- TODO: Find proper way to test MQTT with background threads in Odoo
- TODO: Either fully mock or use different test approach (not TransactionCase)
2026-01-25 10:15:52 +01:00
b6a0f0462d feat: MQTT integration - auto-start, session detection, UI fixes
- Auto-start connections after Odoo restart via _register_hook()
- Start/Stop buttons with invalidate_recordset() and reload action
- Session detection with ShellyParser (RPC, telemetry, status)
- Fixed imports: datetime, ShellyParser
- Parser matches prototype with device_id, timestamp extraction
- Sessions created/ended based on power > 0 threshold
2026-01-24 23:40:03 +01:00
5fcaef0336 feat(M5): Implement MQTT reconnect, state recovery, and error handling
 M5 Complete - All 21 tests passing

**MQTT Auto-Reconnect:**
- Exponential backoff (1s → 60s) in mqtt_client.py
- Automatic reconnection on disconnect
- Reset delay on successful connect

**State Recovery:**
- load_sessions() and get_running_sessions() in event_storage.py
- restore_state() in session_detector.py
- _restore_running_sessions() in main.py before MQTT connect
- Running sessions continue with timeout detection after restart

**Error Handling:**
- All parsers wrapped in try-except (shelly_parser, session_detector)
- Errors logged with exc_info=True for debugging
- Bridge continues running on malformed messages

**Bug Fixes:**
- Fixed field name mismatch: duration_s → total_duration_s
- Fixed None handling in session end methods
- Fixed infinite recursion in _read_sessions()

Test Results: 21 passed in 175.46s (0:02:55)
2026-01-24 19:21:05 +01:00
bb3e492d30 feat: Add multi-device support (M4)
- Support multiple machines in parallel
- Each device uses unique topic_prefix
- Add 3 integration tests for multi-device scenarios
- Update config.yaml.example with 2-machine setup
- All 8 integration tests passing
- Test scenarios: parallel sessions, independent timeouts, different thresholds
2026-01-24 13:01:41 +01:00
aeb8e5660b feat: Add timeout detection and comprehensive test suite
- Implement check_timeouts() for session timeout detection (20s)
- Fix code duplication bug in session_detector.py
- Add periodic timeout check in main loop (every 1s)
- Add 13 unit tests for session detection
- Add 5 integration tests with real MQTT broker
- Document Odoo integration strategy in README
- Remove hardcoded credentials, use env vars
- All 18 tests passing
2026-01-24 11:32:23 +01:00
4c03959437 feat(mqtt): Implement M0-M3 - MQTT IoT Bridge with Session Detection
- M0: MQTT Client with TLS/SSL support
  - Connection to mqtt.majufilo.eu:8883
  - Topic subscription with wildcards
  - JSON payload parsing

- M1: Shelly PM Mini G3 Integration
  - Status message parser (shaperorigin/status/pm1:0)
  - Custom MQTT topic prefix support
  - Power, voltage, current, frequency extraction
  - Device mapping via topic_prefix

- M2: Event Normalization
  - Event Schema v1 with UUID-based event IDs
  - ISO 8601 UTC timestamps
  - Machine/Device info mapping
  - Metrics normalization (power_w, voltage_v, current_a, frequency_hz)
  - Filter None values

- M3: Session Detection Engine
  - State machine: IDLE → STARTING → RUNNING → STOPPING → IDLE
  - Power-based threshold detection (configurable per machine)
  - Debounce logic (separate for start/stop)
  - Session events with duration calculation
  - Persistent storage (JSONL for events, JSON for sessions)
  - Odoo-ready data format for future migration

Data Storage:
- events.jsonl: JSON Lines format (one event per line)
- sessions.json: Session records with start/end/duration
- Ready for migration to open_workshop.session model

Multi-device ready: Add devices via config.yaml with unique topic_prefix
2026-01-22 19:59:17 +01:00