config_match.py 794 B

12345678910111213141516171819202122232425262728
  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. for entity in match.all_entities():
  13. print(f" {entity.config_id}:")
  14. for dp in entity.dps():
  15. dps_seen.discard(dp.id)
  16. print(f" {dp.name}: {dp.get_value(device)}")
  17. for dp in dps_seen:
  18. print(f" Missing {dp}: {dps[dp]}")
  19. if __name__ == "__main__":
  20. sys.exit(main())