config_match.py 995 B

1234567891011121314151617181920212223242526272829303132
  1. """Find matching devices for the supplied dp list"""
  2. import json
  3. import sys
  4. from common_funcs import FakeDevice
  5. from custom_components.tuya_local.helpers.device_config import possible_matches
  6. def main() -> int:
  7. dps = json.loads(" ".join(sys.argv[1:]))
  8. device = FakeDevice(dps)
  9. for match in possible_matches(dps):
  10. dps_seen = set(dps.keys())
  11. print(f"{match.config_type} matched {match.match_quality(dps)}%")
  12. print(f" {match.primary_entity.config_id}:")
  13. for dp in match.primary_entity.dps():
  14. dps_seen.discard(dp.id)
  15. print(f" {dp.name}: {dp.get_value(device)}")
  16. for entity in match.secondary_entities():
  17. print(f" {entity.config_id}:")
  18. for dp in entity.dps():
  19. dps_seen.discard(dp.id)
  20. print(f" {dp.name}: {dp.get_value(device)}")
  21. for dp in dps_seen:
  22. print(f" Missing {dp}: {dps[dp]}")
  23. if __name__ == "__main__":
  24. sys.exit(main())