untranslated_entities.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. """Find entities with names that match existing translation keys."""
  2. import json
  3. import sys
  4. from custom_components.tuya_local.helpers.device_config import (
  5. TuyaDeviceConfig,
  6. available_configs,
  7. )
  8. from homeassistant.util import slugify
  9. def main() -> int:
  10. with open("custom_components/tuya_local/translations/en.json", "r") as f:
  11. english = json.load(f)
  12. for config in available_configs():
  13. device = TuyaDeviceConfig(config)
  14. for entity in device.all_entities():
  15. if (
  16. entity.translation_key
  17. or entity.name is None
  18. or entity.entity not in english["entity"]
  19. ):
  20. continue
  21. translations = english["entity"][entity.entity]
  22. slug = slugify(entity.name)
  23. if slug in translations:
  24. print(
  25. f"{config}:{entity._config.__line__}: can use translation_key: {slug}"
  26. )
  27. return 0
  28. if __name__ == "__main__":
  29. sys.exit(main())