Smarthome Functionen
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

brennenstuhl.py 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devices.base import base
  5. from devices.base import BATTERY_WARN_LEVEL
  6. from devices.base import warning
  7. import json
  8. class brennenstuhl_heatingvalve(base):
  9. """ Communication (MQTT)
  10. brennenstuhl_heatingvalve {
  11. | "away_mode": ["ON", "OFF"]
  12. | "battery": [0...100] %
  13. | "child_lock": ["LOCK", "UNLOCK"]
  14. | "current_heating_setpoint": [5...30] °C
  15. | "linkquality": [0...255] lqi
  16. | "local_temperature": [numeric] °C
  17. | "preset": ["manual", ...]
  18. | "system_mode": ["heat", ...]
  19. | "valve_detection": ["ON", "OFF"]
  20. | "window_detection": ["ON", "OFF"]
  21. | }
  22. +- set {
  23. "away_mode": ["ON", "OFF", "TOGGLE"]
  24. "child_lock": ["LOCK", "UNLOCK"]
  25. "current_heating_setpoint": [5...30] °C
  26. "preset": ["manual", ...]
  27. "system_mode": ["heat", ...]
  28. "valve_detection": ["ON", "OFF", "TOGGLE"]
  29. "window_detection": ["ON", "OFF", "TOGGLE"]
  30. }
  31. """
  32. KEY_LINKQUALITY = "linkquality"
  33. KEY_BATTERY = "battery"
  34. KEY_HEATING_SETPOINT = "current_heating_setpoint"
  35. KEY_TEMPERATURE = "local_temperature"
  36. #
  37. KEY_AWAY_MODE = "away_mode"
  38. KEY_CHILD_LOCK = "child_lock"
  39. KEY_PRESET = "preset"
  40. KEY_SYSTEM_MODE = "system_mode"
  41. KEY_VALVE_DETECTION = "valve_detection"
  42. KEY_WINDOW_DETECTION = "window_detection"
  43. #
  44. TX_TYPE = base.TX_DICT
  45. #
  46. RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_HEATING_SETPOINT, KEY_TEMPERATURE]
  47. RX_IGNORE_KEYS = [KEY_AWAY_MODE, KEY_CHILD_LOCK, KEY_PRESET, KEY_SYSTEM_MODE, KEY_VALVE_DETECTION, KEY_WINDOW_DETECTION]
  48. def __init__(self, mqtt_client, topic):
  49. super().__init__(mqtt_client, topic)
  50. self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps({self.KEY_WINDOW_DETECTION: "ON",
  51. self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat", self.KEY_PRESET: "manual"}))
  52. #
  53. self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
  54. self.__battery_warning__ = False
  55. def __state_logging__(self, inst, key, data):
  56. if key in [self.KEY_HEATING_SETPOINT, self.KEY_CHILD_LOCK, self.KEY_WINDOW_DETECTION, self.KEY_VALVE_DETECTION]:
  57. self.logger.info("State change of '%s' to '%s'", key, repr(data))
  58. #
  59. # WARNING CALL
  60. #
  61. def __warning__(self, client, key, data):
  62. if data <= BATTERY_WARN_LEVEL:
  63. if not self.__battery_warning__:
  64. self.__battery_warning__ = True
  65. w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", data)
  66. self.logger.warning(w)
  67. self.set(self.KEY_WARNING, w)
  68. else:
  69. self.__battery_warning__ = False
  70. #
  71. # RX
  72. #
  73. @property
  74. def linkqulity(self):
  75. return self.get(self.KEY_LINKQUALITY)
  76. @property
  77. def heating_setpoint(self):
  78. return self.get(self.KEY_HEATING_SETPOINT)
  79. @property
  80. def temperature(self):
  81. return self.get(self.KEY_TEMPERATURE)
  82. #
  83. # TX
  84. #
  85. def set_heating_setpoint(self, setpoint):
  86. self.send_command(self.KEY_HEATING_SETPOINT, setpoint)
  87. def set_heating_setpoint_mcb(self, device, key, data):
  88. self.set_heating_setpoint(data)