| 12345678910111213141516171819202122232425262728293031323334353637 |
- """Find entities with names that match existing translation keys."""
- import json
- import sys
- from homeassistant.util import slugify
- from custom_components.tuya_local.helpers.device_config import (
- TuyaDeviceConfig,
- available_configs,
- )
- def main() -> int:
- with open("custom_components/tuya_local/translations/en.json", "r") as f:
- english = json.load(f)
- detected = 0
- for config in available_configs():
- device = TuyaDeviceConfig(config)
- for entity in device.all_entities():
- if entity.name is None or entity.entity not in english["entity"]:
- continue
- slug = slugify(entity.name)
- if entity.translation_key and slug != entity.translation_key:
- continue
- translations = english["entity"][entity.entity]
- if slug in translations:
- print(
- f"::error file=custom_components/tuya_local/devices/{config},line={entity._config.__line__}:: Entity can use translation_key: {slug}"
- )
- detected += 1
- return detected
- if __name__ == "__main__":
- sys.exit(main())
|