Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

54 wiersze
1.1KB

  1. # -*- coding: utf-8 -*-
  2. import subprocess
  3. import time
  4. from modules import cbpi, socketio
  5. from modules.core.hardware import SensorActive
  6. from modules import cbpi
  7. from modules.core.props import Property
  8. @cbpi.sensor
  9. class DummyTempSensor(SensorActive):
  10. temp = Property.Number("Temperature", configurable=True, default_value=5, description="Dummy Temperature as decimal value")
  11. @cbpi.action("My Custom Action")
  12. def my_action(self):
  13. pass
  14. def get_unit(self):
  15. '''
  16. :return: Unit of the sensor as string. Should not be longer than 3 characters
  17. '''
  18. return "°C" if self.get_config_parameter("unit", "C") == "C" else "°F"
  19. def stop(self):
  20. SensorActive.stop(self)
  21. def execute(self):
  22. '''
  23. Active sensor has to handle his own loop
  24. :return:
  25. '''
  26. while self.is_running() is True:
  27. self.data_received(self.temp)
  28. self.sleep(5)
  29. @classmethod
  30. def init_global(cls):
  31. '''
  32. Called one at the startup for all sensors
  33. :return:
  34. '''