duplicates.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Check for duplicates of the supplied file."""
  2. import sys
  3. from custom_components.tuya_local.helpers.device_config import (
  4. get_config,
  5. possible_matches,
  6. )
  7. class FakeDevice:
  8. def __init__(self, dps):
  9. self._dps = dps
  10. def get_property(self, id):
  11. return self._dps.get(id)
  12. @property
  13. def name(self):
  14. return "cmdline"
  15. def representation(dp):
  16. """Return a represenative value for the dp."""
  17. if dp.type is bool:
  18. return True
  19. if dp.type is int:
  20. if dp._config.get(range):
  21. return dp._config.get(range)["min"]
  22. return 0
  23. if dp.type is str:
  24. return ""
  25. if dp.type is float:
  26. return 0.0
  27. def main():
  28. for filename in sys.argv[1:]:
  29. if filename.endswith(".yaml"):
  30. filename = filename[:-5]
  31. if "/" in filename:
  32. filename = filename.split("/")[-1]
  33. config = get_config(filename)
  34. all_dps = config._get_all_dps()
  35. sample_dps = {dp.id: representation(dp) for dp in all_dps}
  36. # device = FakeDevice(sample_dps)
  37. for m in possible_matches(sample_dps):
  38. if m.config_type == filename:
  39. continue
  40. if m.match_quality(sample_dps) > 50:
  41. print(
  42. f"{m.config_type} matched {filename} {m.match_quality(sample_dps)}%"
  43. )
  44. if __name__ == "__main__":
  45. sys.exit(main())