選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

53 行
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)
  11. def get_unit(self):
  12. '''
  13. :return: Unit of the sensor as string. Should not be longer than 3 characters
  14. '''
  15. return "°C" if self.get_config_parameter("unit", "C") == "C" else "°F"
  16. def stop(self):
  17. '''
  18. Stop the sensor. Is called when the sensor config is updated or the sensor is deleted
  19. :return:
  20. '''
  21. pass
  22. def execute(self):
  23. '''
  24. Active sensor has to handle his own loop
  25. :return:
  26. '''
  27. while self.is_running():
  28. self.data_received(self.temp)
  29. socketio.sleep(5)
  30. @classmethod
  31. def init_global(cls):
  32. '''
  33. Called one at the startup for all sensors
  34. :return:
  35. '''