4
0

common_funcs.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """Common functions used in the utilities."""
  2. from custom_components.tuya_local.helpers.device_config import (
  3. get_config,
  4. )
  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 load_config(filename):
  14. """Load the config for the device."""
  15. if filename.endswith(".yaml"):
  16. filename = filename[:-5]
  17. if "/" in filename:
  18. filename = filename.split("/")[-1]
  19. return get_config(filename)
  20. def representation(dp):
  21. """Return a represenative value for the dp."""
  22. if dp.type is bool:
  23. return True
  24. if dp.type is int:
  25. if dp._config.get(range):
  26. return dp._config.get(range)["min"]
  27. return 0
  28. if dp.type is str:
  29. return ""
  30. if dp.type is float:
  31. return 0.0
  32. def make_sample_dps(config):
  33. """Return a dictionary of sample DPS values."""
  34. all_dps = config._get_all_dps()
  35. return {dp.id: representation(dp) for dp in all_dps}