Major updates: - Complete Rust rewrite (pilot-v2/) with working MQTT client - Fixed MQTT event loop deadlock (background task pattern) - Battery telemetry for Linux (auto-detected via /sys/class/power_supply) - Home Assistant auto-discovery for all sensors and switches - Comprehensive documentation (AVANCEMENT.md, CLAUDE.md, roadmap) - Docker test environment with Mosquitto broker - Helper scripts for development and testing Features working: ✅ MQTT connectivity with LWT ✅ YAML configuration with validation ✅ Telemetry: CPU, memory, IP, battery (Linux) ✅ Commands: shutdown, reboot, sleep, screen (dry-run tested) ✅ HA discovery and integration ✅ Allowlist and cooldown protection Ready for testing on real hardware. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
73 lines
2.8 KiB
Markdown
73 lines
2.8 KiB
Markdown
<!-- Codex created 2025-12-29_0224 -->
|
|
# Analyse v1 (etat des lieux)
|
|
|
|
## Objectif
|
|
- Agent MQTT de pilotage PC pour Home Assistant.
|
|
- Publie des capteurs (CPU, RAM, batterie, GPU, IP) et expose des commandes (shutdown, reboot, ecran, frequence CPU).
|
|
|
|
## Technologies et dependances
|
|
- Python 3
|
|
- paho-mqtt
|
|
- psutil
|
|
- pynvml (GPU, selon variante)
|
|
- systemd (service Linux)
|
|
|
|
## Points d'entree / scripts
|
|
- `main.py` : variante desktop + GPU temp/memoire, shutdown.
|
|
- `main_prog.py` : variante laptop (Lenovo), shutdown/reboot/ecran/freq CPU + telemetrie + slider.
|
|
- `main-lenovo-bureau.py` : variante desktop (CPU/RAM), shutdown.
|
|
- `mqtt_unvai.py` : publie availability=offline puis se termine.
|
|
- `mqtt_pilot.service` : service systemd pointant vers `main_prog.py`.
|
|
|
|
## MQTT (topics et payloads)
|
|
Les topics sont hardcodes et varient selon le script.
|
|
|
|
### Variante main_prog.py (device_name = yoga14)
|
|
- Discovery: `homeassistant/<component>/yoga14/<entity>/config` (retain=true)
|
|
- Commandes:
|
|
- `pilot/yoga14/shutdown/set` payload OFF -> shutdown
|
|
- `pilot/yoga14/reboot/set` payload OFF -> reboot
|
|
- `pilot/yoga14/screen/set` payload ON/OFF -> busctl (GNOME)
|
|
- `pilot/yoga14/cpu_frequency_slider/set` payload float GHz -> write /sys
|
|
- States: `pilot/yoga14/<entity>/state` (retain=true)
|
|
- Availability: `pilot/yoga14/<entity>/available` (retain=true)
|
|
|
|
### Variante main.py / main-lenovo-bureau.py (hostname dynamique)
|
|
- Discovery: `homeassistant/<component>/<hostname>/<entity>/config` (retain=true)
|
|
- Commandes:
|
|
- `pilot/<hostname>/shutdown/available` payload OFF -> shutdown
|
|
- States: `pilot/<hostname>/<sensor>` (retain=true)
|
|
- Availability: `pilot/<hostname>/<sensor>/available` (retain=true)
|
|
|
|
Auth/TLS/LWT: Non trouve (pas de TLS ni LWT, username/password vides).
|
|
|
|
## Commandes systeme
|
|
- Shutdown : `sudo shutdown -h now`
|
|
- Reboot : `sudo reboot`
|
|
- Ecran : `busctl --user set-property ... PowerSaveMode i 1/0`
|
|
- Frequence CPU : ecriture `/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed`
|
|
|
|
## Service systemd
|
|
- Fichier: `mqtt_pilot.service`
|
|
- ExecStart: `/home/gilles/pilot/monenv/bin/python3 /home/gilles/pilot/main_prog.py`
|
|
- Restart: on-failure
|
|
- ExecStopPost: `mqtt_unvai.py` (publie offline)
|
|
|
|
## Config
|
|
- Hardcode dans les scripts (broker, topics, device_name, intervals).
|
|
- Pas de .env ou YAML.
|
|
|
|
## Points faibles
|
|
- Securite: pas d'auth/TLS, commandes privilegiees, pas d'allowlist.
|
|
- Config: hardcodee, duplication entre scripts.
|
|
- MQTT: pas de LWT, pas de QoS explicite, pas de schema de payload formalise.
|
|
- Observabilite: logs stdout simples, pas de tests.
|
|
|
|
## Ce que la v2 doit corriger
|
|
- Contrat MQTT unique et documente.
|
|
- Config YAML centralisee.
|
|
- Auth/TLS optionnel, allowlist et validation des payloads.
|
|
- LWT + status + capabilities.
|
|
- Separation Linux/Windows avec backends.
|
|
<!-- Codex modified 2025-12-29_0224 -->
|