Phase 1.4 abgeschlossen: Event Queue mit exponential backoff retry logic Neue Features: - event_queue.py: Thread-safe Queue mit Retry-Mechanismus * Exponential backoff: 2^retry_count, max 60s * Max 10 retries pro Event * Background-Thread für kontinuierliche Verarbeitung * Queue-Statistiken (pending, sent, failed, retry counts) - Event-UID Generation (UUID) in allen Events * session_started, session_heartbeat, session_ended, session_timeout * Ermöglicht Idempotenz in Odoo - MockOdooClient Failure-Simulation * mock_failure_rate (0.0-1.0) in config.yaml * Wirft Exceptions für Retry-Testing - Config-Erweiterungen * LoggingConfig.log_file (Optional[str]) * OdooConfig.mock_failure_rate (float, default 0.0) Änderungen: - main.py: Queue-Integration mit Background-Thread * on_event_generated() nutzt Queue statt direktem send * Graceful shutdown: Queue-Processing vor MQTT-Disconnect * Alte IotBridge-Klasse entfernt (duplicate code cleanup) - session_detector.py: event_uid zu allen Events hinzugefügt - odoo_client.py: MockOdooClient mit failure_rate Parameter Tests (alle PASSED): - Unit Tests: test_event_queue.py (13/13 passed) * QueuedEvent retry logic & exponential backoff * Queue operations (enqueue, statistics) * Successful send, retry scenarios, max retries exceeded - Integration Tests: test_retry_logic.py (2/2 passed in 48.29s) * test_retry_on_odoo_failure: Events werden bei Failures enqueued * test_eventual_success_after_retries: 50% failure → eventual success Bridge ist jetzt resilient gegen Odoo-Ausfälle! |
||
|---|---|---|
| .. | ||
| iot_bridge | ||
| models | ||
| python_prototype | ||
| security | ||
| services | ||
| tests | ||
| views | ||
| __init__.py | ||
| __manifest__.py | ||
| FEATURE_REQUEST_OPEN_WORKSHOP_MQTT_IoT.md | ||
| IMPLEMENTATION_PLAN.md | ||
| README.md | ||
| run-tests.sh | ||
| test-direct.sh | ||
| test-output.txt | ||
| TODO.md | ||
Open Workshop MQTT
MQTT IoT Device Integration for Odoo 18
Features
- ✅ MQTT Broker Connection - Connect to external MQTT brokers (Mosquitto, etc.)
- ✅ Device Management - Configure and monitor IoT devices
- ✅ Session Tracking - Automatic runtime session detection
- ✅ Flexible Parsers - Support for Shelly PM Mini G3, Tasmota, Generic JSON
- ✅ Session Strategies - Power threshold, Last Will Testament, Manual control
- ✅ Analytics - Pivot tables and graphs for runtime analysis
- ✅ Auto-Reconnect - Exponential backoff on connection loss
- ✅ Message Logging - Debug log for MQTT messages
Installation
-
Install Python dependencies:
pip install paho-mqtt -
Install the module in Odoo:
- Apps → Update Apps List
- Search for "Open Workshop MQTT"
- Click Install
Quick Start
-
Create MQTT Connection
- MQTT → Connections → Create
- Enter broker details (host, port, credentials)
- Click "Test Connection" then "Start"
-
Add Device
- MQTT → Devices → Create
- Select connection
- Configure device ID and topic pattern
- Choose parser type (Shelly, Tasmota, etc.)
- Set session detection strategy
-
Monitor Sessions
- MQTT → Sessions
- View runtime analytics in Pivot/Graph views
Session Detection Strategies
Power Threshold (Recommended)
- Dual threshold detection (standby/working)
- Configurable debounce timers
- Timeout detection
- Reference:
python_prototype/session_detector.py
Last Will Testament
- Uses MQTT LWT for offline detection
- Immediate session end on device disconnect
Manual
- Start/stop sessions via buttons or MQTT commands
Configuration Example
Shelly PM Mini G3:
{
"standby_threshold_w": 20,
"working_threshold_w": 100,
"start_debounce_s": 3,
"stop_debounce_s": 15,
"message_timeout_s": 20
}
Optional: Maintenance Integration
Install open_workshop_mqtt_maintenance (separate module) to link MQTT devices to maintenance.equipment.
Technical Reference
See python_prototype/ directory for:
- Implementation reference
- Test suite (pytest)
- Session detection logic
- MQTT client implementation
Support
- Documentation: See
python_prototype/README.md - Issues: GitHub Issues
- Tests:
pytest python_prototype/tests/ -v
License
LGPL-3