Smarthome Functionen
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

silvercrest.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devices.base import base
  5. from devices.base import warning
  6. import logging
  7. class silvercrest_powerplug(base):
  8. """ Communication (MQTT)
  9. silvercrest_powerplug {
  10. | "state": ["ON" / "OFF"]
  11. | "linkquality": [0...255] lqi
  12. | }
  13. +- get {
  14. | "state": ""
  15. | }
  16. +- set {
  17. "state": ["ON" / "OFF"]
  18. }
  19. """
  20. KEY_LINKQUALITY = "linkquality"
  21. KEY_OUTPUT_0 = "state"
  22. #
  23. TX_TYPE = base.TX_DICT
  24. TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
  25. #
  26. RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0]
  27. RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
  28. def __init__(self, mqtt_client, topic):
  29. super().__init__(mqtt_client, topic)
  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.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
  49. self.set_output_0(data)
  50. def toggle_output_0_mcb(self, device, key, data):
  51. self.logger.info("Toggeling output 0")
  52. self.set_output_0(not self.output_0)
  53. def all_off(self):
  54. if self.output_0:
  55. self.set_output_0(False)
  56. class silvercrest_motion_sensor(base):
  57. """ Communication (MQTT)
  58. silvercrest_motion_sensor {
  59. battery: [0...100] %
  60. battery_low: [True, False]
  61. linkquality: [0...255] lqi
  62. occupancy: [True, False]
  63. tamper: [True, False]
  64. voltage: [0...] mV
  65. }
  66. """
  67. KEY_BATTERY = "battery"
  68. KEY_BATTERY_LOW = "battery_low"
  69. KEY_LINKQUALITY = "linkquality"
  70. KEY_OCCUPANCY = "occupancy"
  71. KEY_UNMOUNTED = "tamper"
  72. KEY_VOLTAGE = "voltage"
  73. #
  74. TX_TYPE = base.TX_DICT
  75. #
  76. RX_KEYS = [KEY_BATTERY, KEY_BATTERY_LOW, KEY_LINKQUALITY, KEY_OCCUPANCY, KEY_UNMOUNTED, KEY_VOLTAGE]
  77. def __init__(self, mqtt_client, topic):
  78. super().__init__(mqtt_client, topic)
  79. #
  80. self.add_callback(self.KEY_BATTERY_LOW, True, self.__warning__, True)
  81. #
  82. # WARNING CALL
  83. #
  84. def __warning__(self, client, key, data):
  85. w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", self.get(self.KEY_BATTERY) or math.nan)
  86. self.logger.warning(w)
  87. self.set(self.KEY_WARNING, w)
  88. #
  89. # RX
  90. #
  91. @property
  92. def linkquality(self):
  93. """rv: numeric value"""
  94. return self.get(self.KEY_LINKQUALITY)
  95. @property
  96. def battery(self):
  97. """rv: numeric value"""
  98. return self.get(self.KEY_BATTERY)