Commit Graph

9 Commits

Author SHA1 Message Date
e82c73441b Update Implementation Plan 2026-02-18 21:20:22 +01:00
3eaf2e933d feat: IoT Bridge Health Monitoring & Dynamic MQTT Reconnection
Features:
- Added ows.mqtt.bridge model with health status monitoring
- Bridge list/form views with status indicators (Online/Offline/Unknown)
- Scheduled action for periodic health checks (every 2 minutes)
- Health metrics: devices count, subscriptions, last seen timestamp
- Manual health check button in UI
- Smart button linking brokers to bridge instance

Infrastructure:
- Added ows.mqtt.broker model for MQTT broker configurations
- Bridge-Broker relation via Many2one field
- Dynamic MQTT reconnection without container restart
- Robust startup: Bridge starts even when MQTT fails
- TLS reconfiguration limitation documented (paho-mqtt)

Technical Changes:
- Updated models to use @api.model_create_multi for Odoo 18
- Fixed view definitions: tree → list for Odoo 18 compatibility
- Removed mail.thread dependency (unnecessary chatter)
- Added ir.cron for automated health monitoring
- Security/ACL rules for bridge and broker models
- Menu integration under IoT/MQTT section

Documentation:
- Updated IMPLEMENTATION_PLAN.md with new features
- Updated Odoo module README with bridge/broker models
- iot_bridge/README.md already documents dynamic reconnection

Testing:
- All changes tested via Odoo module upgrade
- Health check endpoint verified: GET /health
- Bridge reconnection tested with broker config changes
2026-02-18 20:36:11 +01:00
ba588842ad feat: Add automatic API documentation generation and device status monitoring
- Implement build script (build_docs.py) with AST parser to auto-generate HTML docs from docstrings
- Add comprehensive Google-style docstrings to all controllers and models
- Create static/description/index.html for Odoo Apps UI with module overview
- Generate api_reference.html (20.5 KB) from source code, linked from Odoo UI
- Add DOCUMENTATION_STRATEGY.md with comparison of 5 documentation approaches
- Create API.md with complete REST API documentation

Device Status Monitoring:
- Implement device_status_monitor.py with health checks and offline detection
- Add /status endpoint for device health overview
- Automatic offline detection after message_timeout_s

Config Push Architecture:
- Add POST /config endpoint to IoT Bridge for dynamic device management
- Auto-push device config from Odoo on create/write/unlink
- Implement device_manager.py for runtime device updates

E2E Tests:
- All 6 E2E tests passing (Create, Update, Push, Delete, Restart, Status Monitor)
- Test coverage for device lifecycle and config synchronization

Documentation is auto-generated via: ./build_docs.sh
View in Odoo: Settings → Apps → Open Workshop MQTT → API Reference
2026-02-15 11:03:22 +01:00
f1af17fd39 docs: complete phase 4 documentation 2026-02-12 21:12:02 +01:00
deaa95c650 refactor: Remove legacy PULL config methods (Phase 3.3)
Completes PUSH-only architecture - removes all PULL-based config fetching

REMOVED:
- MockOdooClient.get_config() method (~15 lines)
  - Legacy PULL logic: returned hardcoded device config
  - No longer used after PUSH architecture (Phase 3.1/3.2)

- OdooClient.get_config() method (~27 lines)
  - Legacy PULL logic: GET /ows/iot/config from Odoo
  - No longer used after PUSH architecture (Phase 3.1/3.2)

VERIFIED:
-  No periodic config refresh logic in main.py
-  Bridge loads config-active.yaml at startup only
-  Bridge receives config via POST /config (pushed by Odoo)
-  No GET requests to Odoo for config anymore

KEPT (unchanged):
- odoo_client.send_event() - still used for event pushing
- config_server.py GET /config - returns bridge's current config (debugging)

ARCHITECTURE CLEANUP:
Before: Bridge could PULL config from Odoo (get_config)
After:  Bridge ONLY receives PUSH from Odoo (POST /config)
        - Cleaner separation of concerns
        - No periodic polling overhead
        - Bridge fully autonomous with config-active.yaml

MODIFIED FILES:
- iot_bridge/odoo_client.py                          - ~40 lines removed
- IMPLEMENTATION_PLAN.md                            - Phase 3.3 marked complete

TESTING:
 Bridge still runs without config-active.yaml (waits for push)
 Bridge loads config-active.yaml at startup
 No errors in bridge logs (no missing get_config calls)
 Odoo push still works (Phase 3.2 model hooks)

NEXT STEP:
Phase 3.5 - End-to-End Tests (full PUSH architecture validation)
2026-02-12 20:28:54 +01:00
7337e57b40 feat: Implement Odoo Config-Push System (Phase 3.2)
Completes PUSH architecture - Odoo automatically pushes config to Bridge

NEW FEATURES:
- Model Hooks in mqtt.device (create/write/unlink)
  - Automatically push config after device create/update/delete
  - Smart detection: only relevant fields trigger push
  - Non-blocking: UI works even if bridge is offline

- Config Builder (_build_bridge_config)
  - Collects all active mqtt.device records
  - Converts to Bridge-compatible JSON format
  - Topic pattern transformation (/#→/status/pm1:0)
  - Session config extraction from strategy_config JSON
  - Returns BridgeConfig schema with timestamp + version

- HTTP Client with Retry Logic (_push_bridge_config)
  - POST to bridge_url/config with JSON payload
  - 3 retries with exponential backoff (1s, 2s, 4s)
  - Timeout: 10 seconds per request
  - Error handling: 4xx no retry, 5xx retry
  - Returns success/message dict for UI notifications

- System Parameter for Bridge URL
  - Configurable via ir.config_parameter
  - Key: open_workshop_mqtt.bridge_url
  - Default: http://iot-bridge:8080
  - Stored in data/system_parameters.xml

- Manual Push Button in UI
  - '🔄 Push Config to Bridge' button in device list header
  - Calls action_push_config_to_bridge()
  - Shows success/error notification toast
  - Allows manual sync when needed

NEW FILES:
- data/system_parameters.xml                          - Bridge URL param
- tests/test_config_push_integration.py              - Python integration test

MODIFIED FILES:
- models/mqtt_device.py                              - +250 lines (hooks, builder, client)
- views/mqtt_device_views.xml                        - Manual push button
- __manifest__.py                                    - requests dependency, data file

ARCHITECTURE CHANGE:
Before: Bridge pulls config from Odoo via GET /api/config
After:  Odoo pushes config to Bridge via POST /config
        - Triggered automatically on device changes (create/write/unlink)
        - Manual trigger via UI button
        - Bridge receives validated config via FastAPI endpoint

TESTING:
 Model hooks fire on create/write/unlink
 Config builder generates valid JSON
 HTTP client successfully pushes to bridge
 Retry logic works (tested with bridge down→up)
 Manual button displays notifications
 Bridge receives and applies config
 Device add/update/remove reflected in bridge

NEXT STEP:
Phase 3.3 - Remove legacy get_config() from bridge (no longer needed)
2026-02-12 20:18:13 +01:00
19be0903d2 feat: Implement HTTP Config API for Bridge (Phase 3.1)
Implements PUSH architecture - Bridge receives config from Odoo via HTTP

NEW FEATURES:
- HTTP Config Server (FastAPI on port 8080)
  - POST /config: Receive device configuration from Odoo
  - GET /config: Query currently active configuration
  - GET /health: Health check endpoint with device statistics
  - Optional Bearer token authentication (BRIDGE_API_TOKEN)

- Config Validation (Pydantic models)
  - BridgeConfig, DeviceConfig, SessionConfig schemas
  - Validation: unique device_id, unique mqtt_topic
  - Threshold validation: working_threshold_w > standby_threshold_w

- Dynamic Device Management (DeviceManager)
  - Device diff detection (add/update/remove)
  - Automatic MQTT subscribe/unsubscribe for topic changes
  - SessionDetector lifecycle management
  - Active session closing on device removal

- Config Persistence
  - Saves received config to /data/config-active.yaml
  - Bridge startup: loads config-active.yaml as fallback
  - Docker volume iot-bridge-data:/data for persistence

NEW FILES:
- iot_bridge/config_server.py          - FastAPI HTTP server
- iot_bridge/device_manager.py         - Device lifecycle management
- iot_bridge/tests/test-config-push.sh - Integration test script
- iot_bridge/tests/test-config-push.json - Test configuration

MODIFIED FILES:
- iot_bridge/main.py                   - Integrated HTTP server in thread
- iot_bridge/mqtt_client.py            - Added subscribe()/unsubscribe()
- iot_bridge/requirements.txt          - Added fastapi, uvicorn, pydantic
- iot_bridge/Dockerfile                - EXPOSE 8080, HTTP healthcheck
- odoo/docker-compose.dev.yaml         - Port 8080, volume /data

TESTING:
Verified via iot_bridge/tests/test-config-push.sh:
 Config push via HTTP works (200 OK)
 Old devices removed, new devices added
 MQTT topics dynamically updated (subscribe/unsubscribe)
 Config persisted to /data/config-active.yaml
 Health endpoint shows last_config_update timestamp
 Bridge restarts load config-active.yaml automatically

NEXT STEP:
Phase 3.2 - Implement Odoo-side config push (Model hooks)
2026-02-12 20:05:49 +01:00
18cac263a2 fix: Make IoT Bridge autonomous and fix session closing
Major architectural improvements to make Bridge resilient:

1. Bridge Autonomy (CRITICAL FIX):
   - Remove sys.exit(1) when Odoo config fails (iot_bridge/main.py)
   - Bridge now runs autonomously with local config.yaml
   - No longer crashes in endless restart loop when Odoo is down
   - Odoo connection check becomes optional warning, not blocker

2. Event Type Compatibility:
   - Add 'session_ended' to controller event processing (iot_api.py)
   - Bridge sends 'session_ended', controller expected 'session_stopped'
   - Now accepts both event types for closing sessions

3. Event Type Support:
   - Add 'session_ended' to iot_event model selection (iot_event.py)
   - Fixes 500 errors when Bridge sends session_ended events

4. Architecture Documentation:
   - Update FEATURE_REQUEST with new PUSH architecture (Odoo -> Bridge)
   - Update IMPLEMENTATION_PLAN with Phase 3 refactoring plan
   - Document autonomous mode and config-push design
   - Remove obsolete documentation files

Tested Scenarios:
-  Bridge starts and runs without Odoo
-  Session detection works autonomously
-  Events queue when Odoo is down
-  Queue automatically processes when Odoo returns
-  Sessions close correctly with session_ended events

This enables the next phase: Odoo pushing config to Bridge via HTTP API.
2026-02-12 19:28:25 +01:00
807436df58 initial version 2026-02-10 20:00:27 +01:00