match_against.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Find matching devices for the supplied dp list"""
  2. import json
  3. import sys
  4. from common_funcs import FakeDevice, load_config
  5. from custom_components.tuya_local.helpers.device_config import _typematch
  6. def main() -> int:
  7. dps = json.loads(" ".join(sys.argv[2:]))
  8. device = FakeDevice(dps)
  9. config = load_config(sys.argv[1])
  10. if config is None:
  11. print(f"No config could be loaded for {sys.argv[1]}")
  12. return 1
  13. for entity in config.all_entities():
  14. print(f"{entity.config_id}:")
  15. for dp in entity.dps():
  16. if dp.id not in dps.keys():
  17. print(f" {dp.name} missing from data")
  18. if not dp.optional:
  19. print(f">> dp {dp.id} is REQUIRED!!!!")
  20. elif not _typematch(dp.type, dps.get(dp.id)):
  21. print(
  22. f">> {dp.name} type MISMATCH, expected {dp.type.__name__}, got {dps.get(dp.id)}!!!"
  23. )
  24. else:
  25. values = dp.values(device)
  26. if values:
  27. values = f" from {values}"
  28. else:
  29. values = ""
  30. print(f" {dp.name}: {dp.get_value(device)}{values}")
  31. if __name__ == "__main__":
  32. sys.exit(main())