MQTT Home Emulation
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.

brennenstuhl.py 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """ Communication (MQTT)
  5. brennenstuhl_heatingvalve {
  6. | "away_mode": ["ON", "OFF"]
  7. | "battery": [0...100] %
  8. | "child_lock": ["LOCK", "UNLOCK"]
  9. | "current_heating_setpoint": [5...30] °C
  10. | "linkquality": [0...255] lqi
  11. | "local_temperature": [numeric] °C
  12. | "preset": ["manual", ...]
  13. | "system_mode": ["heat", ...]
  14. | "valve_detection": ["ON", "OFF"]
  15. | "window_detection": ["ON", "OFF"]
  16. | }
  17. +- set {
  18. "away_mode": ["ON", "OFF", "TOGGLE"]
  19. "child_lock": ["LOCK", "UNLOCK"]
  20. "current_heating_setpoint": [5...30] °C
  21. "preset": ["manual", ...]
  22. "system_mode": ["heat", ...]
  23. "valve_detection": ["ON", "OFF", "TOGGLE"]
  24. "window_detection": ["ON", "OFF", "TOGGLE"]
  25. }
  26. """
  27. from devices.base import base
  28. import json
  29. import time
  30. """ ANSWER of a device:
  31. {
  32. "away_mode":"OFF",
  33. "battery":5,
  34. "child_lock":"UNLOCK",
  35. "current_heating_setpoint":21,
  36. "linkquality":196,
  37. "local_temperature":21.2,
  38. "preset":"manual",
  39. "system_mode":"heat",
  40. "valve_detection":"ON",
  41. "window_detection":"ON"
  42. }
  43. """
  44. class vlv(base):
  45. # """A tradfri device with switching functionality
  46. # Args:
  47. # mqtt_client (mqtt.mqtt_client): A MQTT Client instance
  48. # topic (str): the base topic for this device
  49. # """
  50. PROPERTIES = [
  51. "away_mode",
  52. "battery",
  53. "child_lock",
  54. "current_heating_setpoint",
  55. "linkquality",
  56. "local_temperature",
  57. "preset",
  58. "system_mode",
  59. "valve_detection",
  60. "window_detection"
  61. ]
  62. def __init__(self, mqtt_client, topic, **kwargs):
  63. super().__init__(mqtt_client, topic, **kwargs)
  64. self["away_mode"] = "OFF"
  65. self["battery"] = 87
  66. self["child_lock"] = "UNLOCK"
  67. self["current_heating_setpoint"] = 21
  68. self["linkquality"] = 196
  69. self["local_temperature"] = 21.2
  70. self["preset"] = "manual"
  71. self["system_mode"] = "heat"
  72. self["valve_detection"] = "ON"
  73. self["window_detection"] = "ON"
  74. #
  75. self.mqtt_client.add_callback(self.topic + '/set', self.__rx_set__)
  76. def set_state(self, value):
  77. self.__set__("state", "on" if value else "off")
  78. self.send_device_status()
  79. def __rx_set__(self, client, userdata, message):
  80. data = json.loads(message.payload)
  81. self.logger.info("Received set data: %s", repr(data))
  82. for key in data:
  83. self.__set__(key, data[key])
  84. #time.sleep(1.5)
  85. self.send_device_status()
  86. def send_device_status(self):
  87. data = json.dumps(self)
  88. self.logger.info("Sending status: %s", repr(data))
  89. self.mqtt_client.send(self.topic, data)