products.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """Check products info"""
  2. import sys
  3. from common_funcs import load_config
  4. from custom_components.tuya_local.helpers.device_config import (
  5. available_configs,
  6. TuyaDeviceConfig,
  7. )
  8. def main():
  9. missing = False
  10. nameonly = False
  11. arg_supplied = False
  12. for arg in sys.argv[1:]:
  13. arg_supplied = True
  14. if arg == "--missing":
  15. missing = True
  16. elif arg == "--nameonly":
  17. nameonly = True
  18. else:
  19. printf("List potential issues with products listings")
  20. printf("")
  21. print(f"Usage: {sys.argv[0]} [--missing] [--nameonly]")
  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())