|
@@ -11,23 +11,48 @@ from custom_components.tuya_local.helpers.device_config import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def error_location(entity):
|
|
|
|
|
+ return f"::error file=custom_components/tuya_local/devices/{entity._device.config},line={entity._config.__line__}:"
|
|
|
|
|
+
|
|
|
def main() -> int:
|
|
def main() -> int:
|
|
|
with open("custom_components/tuya_local/translations/en.json", "r") as f:
|
|
with open("custom_components/tuya_local/translations/en.json", "r") as f:
|
|
|
- english = json.load(f)
|
|
|
|
|
|
|
+ english = json.load(f)["entity"]
|
|
|
detected = 0
|
|
detected = 0
|
|
|
for config in available_configs():
|
|
for config in available_configs():
|
|
|
device = TuyaDeviceConfig(config)
|
|
device = TuyaDeviceConfig(config)
|
|
|
for entity in device.all_entities():
|
|
for entity in device.all_entities():
|
|
|
- if entity.name is None or entity.entity not in english["entity"]:
|
|
|
|
|
|
|
+ key = entity.translation_key
|
|
|
|
|
+ where = location(entity)
|
|
|
|
|
+ if key and (
|
|
|
|
|
+ entity.entity not in english
|
|
|
|
|
+ or key not in english[entity.entity]
|
|
|
|
|
+ ):
|
|
|
|
|
+ print(f"{where}: translation_key {key} does not exist")
|
|
|
|
|
+ detected +=1
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
|
|
+ if entity.name is None:
|
|
|
continue
|
|
continue
|
|
|
slug = slugify(entity.name)
|
|
slug = slugify(entity.name)
|
|
|
|
|
+ cls = entity.class
|
|
|
|
|
+
|
|
|
|
|
+ if cls is not None and key is None and cls == slug:
|
|
|
|
|
+ print(f"{where}: Entity name {entity.name} hides class translation.")
|
|
|
|
|
+ detected +=1
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
|
|
+ if entity.entity not in english["entity"]:
|
|
|
|
|
+ continue
|
|
|
|
|
|
|
|
- if entity.translation_key and slug != entity.translation_key:
|
|
|
|
|
|
|
+ if entity.translation_key:
|
|
|
|
|
+ if slug == entity.translation_key:
|
|
|
|
|
+ print(f"{where}: Entity name {entity.name} hides translation.")
|
|
|
|
|
+ detected +=1
|
|
|
continue
|
|
continue
|
|
|
translations = english["entity"][entity.entity]
|
|
translations = english["entity"][entity.entity]
|
|
|
if slug in translations:
|
|
if slug in translations:
|
|
|
print(
|
|
print(
|
|
|
- f"::error file=custom_components/tuya_local/devices/{config},line={entity._config.__line__}:: Entity can use translation_key: {slug}"
|
|
|
|
|
|
|
+ f"{where}: Entity can use translation_key: {slug}"
|
|
|
)
|
|
)
|
|
|
detected += 1
|
|
detected += 1
|
|
|
return detected
|
|
return detected
|