MQTT Home Emulation
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

brennenstuhl.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 task
  30. import time
  31. """ ANSWER of a device:
  32. {
  33. "away_mode":"OFF",
  34. "battery":5,
  35. "child_lock":"UNLOCK",
  36. "current_heating_setpoint":21,
  37. "linkquality":196,
  38. "local_temperature":21.2,
  39. "preset":"manual",
  40. "system_mode":"heat",
  41. "valve_detection":"ON",
  42. "window_detection":"ON"
  43. }
  44. """
  45. class vlv(base):
  46. # """A tradfri device with switching functionality
  47. # Args:
  48. # mqtt_client (mqtt.mqtt_client): A MQTT Client instance
  49. # topic (str): the base topic for this device
  50. # """
  51. PROPERTIES = [
  52. "away_mode",
  53. "battery",
  54. "child_lock",
  55. "current_heating_setpoint",
  56. "linkquality",
  57. "local_temperature",
  58. "preset",
  59. "system_mode",
  60. "valve_detection",
  61. "window_detection"
  62. ]
  63. def __init__(self, mqtt_client, topic, **kwargs):
  64. super().__init__(mqtt_client, topic, **kwargs)
  65. self["away_mode"] = "OFF"
  66. self["battery"] = 87
  67. self["child_lock"] = "UNLOCK"
  68. self["current_heating_setpoint"] = 21
  69. self["linkquality"] = 196
  70. self["local_temperature"] = 21.2
  71. self["preset"] = "manual"
  72. self["system_mode"] = "heat"
  73. self["valve_detection"] = "ON"
  74. self["window_detection"] = "ON"
  75. #
  76. self.mqtt_client.add_callback(self.topic + '/set', self.__rx_set__)
  77. #
  78. self.tq = task.threaded_queue()
  79. self.tq.run()
  80. def set_state(self, value):
  81. self.__set__("state", "on" if value else "off")
  82. self.send_device_status()
  83. def __rx_set__(self, client, userdata, message):
  84. data = json.loads(message.payload)
  85. self.logger.info("Received set data: %s", repr(data))
  86. for key in data:
  87. self.__set__(key, data[key])
  88. self.tq.enqueue(1, self.send_device_status, data)
  89. def send_device_status(self, rt, data):
  90. for i in range(0, 75):
  91. time.sleep(0.01)
  92. if self.tq.qsize() >= 3:
  93. return
  94. for key in self:
  95. if key not in data:
  96. data[key] = self[key]
  97. self.logger.info("Sending status: %s", repr(data))
  98. self.mqtt_client.send(self.topic, json.dumps(data))