Control for Window lights
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devices.base import base, base_output
  5. import logging
  6. class silvercrest_powerplug(base_output):
  7. """ Communication (MQTT)
  8. silvercrest_powerplug {
  9. | "state": ["ON" / "OFF"]
  10. | "linkquality": [0...255] lqi
  11. | }
  12. +- get {
  13. | "state": ""
  14. | }
  15. +- set {
  16. "state": ["ON" / "OFF"]
  17. }
  18. """
  19. KEY_LINKQUALITY = "linkquality"
  20. KEY_OUTPUT_0 = "state"
  21. #
  22. TX_TYPE = base.TX_DICT
  23. TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
  24. #
  25. RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0]
  26. RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
  27. def __state_logging__(self, inst, key, data):
  28. if key in [self.KEY_OUTPUT_0]:
  29. self.logger.info("State change of '%s' to '%s'", key, repr(data))
  30. #
  31. # RX
  32. #
  33. @property
  34. def output_0(self):
  35. """rv: [True, False]"""
  36. return self.get(self.KEY_OUTPUT_0)
  37. @property
  38. def linkquality(self):
  39. """rv: numeric value"""
  40. return self.get(self.KEY_LINKQUALITY)
  41. #
  42. # TX
  43. #
  44. def set_output_0(self, state):
  45. """state: [True, False]"""
  46. self.send_command(self.KEY_OUTPUT_0, state)
  47. def set_output_0_mcb(self, device, key, data):
  48. self.set_output_0(data)
  49. def toggle_output_0_mcb(self, device, key, data):
  50. self.set_output_0(not self.output_0)
  51. def __all_off__(self):
  52. if self.output_0:
  53. self.set_output_0(False)
  54. class silvercrest_motion_sensor(base):
  55. """ Communication (MQTT)
  56. silvercrest_motion_sensor {
  57. battery: [0...100] %
  58. battery_low: [True, False]
  59. linkquality: [0...255] lqi
  60. occupancy: [True, False]
  61. tamper: [True, False]
  62. voltage: [0...] mV
  63. }
  64. """
  65. KEY_BATTERY = "battery"
  66. KEY_BATTERY_LOW = "battery_low"
  67. KEY_LINKQUALITY = "linkquality"
  68. KEY_OCCUPANCY = "occupancy"
  69. KEY_UNMOUNTED = "tamper"
  70. KEY_VOLTAGE = "voltage"
  71. #
  72. TX_TYPE = base.TX_DICT
  73. #
  74. RX_KEYS = [KEY_BATTERY, KEY_BATTERY_LOW, KEY_LINKQUALITY, KEY_OCCUPANCY, KEY_UNMOUNTED, KEY_VOLTAGE]
  75. def __init__(self, mqtt_client, topic):
  76. super().__init__(mqtt_client, topic)
  77. def __state_logging__(self, inst, key, data):
  78. if key in [self.KEY_OCCUPANCY, self.KEY_UNMOUNTED]:
  79. self.logger.info("State change of '%s' to '%s'", key, repr(data))
  80. #
  81. # RX
  82. #
  83. @property
  84. def linkquality(self):
  85. """rv: numeric value"""
  86. return self.get(self.KEY_LINKQUALITY)
  87. @property
  88. def battery(self):
  89. """rv: numeric value"""
  90. return self.get(self.KEY_BATTERY)