Smarthome Functionen
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

mydevices.py 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devices.base import base
  5. import logging
  6. class powerplug(base):
  7. """ Communication (MQTT)
  8. my_powerplug
  9. +- output
  10. +- 1 [True, False] <- status
  11. | +- set [True, False, "toggle"] <- command
  12. +- 2 [True, False] <- status
  13. | +- set [True, False, "toggle"] <- command
  14. +- 3 [True, False] <- status
  15. | +- set [True, False, "toggle"] <- command
  16. +- 4 [True, False] <- status
  17. | +- set [True, False, "toggle"] <- command
  18. +- all
  19. +- set [True, False, "toggle"] <- command
  20. """
  21. KEY_OUTPUT_0 = "output/1"
  22. KEY_OUTPUT_1 = "output/2"
  23. KEY_OUTPUT_2 = "output/3"
  24. KEY_OUTPUT_3 = "output/4"
  25. KEY_OUTPUT_ALL = "output/all"
  26. KEY_OUTPUT_LIST = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
  27. #
  28. TX_TYPE = base.TX_VALUE
  29. #
  30. RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
  31. def __init__(self, mqtt_client, topic):
  32. super().__init__(mqtt_client, topic)
  33. #
  34. # RX
  35. #
  36. @property
  37. def output_0(self):
  38. """rv: [True, False]"""
  39. return self.get(self.KEY_OUTPUT_0)
  40. @property
  41. def output_1(self):
  42. """rv: [True, False]"""
  43. return self.get(self.KEY_OUTPUT_1)
  44. @property
  45. def output_2(self):
  46. """rv: [True, False]"""
  47. return self.get(self.KEY_OUTPUT_2)
  48. @property
  49. def output_3(self):
  50. """rv: [True, False]"""
  51. return self.get(self.KEY_OUTPUT_3)
  52. #
  53. # TX
  54. #
  55. def set_output(self, key, state):
  56. if key in self.KEY_OUTPUT_LIST:
  57. self.send_command(key, state)
  58. else:
  59. logging.error("Unknown key to set the output!")
  60. def set_output_0(self, state):
  61. """state: [True, False]"""
  62. self.send_command(self.KEY_OUTPUT_0, state)
  63. def set_output_0_mcb(self, device, key, data):
  64. self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
  65. self.set_output_0(data)
  66. def toggle_output_0_mcb(self, device, key, data):
  67. self.logger.info("Toggeling output 0")
  68. self.set_output_0(not self.output_0)
  69. def set_output_1(self, state):
  70. """state: [True, False]"""
  71. self.send_command(self.KEY_OUTPUT_1, state)
  72. def set_output_1_mcb(self, device, key, data):
  73. self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "Changing output 1 to %s", str(data))
  74. self.set_output_1(data)
  75. def toggle_output_1_mcb(self, device, key, data):
  76. self.logger.info("Toggeling output 1")
  77. self.set_output_1(not self.output_1)
  78. def set_output_2(self, state):
  79. """state: [True, False]"""
  80. self.send_command(self.KEY_OUTPUT_2, state)
  81. def set_output_2_mcb(self, device, key, data):
  82. self.logger.log(logging.INFO if data != self.output_2 else logging.DEBUG, "Changing output 2 to %s", str(data))
  83. self.set_output_2(data)
  84. def toggle_output_2_mcb(self, device, key, data):
  85. self.logger.info("Toggeling output 2")
  86. self.set_output_2(not self.output_2)
  87. def set_output_3(self, state):
  88. """state: [True, False]"""
  89. self.send_command(self.KEY_OUTPUT_3, state)
  90. def set_output_3_mcb(self, device, key, data):
  91. self.logger.log(logging.INFO if data != self.output_3 else logging.DEBUG, "Changing output 3 to %s", str(data))
  92. self.set_output_3(data)
  93. def toggle_output_3_mcb(self, device, key, data):
  94. self.logger.info("Toggeling output 3")
  95. self.set_output_3(not self.output_3)
  96. def set_output_all(self, state):
  97. """state: [True, False, 'toggle']"""
  98. self.send_command(self.KEY_OUTPUT_ALL, state)
  99. def set_output_all_mcb(self, device, key, data):
  100. self.logger.info("Changing all outputs to %s", str(data))
  101. self.set_output_all(data)
  102. def all_off(self):
  103. self.set_output_all(False)
  104. class remote(base):
  105. """ Communication (MQTT)
  106. remote (RAS5) <- command
  107. +- CD [dc]
  108. +- LINE1 [dc]
  109. +- LINE2 [dc]
  110. +- LINE3 [dc]
  111. +- MUTE [dc]
  112. +- POWER [dc]
  113. +- VOLDOWN [dc]
  114. +- VOLUP [dc]
  115. +- PHONO [dc]
  116. +- DOCK [dc]
  117. remote (EUR642100) <- command
  118. +- OPEN_CLOSE [dc]
  119. +- VOLDOWN [dc]
  120. +- VOLUP [dc]
  121. +- ONE [dc]
  122. +- TWO [dc]
  123. +- THREE [dc]
  124. +- FOUR [dc]
  125. +- FIVE [dc]
  126. +- SIX [dc]
  127. +- SEVEN [dc]
  128. +- EIGHT [dc]
  129. +- NINE [dc]
  130. +- ZERO [dc]
  131. +- TEN [dc]
  132. +- TEN_PLUS [dc]
  133. +- PROGRAM [dc]
  134. +- CLEAR [dc]
  135. +- RECALL [dc]
  136. +- TIME_MODE [dc]
  137. +- A_B_REPEAT [dc]
  138. +- REPEAT [dc]
  139. +- RANDOM [dc]
  140. +- AUTO_CUE [dc]
  141. +- TAPE_LENGTH [dc]
  142. +- SIDE_A_B [dc]
  143. +- TIME_FADE [dc]
  144. +- PEAK_SEARCH [dc]
  145. +- SEARCH_BACK [dc]
  146. +- SEARCH_FOR [dc]
  147. +- TRACK_NEXT [dc]
  148. +- TRACK_PREV [dc]
  149. +- STOP [dc]
  150. +- PAUSE [dc]
  151. +- PLAY [dc]
  152. """
  153. KEY_CD = "CD"
  154. KEY_LINE1 = "LINE1"
  155. KEY_LINE3 = "LINE3"
  156. KEY_MUTE = "MUTE"
  157. KEY_POWER = "POWER"
  158. KEY_VOLDOWN = "VOLDOWN"
  159. KEY_VOLUP = "VOLUP"
  160. #
  161. TX_TOPIC = ''
  162. TX_TYPE = base.TX_VALUE
  163. #
  164. RX_IGNORE_TOPICS = [KEY_CD, KEY_LINE1, KEY_LINE3, KEY_MUTE, KEY_POWER, KEY_VOLUP, KEY_VOLDOWN]
  165. def set_cd(self, device=None, key=None, data=None):
  166. self.send_command(self.KEY_CD, None)
  167. def set_line1(self, device=None, key=None, data=None):
  168. self.send_command(self.KEY_LINE1, None)
  169. def set_line3(self, device=None, key=None, data=None):
  170. self.send_command(self.KEY_LINE3, None)
  171. def set_mute(self, device=None, key=None, data=None):
  172. self.send_command(self.KEY_MUTE, None)
  173. def set_power(self, device=None, key=None, data=None):
  174. self.send_command(self.KEY_POWER, None)
  175. def set_volume_up(self, data=False):
  176. """data: [True, False]"""
  177. self.send_command(self.KEY_VOLUP, data)
  178. def set_volume_down(self, data=False):
  179. """data: [True, False]"""
  180. self.send_command(self.KEY_VOLDOWN, data)
  181. def default_inc(self, device=None, key=None, data=None):
  182. self.set_volume_up(True)
  183. def default_dec(self, device=None, key=None, data=None):
  184. self.set_volume_down(True)
  185. def default_stop(self, device=None, key=None, data=None):
  186. self.set_volume_up(False)
  187. class audio_status(base):
  188. """ Communication (MQTT)
  189. audio_status
  190. +- state [True, False] <- status
  191. +- title [text] <- status
  192. """
  193. KEY_STATE = "state"
  194. KEY_TITLE = "title"
  195. #
  196. TX_TYPE = base.TX_VALUE
  197. #
  198. RX_KEYS = [KEY_STATE, KEY_TITLE]
  199. def set_state(self, num, data):
  200. """data: [True, False]"""
  201. self.send_command(self.KEY_STATE + "/" + str(num), data)
  202. def set_state_mcb(self, device, key, data):
  203. self.logger.info("Changing state to %s", str(data))
  204. self.set_state(data)