You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3KB

  1. # -*- coding: utf-8 -*-
  2. import os
  3. from os.path import join
  4. from modules.core.basetypes import Sensor
  5. from modules.core.core import cbpi
  6. from modules.core.proptypes import Property
  7. import logging
  8. @cbpi.addon.sensor.type("Dummy Sensor")
  9. class Dummy(Sensor):
  10. text = Property.Text(label="Text", required=True, description="This is a parameter", configurable=True)
  11. p = Property.Select(label="hallo",options=[1,2,3])
  12. def __init__(self):
  13. self.logger = logging.getLogger(__name__)
  14. self.logger.info("INIT SENSOR")
  15. def init(self):
  16. if self.api.get_config_parameter("unit","C") == "C":
  17. self.unit = "°C"
  18. else:
  19. self.unit = "°F"
  20. @cbpi.addon.sensor.action("WOHOO")
  21. def myaction(self):
  22. self.logger.debug("SENSOR ACTION HALLO!!!")
  23. def execute(self):
  24. while True:
  25. try:
  26. self.update_value(int(self.text))
  27. except:
  28. pass
  29. self.api.sleep(1)
  30. @cbpi.addon.core.action(key="clear", label="Clear all Logs")
  31. def woohoo(cbpi):
  32. dir = "./logs"
  33. test = os.listdir(dir)
  34. for item in test:
  35. if item.endswith(".log"):
  36. os.remove(join(dir, item))
  37. cbpi.notify(headline="Logs Deleted",message="All Logs Cleared")