common_funcs.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Common functions used in the unilities."""
  2. from custom_components.tuya_local.helpers.device_config import (
  3. get_config,
  4. possible_matches,
  5. )
  6. class FakeDevice:
  7. def __init__(self, dps):
  8. self._dps = dps
  9. def get_property(self, id):
  10. return self._dps.get(id)
  11. @property
  12. def name(self):
  13. return "cmdline"
  14. def load_config(filename):
  15. """Load the config for the device."""
  16. if filename.endswith(".yaml"):
  17. filename = filename[:-5]
  18. if "/" in filename:
  19. filename = filename.split("/")[-1]
  20. return get_config(filename)
  21. def representation(dp):
  22. """Return a represenative value for the dp."""
  23. if dp.type is bool:
  24. return True
  25. if dp.type is int:
  26. if dp._config.get(range):
  27. return dp._config.get(range)["min"]
  28. return 0
  29. if dp.type is str:
  30. return ""
  31. if dp.type is float:
  32. return 0.0
  33. def make_sample_dps(config):
  34. """Return a dictionary of sample DPS values."""
  35. all_dps = config._get_all_dps()
  36. return {dp.id: representation(dp) for dp in all_dps}