Control for Window lights
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

mydevices.py 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devices.base import base, base_output
  5. import logging
  6. class powerplug(base_output):
  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_LINE2 = "LINE2"
  148. KEY_LINE3 = "LINE3"
  149. KEY_PHONO = "PHONO"
  150. KEY_MUTE = "MUTE"
  151. KEY_POWER = "POWER"
  152. KEY_VOLDOWN = "VOLDOWN"
  153. KEY_VOLUP = "VOLUP"
  154. #
  155. TX_TOPIC = ''
  156. TX_TYPE = base.TX_VALUE
  157. #
  158. RX_IGNORE_TOPICS = [KEY_CD, KEY_LINE1, KEY_LINE2, KEY_LINE3, KEY_PHONO, KEY_MUTE, KEY_POWER, KEY_VOLUP, KEY_VOLDOWN]
  159. def __state_logging__(self, inst, key, data):
  160. pass # This is just a TX device using self.set_*
  161. def set_cd(self, device=None, key=None, data=None):
  162. self.logger.info("Changing amplifier source to CD")
  163. self.send_command(self.KEY_CD, None)
  164. def set_line1(self, device=None, key=None, data=None):
  165. self.logger.info("Changing amplifier source to LINE1")
  166. self.send_command(self.KEY_LINE1, None)
  167. def set_line2(self, device=None, key=None, data=None):
  168. self.logger.info("Changing amplifier source to LINE2")
  169. self.send_command(self.KEY_LINE2, None)
  170. def set_line3(self, device=None, key=None, data=None):
  171. self.logger.info("Changing amplifier source to LINE3")
  172. self.send_command(self.KEY_LINE3, None)
  173. def set_phono(self, device=None, key=None, data=None):
  174. self.logger.info("Changing amplifier source to PHONO")
  175. self.send_command(self.KEY_PHONO, None)
  176. def set_mute(self, device=None, key=None, data=None):
  177. self.logger.info("Muting / Unmuting amplifier")
  178. self.send_command(self.KEY_MUTE, None)
  179. def set_power(self, device=None, key=None, data=None):
  180. self.logger.info("Power on/off amplifier")
  181. self.send_command(self.KEY_POWER, None)
  182. def set_volume_up(self, data=False):
  183. """data: [True, False]"""
  184. self.logger.info("Increasing amplifier volume")
  185. self.send_command(self.KEY_VOLUP, data)
  186. def set_volume_down(self, data=False):
  187. """data: [True, False]"""
  188. self.logger.info("Decreasing amplifier volume")
  189. self.send_command(self.KEY_VOLDOWN, data)
  190. def default_inc(self, device=None, key=None, data=None):
  191. self.set_volume_up(True)
  192. def default_dec(self, device=None, key=None, data=None):
  193. self.set_volume_down(True)
  194. def default_stop(self, device=None, key=None, data=None):
  195. self.set_volume_up(False)
  196. class audio_status(base):
  197. """ Communication (MQTT)
  198. audio_status
  199. +- state [True, False] <- status
  200. +- title [text] <- status
  201. """
  202. KEY_STATE = "state"
  203. KEY_TITLE = "title"
  204. #
  205. TX_TYPE = base.TX_VALUE
  206. #
  207. RX_KEYS = [KEY_STATE, KEY_TITLE]
  208. def __state_logging__(self, inst, key, data):
  209. if key in [self.KEY_STATE, self.KEY_TITLE]:
  210. self.logger.info("State change of '%s' to '%s'", key, repr(data))
  211. def set_state(self, num, data):
  212. """data: [True, False]"""
  213. self.send_command(self.KEY_STATE + "/" + str(num), data)
  214. def set_state_mcb(self, device, key, data):
  215. self.set_state(data)