mirror of
https://github.com/Ladebeze66/tuya_project.git
synced 2025-12-15 19:26:57 +01:00
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Script pour scanner et afficher tous les appareils Tuya disponibles sur le réseau
|
|
Utile pour diagnostiquer les problèmes de connexion
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import json
|
|
import time
|
|
|
|
# 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 scan_for_devices
|
|
|
|
def main():
|
|
"""Fonction principale pour scanner et afficher les appareils"""
|
|
print("Recherche des appareils Tuya sur le réseau...")
|
|
print("Veuillez patienter, cela peut prendre jusqu'à 30 secondes...")
|
|
|
|
# Réaliser un scan du réseau
|
|
devices = scan_for_devices()
|
|
|
|
if not devices:
|
|
print("Aucun appareil trouvé sur le réseau.")
|
|
return
|
|
|
|
print(f"\nAppareils trouvés: {len(devices)}\n")
|
|
|
|
# Afficher les informations détaillées pour chaque appareil
|
|
for device in devices:
|
|
print("="*50)
|
|
print(f"Nom : {device.get('name', 'Inconnu')}")
|
|
print(f"ID : {device.get('id', 'N/A')}")
|
|
print(f"IP : {device.get('ip', 'N/A')}")
|
|
print(f"Produit : {device.get('productKey', 'N/A')}")
|
|
print(f"Version : {device.get('ver', 'N/A')}")
|
|
|
|
# Afficher l'état actuel si disponible
|
|
if 'dps' in device:
|
|
print("\nÉtat actuel:")
|
|
try:
|
|
# Formater les DPS pour une meilleure lisibilité
|
|
dps_formatted = json.dumps(device['dps'], indent=2, ensure_ascii=False)
|
|
print(dps_formatted)
|
|
except:
|
|
print(device['dps'])
|
|
|
|
print("="*50 + "\n")
|
|
|
|
# Sauvegarder les résultats dans un fichier snapshot
|
|
timestamp = int(time.time())
|
|
snapshot_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), f"snapshot_{timestamp}.json")
|
|
|
|
with open(snapshot_file, 'w', encoding='utf-8') as f:
|
|
json.dump({"timestamp": time.time(), "devices": devices}, f, indent=4, ensure_ascii=False)
|
|
|
|
print(f"Résultats sauvegardés dans {snapshot_file}")
|
|
|
|
if __name__ == "__main__":
|
|
main() |