Commit Graph

7 Commits

Author SHA1 Message Date
5a27dc6a65 refactor: Remove old service-based MQTT integration
Removed deprecated in-process MQTT service in favor of standalone IoT Bridge container:

Deleted:
- services/ directory (iot_bridge_service, mqtt_client, session_detector, parsers)
- Old tests (test_mqtt_connection, test_mqtt_mocked, test_session_detector, test_topic_matching, test_no_duplicate_messages)

Modified:
- mqtt_connection.py: action_start/stop now show deprecation message
- mqtt_connection.py: Auto-start on Odoo restart disabled
- mqtt_device.py: Auto-subscribe on device changes disabled
- tests/__init__.py: Removed old test imports
- tests/common.py: Replaced with stub (legacy support only)

Reason:
- Old integration ran MQTT client in Odoo process (tight coupling)
- New architecture: Standalone IoT Bridge container + REST API
- Better separation of concerns, scalability, and maintainability
- All functionality moved to iot_bridge/ (Phase 1) + REST API (Phase 2)

All old code is preserved in git history if needed.
Models (mqtt.device, mqtt.session, mqtt.connection, ows.iot.event) remain unchanged.
2026-02-05 16:49:18 +01:00
c55b0e59d2 feat(odoo): IoT Bridge Phase 2 - Odoo REST API
Phase 2.1 - Models:
- ows.iot.event Model für Event-Logging
  - event_uid (unique constraint) für Duplikat-Prävention
  - event_type (session_started/updated/stopped/timeout/heartbeat)
  - payload_json mit auto-extraction (power_w, state)
  - Auto-Linking zu mqtt.device und mqtt.session
  - Processing-Status tracking
- mqtt.device erweitert mit device_id (External ID für API)
- Existing mqtt.session bereits perfekt strukturiert

Phase 2.2 - REST API Controller:
- GET /ows/iot/config
  - Returns aktive Devices mit session_config als JSON
  - Public auth (später API-Key optional)
- POST /ows/iot/event
  - JSON-RPC Format (Odoo type='json')
  - Schema-Validation (required: event_uid, event_type, device_id, timestamp)
  - Duplikat-Check: 409 Conflict für idempotency
  - Auto-Processing: Session create/update/complete
  - Response codes: 201/409/400/500

Phase 2.3 - Bridge OdooClient:
- Echte REST API Implementation
  - get_config(): GET /ows/iot/config
  - send_event(): POST /ows/iot/event (JSON-RPC)
  - Duplicate handling (409 = success)
  - HTTP Session mit requests library
- config.py: OdooConfig mit base_url, database, username, api_key
- main.py: Conditional OdooClient/MockOdooClient based on use_mock

Testing Guide:
- PHASE2_TESTING.md mit kompletter Anleitung
- Manuelle API Tests (curl examples)
- Integration Test Steps (Odoo + Mosquitto + Bridge)
- Success Criteria Checklist

Bereit für Phase 2.4 Integration Testing!
2026-02-05 16:43:26 +01:00
92f9548d34 WIP: Duplikate-Fix und ausführliche Service-Dokumentation
- Entfernt doppelte Topic-Subscription (war Ursache für Duplikate)
- Subscription passiert nur noch in _on_connect() Callback
- Ausführliche Dokumentation in iot_bridge_service.py hinzugefügt
- Test für Duplikate erstellt (test_no_duplicate_messages.py)
- Recovery-Logik für Container-Restart dokumentiert

HINWEIS: Service-Design muss überarbeitet werden!
- Aktuell: Lazy Init, manueller Start
- Sollte sein: Auto-Init beim Odoo-Start, always-on MQTT
- Nächster Schritt: Odoo 18 Service Pattern + MQTT Bridge Pattern recherchieren
2026-01-31 11:19:44 +01:00
b46fed0f8e feat: SessionDetector Integration - Live-Tracking & Timeout Worker
Integriert SessionDetector vollständig in iot_bridge_service:

iot_bridge_service.py:
- SessionDetector Import & _detectors Dictionary
- Timeout Worker Thread für automatisches Session-Ende
- _restore_detector_states() bei Service-Start
- _get_or_create_detector() Factory Methode
- _process_session() ruft detector.process_power_event(env, power, ts)
- _timeout_worker_loop() prüft alle 10s auf Timeouts

models/mqtt_session.py:
- current_power_w Field für Live-Power Updates
- current_state Field für State Machine Status (idle/starting/standby/working/stopping)
- last_message_time Field für Timeout Detection

tests/__init__.py:
- Import test_session_detector Module

Diese Änderungen sind essentiell für SessionDetector!
Ohne sie würde der Detector nicht aufgerufen werden.
2026-01-30 16:49:50 +01:00
f1b0c50fbf fix: MQTT topic matching + UI button fixes
- Fix MQTT topic pattern matching (_mqtt_topic_matches):
  * Implement proper # wildcard (multi-level)
  * Implement proper + wildcard (single-level)
  * Fix bug where first device got ALL messages
  * Now shaperorigin/# only matches shaperorigin/* topics

- Fix Stop Connection button (Odoo-style):
  * Remove manual commit() - let Odoo handle it
  * Use write() to update state
  * Handle case where service doesn't have connection

- Fix Test Connection hanging:
  * Add proper cleanup with sleep after disconnect
  * Catch cleanup exceptions

- Add @unittest.skip to real MQTT tests:
  * TransactionCase incompatible with paho-mqtt threads
  * See TODO.md M8 for details

- Fix run-tests.sh:
  * Remove -i flag (was hanging)
  * Simplify to direct output redirect

- Add TODO.md documentation
- Update .gitignore for test logs
2026-01-28 22:08:59 +01:00
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