untranslated_select.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Find translated selects with untranslated mappings in config files."""
  2. import json
  3. import sys
  4. from common_funcs import FakeDevice
  5. from custom_components.tuya_local.helpers.device_config import (
  6. TuyaDeviceConfig,
  7. available_configs,
  8. )
  9. def main() -> int:
  10. with open("custom_components/tuya_local/translations/en.json", "r") as f:
  11. english = json.load(f)
  12. select = english["entity"]["select"]
  13. dev = FakeDevice({})
  14. for config in available_configs():
  15. device = TuyaDeviceConfig(config)
  16. for entity in device.all_entities():
  17. if entity.entity == "select" and entity.translation_key:
  18. d = entity.find_dps("option")
  19. translations = select.get(entity.translation_key)
  20. if translations is None:
  21. print(
  22. f"{config}:{entity._config.__line__}: MISSING {entity.translation_key}"
  23. )
  24. continue
  25. for v in d.values(dev):
  26. if v not in translations["state"]:
  27. print(
  28. f"{config}:{v.__line__}: {v} missing from {entity.translation_key}"
  29. )
  30. return 0
  31. if __name__ == "__main__":
  32. sys.exit(main())