Commit Graph

5 Commits

Author SHA1 Message Date
ff4ef2f563 Phase 3: Complete type safety & logging unification (3.1-3.2)
Phase 3.1: Type Safety
- Add bridge_types.py for shared type aliases (EventDict, PowerWatts, Timestamp, DeviceID)
- Define protocols for callbacks and message parsers
- Strict type annotations on all core modules (session_detector, event_queue, device_manager)
- Fix Optional handling and type guards throughout codebase
- Achieve full mypy compliance: 0 errors across 47 source files

Phase 3.2: Logging Unification
- Migrate from stdlib logging to pure structlog across all runtime modules
- Convert all logs to structured event+fields format (snake_case event names)
- Remove f-string and printf-style logger calls
- Add contextvars support for per-request correlation
- Implement FastAPI middleware to bind request_id, http_method, http_path
- Propagate X-Request-ID header in responses
- Remove stdlib logging imports except setup layer (utils/logging.py)
- Ensure log-level consistency across all modules

Files Modified:
- iot_bridge/bridge_types.py (new) - Central type definitions
- iot_bridge/core/* - Type safety and logging unification
- iot_bridge/clients/* - Structured logging with request context
- iot_bridge/parsers/* - Type-safe parsing with structured logs
- iot_bridge/utils/logging.py - Pure structlog setup with contextvars
- iot_bridge/api/server.py - Added request correlation middleware
- iot_bridge/tests/* - Test fixtures updated for type safety
- iot_bridge/OPTIMIZATION_PLAN.md - Phase 3 status updated

Validation:
- mypy . → 0 errors (47 files)
- All unit tests pass
- Runtime behavior unchanged
- API response headers include X-Request-ID
2026-02-18 23:54:27 +01:00
e675256e0e chore: Apply code quality tools (black, isort, ruff)
Automated code quality improvements:

Black (Code Formatter):
- Reformatted 30 files to match PEP 8 style
- Consistent line length (100 chars)
- Consistent quote style and spacing

isort (Import Sorter):
- Fixed import order in 30+ files
- Grouped imports: stdlib → third-party → first-party → local
- Consistent multi-line import formatting

Ruff (Linter):
- Auto-fixed 161 issues:
  * Modernized type hints (List → list, Optional[X] → X | None)
  * Removed unused imports (json, os, typing utilities)
  * Updated deprecated typing imports (typing.List → list)
  * Simplified type annotations with | operator (Python 3.10+)
- Remaining 20 issues (acceptable):
  * 9x unused-method-argument (callback signatures, cannot be changed)
  * 2x bare-except (intentional for resilience)
  * 2x unused-variable (will be addressed in Phase 2)
  * Minor simplification opportunities (not critical)

Code Quality Stats:
- 32 files modified
- +1749/-1589 lines (net cleanup)
- Code is now consistent and formatted
- Ready for gradual type safety improvements (Phase 3)

All changes are non-functional - pure formatting and import organization.
2026-02-18 22:20:25 +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
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
807436df58 initial version 2026-02-10 20:00:27 +01:00