Просмотр исходного кода

dev (utils): add an entities utility

Takes one argument, a entity config id made up of entity type
followed optionally by an underscore and name, translation_key,
or class (in that order)

Outputs the matching entities, with filename and line info compatible
with grep and compiler output so it can be easily parsed by IDEs.

Mainly to assist with #1708, but probably useful in other cases too.
Jason Rumney 3 месяцев назад
Родитель
Сommit
a2394fb96b
1 измененных файлов с 20 добавлено и 0 удалено
  1. 20 0
      util/entities.py

+ 20 - 0
util/entities.py

@@ -0,0 +1,20 @@
+"""Find matching entities in config files."""
+
+import sys
+from custom_components.tuya_local.helpers.device_config import (
+    TuyaDeviceConfig,
+    available_configs,
+)
+
+
+def main() -> int:
+    for config in available_configs():
+        device = TuyaDeviceConfig(config)
+        for entity in device.all_entities():
+            if entity.config_id == sys.argv[1]:
+                print(f"{config}:{entity._config.__line__}: found {entity.config_id}")
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())