Commit Graph

14 Commits

Author SHA1 Message Date
8d7be4b9a7 feat(pos-mqtt): produktgefilterte Sessions + sichtbares Orderline-Icon
- Maschinenzeit-Icon nur bei gemappten Produkten (OrderSummary Patch)

- Session-Suggestions auf gewählte Produkt-ID gefiltert

- Debug-Dialog bei leerem Zeitfenster inkl. Produkt/Von/Bis

- Asset-Switch auf order_summary Implementierung

- Implementierungsplan Schritt-4 Review ergänzt
2026-02-21 17:35:23 +01:00
f0881c3c2c feat: MVP Step 4 - PoS Maschinenzeit-Übernahme produktiv
- ControlButtons-Extension mit stabiler Template-Inheritance (hasclass XPath)
- MachineTimeSelectionPopup Komponente für Session-Auswahl und Minuten-Bearbeitung
- Backend Service get_pos_session_suggestions mit Overlap + Rounding
- Seed-Tool für reproducible Test-Sessions
- PoS-Mapping-Backend für Device-to-Product-Zuordnung
- Entfernt: fehleranfällige ProductScreen-Extension (Owl-Crash behoben)

Workflow im PoS:
1. Orderline auswählen
2. 'Maschinenzeit'-Button klicken (ControlButtons)
3. Session-Popup mit Vorschlägen + editierbaren Minuten
4. Auswahl bestätigen → Quantity in Orderline durch Summe ersetzen

Akzeptanzkriterien Step 4 erfüllt:
✓ Button sichtbar und erreichbar
✓ Popup öffnet und schließt korrekt
✓ Vorschläge sichtbar und auswählbar
✓ Übernahme schreibt in Auftrag
✓ 'Keine Sessions'-Hinweis bei Leerfall
✓ Keine Crashes mehr
2026-02-21 16:08:01 +01:00
fb0710c680 fix(odoo): close stale running sessions on new starts 2026-02-19 20:42:52 +01:00
f7b5a28f9a Fix: sync device status timeout with Odoo message timeout
- Include device_status_timeout_s in Odoo bridge payload
- Resolve status monitor timeout robustly with backward-compatible fallbacks
- Update running status monitor timeout on POST /config without restart
- Keep compatibility for legacy/local configs without device_status_timeout_s

Result: shaperorigin uses configured 90s timeout for online/offline monitor, preventing 30s flapping.
2026-02-19 18:40:30 +01:00
e723315e35 Fix: Unify device_status timeout with message_timeout_s
Problem: Device Status Monitor was using a hardcoded 30-second global timeout
for marking devices offline, independent of the configurable message_timeout_s.
This caused alternating offline/online events for devices with power=0 that
don't send frequent MQTT messages.

Solution: Use the same timeout value (message_timeout_s) for both:
1. Session Detection (message_timeout_s)
2. Device Status Monitoring (device_status_timeout_s)

Implementation:
- Add device_status_timeout_s field to api/models.py DeviceConfig (default: 120s)
- Update Odoo iot_api.py to include device_status_timeout_s in config response
  (synchronized with message_timeout_s from device strategy config)
- Update Bridge service_manager.py to use device_status_timeout_s when
  initializing DeviceStatusMonitor (fallback to global config if not provided)

Result:
- Single configurable timeout per device in Odoo
- Both checks (session + device status) use same value
- Backward compatible (defaults to 120s if not provided)
- Solves alternating offline/online events for low-power/idle devices

Validation:
- mypy: 0 errors across 47 files
- API model test: device_status_timeout_s field functional
2026-02-19 00:09:22 +01:00
ca31e3f4a6 Update README.md 2026-02-18 23:29:36 +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
d3a28fddb6 feat: benutzerfreundliche GUI für Device-Konfiguration mit Auto-Config-Push
Hauptänderungen:
─────────────
 Benutzerfreundliche GUI statt JSON-Eingabe
  • Abrechnungs-Intervall (Minuten) - klar verständlich statt heartbeat_interval_s
  • Einschalt-/Arbeits-Schwellen (Watt) - statt technischer Begriffe
  • Anlauf-/Abschalt-Verzögerung (Sekunden) - erklärt was es tut
  • Icons, Hilfe-Texte, Beispiele direkt am Feld

🔄 Auto-Config-Push an Bridge
  • write() Hook: Automatischer Push bei Feldänderungen
  • create() Hook: Push bei neuem Device
  • unlink() Hook: Push bei Device-Löschung
  • Retry-Logic: 3 Versuche mit exponential backoff
  • Manueller Button: 🔄 Push Config to Bridge

📊 Transparente Abrechnung
  • Duration-Breakdown: Total = Working + Standby + Idle
  • Alle Zeiten in Minuten (billing-friendly)
  • Idle-Zeit zeigt Overhead (Debounce/Timeout) transparent

🧹 Code-Cleanup
  • Deprecated write() Hook entfernt
  • Überflüssige _onchange_session_strategy() entfernt
  • Computed Field: strategy_config automatisch generiert
  • Validation mit verständlichen deutschen Fehlermeldungen

Technische Details:
──────────────────
Models (mqtt_device.py):
  • billing_interval_min, power_on_threshold_w, active_work_threshold_w,
    startup_delay_s, shutdown_delay_s, message_timeout_s
  • Computed: strategy_config = f(alle benutzerfreundlichen Felder)
  • relevant_fields erweitert für Auto-Push Trigger

Views (mqtt_device_views.xml):
  •  Leistungs-Schwellenwerte
  • ⏱️ Zeitsteuerung
  • 💰 Abrechnung mit Info-Box
  • Generierte Config (readonly) für Debugging

Sessions (mqtt_session.py):
  • idle_duration_s = max(0, total - working - standby)
  • *_duration_min Felder für alle Zeiten
  • Displays konvertiert: hours → minutes

Bridge (session_detector.py):
  • Payload standardisiert: power_w, state (konsistent in allen Events)
  • Heartbeat-Intervall aus Odoo billing_interval_min

Feature Request:
  • Implementierungsstatus aktualisiert (Phase 1+2 komplett)
  • Lessons Learned dokumentiert
  • Nächste Schritte definiert

 Tests bestätigt:
  • Events kommen im konfigurierten Abrechnungs-Intervall (1 Min)
  • Config-Push funktioniert automatisch
  • Duration-Breakdown ist transparent
  • GUI ist verständlich und hilfreich
2026-02-17 00:09:51 +01:00
0b6e41d207 refactor: standardize model naming to ows.* prefix for consistency
BREAKING CHANGE: Renamed models for consistent naming convention
- mqtt.device → ows.mqtt.device (table: ows_mqtt_device)
- mqtt.session → ows.mqtt.session (table: ows_mqtt_session)
- ows.iot.event unchanged (table: ows_iot_event)

Changes:
- Updated all Many2one/One2many relations to use new model names
- Updated all env references in controllers and tests
- Updated security CSV file with new model IDs
- Updated all view records (list/form/kanban/pivot/graph/search)
- Fixed controller reference that was still using old mqtt.session

Documentation:
- Added README.md for user-facing module documentation
- Regenerated API.md from updated docstrings
- Regenerated index.html from README.md

Cleanup:
- Removed debug/test files (check_routes.py, test-*.sh/txt)
- Removed obsolete python_proto_type directory

Note: This requires database migration or fresh setup.
Database was reset and module reinstalled successfully.
E2E test with Shelly Simulator passed.
2026-02-15 13:56:52 +01:00
78b9befc26 Changed Odoo Test Database from OWS_MQTT to odoo 2026-02-15 11:07:21 +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
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
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
8c27373697 initial MQTT Development 2026-02-11 21:07:32 +01:00