Smarthome Functionen
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

stairway.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import config
  5. import devices
  6. import logging
  7. from function.modules import motion_sensor_light
  8. from function.rooms import room
  9. from function.videv import videv_switching_motion
  10. try:
  11. from config import APP_NAME as ROOT_LOGGER_NAME
  12. except ImportError:
  13. ROOT_LOGGER_NAME = 'root'
  14. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  15. class stairway(room):
  16. def __init__(self, mqtt_client):
  17. #
  18. # Device initialisation
  19. #
  20. # http://shelly1-3494546A9364
  21. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY)
  22. self.motion_sensor_gf = devices.silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)
  23. self.motion_sensor_ff = devices.silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF)
  24. super().__init__(mqtt_client)
  25. #
  26. # Functionality initialisation
  27. #
  28. self.motion_sensor_light = motion_sensor_light(
  29. self.main_light_shelly, self.main_light_shelly.set_output_0,
  30. self.motion_sensor_gf, self.motion_sensor_ff,
  31. timer_value=config.USER_ON_TIME_STAIRWAYS
  32. )
  33. ##### TEMPORARY ###################################################################################################################
  34. self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI)
  35. self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
  36. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
  37. self.motion_sensor_light.add_callback(motion_sensor_light.KEY_TIMER, None, self.gui_main_light.set_timer_mcb)
  38. def set_led(device, key, data):
  39. if key == motion_sensor_light.KEY_MOTION_SENSOR_0:
  40. self.gui_main_light.set_led(devices.nodered_gui_light.KEY_LED_0, data)
  41. if key == motion_sensor_light.KEY_MOTION_SENSOR_1:
  42. self.gui_main_light.set_led(devices.nodered_gui_light.KEY_LED_1, data)
  43. self.motion_sensor_light.add_callback(motion_sensor_light.KEY_MOTION_SENSOR_0, None, set_led)
  44. self.motion_sensor_light.add_callback(motion_sensor_light.KEY_MOTION_SENSOR_1, None, set_led)
  45. ##### TEMPORARY ###################################################################################################################
  46. #
  47. # Virtual Device Interface
  48. #
  49. self.main_light_videv = videv_switching_motion(
  50. mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV,
  51. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  52. self.motion_sensor_light
  53. )