Smarthome Functionen
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 __state_logging__(self, inst, key, data):
  32. if key in self.KEY_OUTPUT_LIST:
  33. self.logger.info("State change of '%s' to '%s'", key, repr(data))
  34. #
  35. # RX
  36. #
  37. @property
  38. def output_0(self):
  39. """rv: [True, False]"""
  40. return self.get(self.KEY_OUTPUT_0)
  41. @property
  42. def output_1(self):
  43. """rv: [True, False]"""
  44. return self.get(self.KEY_OUTPUT_1)
  45. @property
  46. def output_2(self):
  47. """rv: [True, False]"""
  48. return self.get(self.KEY_OUTPUT_2)
  49. @property
  50. def output_3(self):
  51. """rv: [True, False]"""
  52. return self.get(self.KEY_OUTPUT_3)
  53. #
  54. # TX
  55. #
  56. def set_output(self, key, state):
  57. if key in self.KEY_OUTPUT_LIST:
  58. self.send_command(key, state)
  59. else:
  60. logging.error("Unknown key to set the output!")
  61. def set_output_0(self, state):
  62. """state: [True, False]"""
  63. self.send_command(self.KEY_OUTPUT_0, state)
  64. def set_output_0_mcb(self, device, key, data):
  65. self.set_output_0(data)
  66. def toggle_output_0_mcb(self, device, key, data):
  67. self.set_output_0(not self.output_0)
  68. def set_output_1(self, state):
  69. """state: [True, False]"""
  70. self.send_command(self.KEY_OUTPUT_1, state)
  71. def set_output_1_mcb(self, device, key, data):
  72. self.set_output_1(data)
  73. def toggle_output_1_mcb(self, device, key, data):
  74. self.set_output_1(not self.output_1)
  75. def set_output_2(self, state):
  76. """state: [True, False]"""
  77. self.send_command(self.KEY_OUTPUT_2, state)
  78. def set_output_2_mcb(self, device, key, data):
  79. self.set_output_2(data)
  80. def toggle_output_2_mcb(self, device, key, data):
  81. self.set_output_2(not self.output_2)
  82. def set_output_3(self, state):
  83. """state: [True, False]"""
  84. self.send_command(self.KEY_OUTPUT_3, state)
  85. def set_output_3_mcb(self, device, key, data):
  86. self.set_output_3(data)
  87. def toggle_output_3_mcb(self, device, key, data):
  88. self.set_output_3(not self.output_3)
  89. def set_output_all(self, state):
  90. """state: [True, False, 'toggle']"""
  91. self.send_command(self.KEY_OUTPUT_ALL, state)
  92. def set_output_all_mcb(self, device, key, data):
  93. self.set_output_all(data)
  94. def all_off(self):
  95. self.set_output_all(False)
  96. class remote(base):
  97. """ Communication (MQTT)
  98. remote (RAS5) <- command
  99. +- CD [dc]
  100. +- LINE1 [dc]
  101. +- LINE2 [dc]
  102. +- LINE3 [dc]
  103. +- MUTE [dc]
  104. +- POWER [dc]
  105. +- VOLDOWN [dc]
  106. +- VOLUP [dc]
  107. +- PHONO [dc]
  108. +- DOCK [dc]
  109. remote (EUR642100) <- command
  110. +- OPEN_CLOSE [dc]
  111. +- VOLDOWN [dc]
  112. +- VOLUP [dc]
  113. +- ONE [dc]
  114. +- TWO [dc]
  115. +- THREE [dc]
  116. +- FOUR [dc]
  117. +- FIVE [dc]
  118. +- SIX [dc]
  119. +- SEVEN [dc]
  120. +- EIGHT [dc]
  121. +- NINE [dc]
  122. +- ZERO [dc]
  123. +- TEN [dc]
  124. +- TEN_PLUS [dc]
  125. +- PROGRAM [dc]
  126. +- CLEAR [dc]
  127. +- RECALL [dc]
  128. +- TIME_MODE [dc]
  129. +- A_B_REPEAT [dc]
  130. +- REPEAT [dc]
  131. +- RANDOM [dc]
  132. +- AUTO_CUE [dc]
  133. +- TAPE_LENGTH [dc]
  134. +- SIDE_A_B [dc]
  135. +- TIME_FADE [dc]
  136. +- PEAK_SEARCH [dc]
  137. +- SEARCH_BACK [dc]
  138. +- SEARCH_FOR [dc]
  139. +- TRACK_NEXT [dc]
  140. +- TRACK_PREV [dc]
  141. +- STOP [dc]
  142. +- PAUSE [dc]
  143. +- PLAY [dc]
  144. """
  145. KEY_CD = "CD"
  146. KEY_LINE1 = "LINE1"
  147. KEY_LINE3 = "LINE3"
  148. KEY_MUTE = "MUTE"
  149. KEY_POWER = "POWER"
  150. KEY_VOLDOWN = "VOLDOWN"
  151. KEY_VOLUP = "VOLUP"
  152. #
  153. TX_TOPIC = ''
  154. TX_TYPE = base.TX_VALUE
  155. #
  156. RX_IGNORE_TOPICS = [KEY_CD, KEY_LINE1, KEY_LINE3, KEY_MUTE, KEY_POWER, KEY_VOLUP, KEY_VOLDOWN]
  157. def __state_logging__(self, inst, key, data):
  158. pass # This is just a TX device using self.set_*
  159. def set_cd(self, device=None, key=None, data=None):
  160. self.logger.info("Changing amplifier source to CD")
  161. self.send_command(self.KEY_CD, None)
  162. def set_line1(self, device=None, key=None, data=None):
  163. self.logger.info("Changing amplifier source to LINE1")
  164. self.send_command(self.KEY_LINE1, None)
  165. def set_line3(self, device=None, key=None, data=None):
  166. self.logger.info("Changing amplifier source to LINE3")
  167. self.send_command(self.KEY_LINE3, None)
  168. def set_mute(self, device=None, key=None, data=None):
  169. self.logger.info("Muting / Unmuting amplifier")
  170. self.send_command(self.KEY_MUTE, None)
  171. def set_power(self, device=None, key=None, data=None):
  172. self.logger.info("Power on/off amplifier")
  173. self.send_command(self.KEY_POWER, None)
  174. def set_volume_up(self, data=False):
  175. """data: [True, False]"""
  176. self.logger.info("Increasing amplifier volume")
  177. self.send_command(self.KEY_VOLUP, data)
  178. def set_volume_down(self, data=False):
  179. """data: [True, False]"""
  180. self.logger.info("Decreasing amplifier volume")
  181. self.send_command(self.KEY_VOLDOWN, data)
  182. def default_inc(self, device=None, key=None, data=None):
  183. self.set_volume_up(True)
  184. def default_dec(self, device=None, key=None, data=None):
  185. self.set_volume_down(True)
  186. def default_stop(self, device=None, key=None, data=None):
  187. self.set_volume_up(False)
  188. class audio_status(base):
  189. """ Communication (MQTT)
  190. audio_status
  191. +- state [True, False] <- status
  192. +- title [text] <- status
  193. """
  194. KEY_STATE = "state"
  195. KEY_TITLE = "title"
  196. #
  197. TX_TYPE = base.TX_VALUE
  198. #
  199. RX_KEYS = [KEY_STATE, KEY_TITLE]
  200. def __state_logging__(self, inst, key, data):
  201. if key in [self.KEY_STATE, self.KEY_TITLE]:
  202. self.logger.info("State change of '%s' to '%s'", key, repr(data))
  203. def set_state(self, num, data):
  204. """data: [True, False]"""
  205. self.send_command(self.KEY_STATE + "/" + str(num), data)
  206. def set_state_mcb(self, device, key, data):
  207. self.set_state(data)