config_match.py 909 B

1234567891011121314151617181920212223242526272829303132
  1. """Find matching devices for the supplied dp list"""
  2. import sys
  3. import json
  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. def main() -> int:
  11. dps = json.loads(" ".join(sys.argv[1:]))
  12. device = FakeDevice(dps)
  13. for match in possible_matches(dps):
  14. print(f"{match.config_type} matched {match.match_quality(dps)}%")
  15. print(f" {match.primary_entity.config_id}:")
  16. for dp in match.primary_entity.dps():
  17. print(f" {dp.name}: {dp.get_value(device)}")
  18. for entity in match.secondary_entities():
  19. print(f" {entity.config_id}:")
  20. for dp in entity.dps():
  21. print(f" {dp.name}: {dp.get_value(device)}")
  22. if __name__ == "__main__":
  23. sys.exit(main())