config_match.py 969 B

123456789101112131415161718192021222324252627282930313233343536
  1. """Find matching devices for the supplied dp list"""
  2. import json
  3. import sys
  4. from custom_components.tuya_local.helpers.device_config import possible_matches
  5. class FakeDevice:
  6. def __init__(self, dps):
  7. self._dps = dps
  8. def get_property(self, id):
  9. return self._dps.get(id)
  10. @property
  11. def name(self):
  12. return "cmdline"
  13. def main() -> int:
  14. dps = json.loads(" ".join(sys.argv[1:]))
  15. device = FakeDevice(dps)
  16. for match in possible_matches(dps):
  17. print(f"{match.config_type} matched {match.match_quality(dps)}%")
  18. print(f" {match.primary_entity.config_id}:")
  19. for dp in match.primary_entity.dps():
  20. print(f" {dp.name}: {dp.get_value(device)}")
  21. for entity in match.secondary_entities():
  22. print(f" {entity.config_id}:")
  23. for dp in entity.dps():
  24. print(f" {dp.name}: {dp.get_value(device)}")
  25. if __name__ == "__main__":
  26. sys.exit(main())