mirror of
https://github.com/Ladebeze66/tuya_project.git
synced 2025-12-16 00:36:56 +01:00
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Script pour afficher le statut de tous les appareils Tuya connus
|
|
Utile pour avoir une vue d'ensemble rapide
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import json
|
|
|
|
# Ajouter le répertoire parent au path pour les imports
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
from common.utils import connect_device, get_device_status_text
|
|
|
|
def main():
|
|
"""Fonction principale pour afficher le statut des appareils"""
|
|
print("Récupération du statut des appareils Tuya...\n")
|
|
|
|
# Charger la liste des appareils depuis devices.json
|
|
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
devices_file = os.path.join(base_dir, 'devices.json')
|
|
|
|
try:
|
|
with open(devices_file, 'r', encoding='utf-8') as f:
|
|
devices = json.load(f)
|
|
except Exception as e:
|
|
print(f"Erreur lors du chargement du fichier devices.json: {e}")
|
|
return
|
|
|
|
# Catégoriser les appareils
|
|
categories = {
|
|
"lights": [], # Lumières
|
|
"shutters": [], # Volets
|
|
"plugs": [], # Prises
|
|
"cameras": [], # Caméras
|
|
"others": [] # Autres appareils
|
|
}
|
|
|
|
# Trier les appareils par catégorie
|
|
for device in devices:
|
|
device_id = device.get('id')
|
|
device_name = device.get('name', 'Appareil inconnu')
|
|
product_key = device.get('product_id', '')
|
|
|
|
# Classifier selon le type
|
|
if product_key in ['key8u54q9dtru5jw', 'keynremrcjf97twe']:
|
|
categories["lights"].append((device_id, device_name))
|
|
elif product_key in ['4pqpkp1rskkjtxay']:
|
|
categories["shutters"].append((device_id, device_name))
|
|
elif product_key in ['uqehhcrmk5depvtl']:
|
|
categories["plugs"].append((device_id, device_name))
|
|
elif product_key in ['biw8urjw2dvss3ur', 'pg7xibyidyvt5pia']:
|
|
categories["cameras"].append((device_id, device_name))
|
|
else:
|
|
categories["others"].append((device_id, device_name))
|
|
|
|
# Afficher le statut par catégorie
|
|
for category, cat_devices in categories.items():
|
|
if not cat_devices:
|
|
continue
|
|
|
|
print(f"\n=== {category.upper()} ===")
|
|
|
|
for device_id, device_name in cat_devices:
|
|
status_text = get_device_status_text(device_id)
|
|
print(f" - {status_text}")
|
|
|
|
print("\nTerminé!")
|
|
|
|
if __name__ == "__main__":
|
|
main() |