products.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """Check products info"""
  2. import sys
  3. from custom_components.tuya_local.helpers.device_config import (
  4. TuyaDeviceConfig,
  5. available_configs,
  6. )
  7. def main():
  8. missing = False
  9. nameonly = False
  10. arg_supplied = False
  11. for arg in sys.argv[1:]:
  12. arg_supplied = True
  13. if arg == "--missing":
  14. missing = True
  15. elif arg == "--nameonly":
  16. nameonly = True
  17. else:
  18. print("List potential issues with products listings")
  19. print("")
  20. print(f"Usage: {sys.argv[0]} [--missing] [--nameonly]")
  21. exit(1)
  22. # default to nameonly if no arguments supplied
  23. if not arg_supplied:
  24. nameonly = True
  25. for config in available_configs():
  26. device = TuyaDeviceConfig(config)
  27. products = device._config.get("products", None)
  28. if products:
  29. for product in products:
  30. if (
  31. product.get("name")
  32. and not product.get("manufacturer")
  33. and not product.get("model")
  34. ):
  35. if nameonly:
  36. print(
  37. f"{config}: {product['name']} may need splitting to manufacturer and model"
  38. )
  39. else:
  40. if missing:
  41. print(f"{config}: No products")
  42. if __name__ == "__main__":
  43. sys.exit(main())