match_against.py 1.4 KB

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