config_match.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. dps_seen = set(dps.keys())
  18. print(f"{match.config_type} matched {match.match_quality(dps)}%")
  19. print(f" {match.primary_entity.config_id}:")
  20. for dp in match.primary_entity.dps():
  21. dps_seen.discard(dp.id)
  22. print(f" {dp.name}: {dp.get_value(device)}")
  23. for entity in match.secondary_entities():
  24. print(f" {entity.config_id}:")
  25. for dp in entity.dps():
  26. dps_seen.discard(dp.id)
  27. print(f" {dp.name}: {dp.get_value(device)}")
  28. for dp in dps_seen:
  29. print(f" Missing {dp}: {dps[dp]}")
  30. if __name__ == "__main__":
  31. sys.exit(main())