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.

silvercrest.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devices.base import base
  5. import logging
  6. class silvercrest_powerplug(base):
  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 __init__(self, mqtt_client, topic):
  28. super().__init__(mqtt_client, topic)
  29. #
  30. # RX
  31. #
  32. @property
  33. def output_0(self):
  34. """rv: [True, False]"""
  35. return self.get(self.KEY_OUTPUT_0)
  36. @property
  37. def linkquality(self):
  38. """rv: numeric value"""
  39. return self.get(self.KEY_LINKQUALITY)
  40. #
  41. # TX
  42. #
  43. def set_output_0(self, state):
  44. """state: [True, False]"""
  45. self.send_command(self.KEY_OUTPUT_0, state)
  46. def set_output_0_mcb(self, device, key, data):
  47. self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
  48. self.set_output_0(data)
  49. def toggle_output_0_mcb(self, device, key, data):
  50. self.logger.info("Toggeling output 0")
  51. self.set_output_0(not self.output_0)
  52. def all_off(self):
  53. if self.output_0:
  54. self.set_output_0(False)
  55. class silvercrest_motion_sensor(base):
  56. """ Communication (MQTT)
  57. silvercrest_motion_sensor {
  58. battery: [0...100] %
  59. battery_low: [True, False]
  60. linkquality: [0...255] lqi
  61. occupancy: [True, False]
  62. tamper: [True, False]
  63. voltage: [0...] mV
  64. }
  65. """
  66. KEY_BATTERY = "battery"
  67. KEY_BATTERY_LOW = "battery_low"
  68. KEY_LINKQUALITY = "linkquality"
  69. KEY_OCCUPANCY = "occupancy"
  70. KEY_UNMOUNTED = "tamper"
  71. KEY_VOLTAGE = "voltage"
  72. #
  73. TX_TYPE = base.TX_DICT
  74. #
  75. RX_KEYS = [KEY_BATTERY, KEY_BATTERY_LOW, KEY_LINKQUALITY, KEY_OCCUPANCY, KEY_UNMOUNTED, KEY_VOLTAGE]
  76. def __init__(self, mqtt_client, topic):
  77. super().__init__(mqtt_client, topic)
  78. #
  79. self.add_callback(self.KEY_BATTERY_LOW, True, self.__warning__, True)
  80. #
  81. # WARNING CALL
  82. #
  83. def __warning__(self, client, key, data):
  84. w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", self.get(self.KEY_BATTERY) or math.nan)
  85. self.logger.warning(w)
  86. self.set(self.KEY_WARNING, w)
  87. #
  88. # RX
  89. #
  90. @property
  91. def linkquality(self):
  92. """rv: numeric value"""
  93. return self.get(self.KEY_LINKQUALITY)
  94. @property
  95. def battery(self):
  96. """rv: numeric value"""
  97. return self.get(self.KEY_BATTERY)