Smarthome Functionen
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.

__init__.py 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. devices (DEVICES)
  6. =================
  7. **Author:**
  8. * Dirk Alders <sudo-dirk@mount-mockery.de>
  9. **Description:**
  10. This Module supports smarthome devices
  11. **Submodules:**
  12. * :mod:`shelly`
  13. * :mod:`silvercrest_powerplug`
  14. **Unittest:**
  15. See also the :download:`unittest <devices/_testresults_/unittest.pdf>` documentation.
  16. **Module Documentation:**
  17. """
  18. __DEPENDENCIES__ = []
  19. import json
  20. import logging
  21. try:
  22. from config import APP_NAME as ROOT_LOGGER_NAME
  23. except ImportError:
  24. ROOT_LOGGER_NAME = 'root'
  25. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  26. BATTERY_WARN_LEVEL = 5
  27. def DEVICE_TYPE_LIST():
  28. return [shelly, silvercrest_powerplug, my_powerplug, tradfri_light, tradfri_button]
  29. def is_json(data):
  30. try:
  31. json.loads(data)
  32. except json.decoder.JSONDecodeError:
  33. return False
  34. else:
  35. return True
  36. class base(dict):
  37. TX_TOPIC = None
  38. TX_VALUE = 0
  39. TX_DICT = 1
  40. TX_TYPE = -1
  41. TX_FILTER_DATA_KEYS = []
  42. #
  43. RX_KEYS = []
  44. RX_IGNORE_TOPICS = []
  45. RX_IGNORE_KEYS = []
  46. RX_FILTER_DATA_KEYS = []
  47. def __init__(self, mqtt_client, topic):
  48. # data storage
  49. self.mqtt_client = mqtt_client
  50. self.topic = topic
  51. # initialisations
  52. dict.__init__(self)
  53. mqtt_client.add_callback(
  54. topic=self.topic, callback=self.receive_callback)
  55. mqtt_client.add_callback(
  56. topic=self.topic+"/#", callback=self.receive_callback)
  57. #
  58. self.callback_list = []
  59. self.warning_callback = None
  60. #
  61. self.__previous__ = {}
  62. def receive_callback(self, client, userdata, message):
  63. self.unpack(message)
  64. def unpack_filter(self, key):
  65. if key in self.RX_FILTER_DATA_KEYS:
  66. if self.get(key) == 1 or self.get(key) == 'on' or self.get(key) == 'ON':
  67. self[key] = True
  68. elif self.get(key) == 0 or self.get(key) == 'off' or self.get(key) == 'OFF':
  69. self[key] = False
  70. def unpack_single_value(self, key, data):
  71. prev_value = self.get(key)
  72. if key in self.RX_KEYS:
  73. self[key] = data
  74. self.__previous__[key] = prev_value
  75. # Filter, if needed
  76. self.unpack_filter(key)
  77. if prev_value != self.get(key):
  78. logger.info("Received new data for (%s) %s - %s", self.topic, key, str(self.get(key)))
  79. else:
  80. logger.debug("Received data for (%s) %s - %s", self.topic, key, str(self.get(key)))
  81. self.callback_caller(key, self[key])
  82. elif key not in self.RX_IGNORE_KEYS:
  83. logger.warning('Got a message from \"%s\" with unparsed content "%s"', self.topic, key)
  84. else:
  85. logger.debug("Ignoring key %s", key)
  86. def unpack(self, message):
  87. content_key = message.topic[len(self.topic) + 1:]
  88. if content_key not in self.RX_IGNORE_TOPICS and (not message.topic.endswith(self.TX_TOPIC) or len(self.TX_TOPIC) == 0):
  89. logger.debug("Unpacking content_key \"%s\" from message.", content_key)
  90. if is_json(message.payload):
  91. data = json.loads(message.payload)
  92. if type(data) is dict:
  93. for key in data:
  94. self.unpack_single_value(key, data[key])
  95. else:
  96. self.unpack_single_value(content_key, data)
  97. # String
  98. else:
  99. self.unpack_single_value(
  100. content_key, message.payload.decode('utf-8'))
  101. self.warning_caller()
  102. else:
  103. logger.debug("Ignoring topic %s", content_key)
  104. def pack_filter(self, key, data):
  105. if key in self.TX_FILTER_DATA_KEYS:
  106. if data is True:
  107. return "on"
  108. elif data is False:
  109. return "off"
  110. else:
  111. return data
  112. return data
  113. def set(self, key, data):
  114. self.pack(key, data)
  115. def pack(self, key, data):
  116. data = self.pack_filter(key, data)
  117. if self.TX_TOPIC is not None:
  118. if self.TX_TYPE < 0:
  119. logger.error(
  120. "Unknown tx type. Set TX_TYPE of class to a known value")
  121. else:
  122. logger.info("Sending data for (%s) %s - %s", self.topic, key, str(data))
  123. if self.TX_TYPE == self.TX_DICT:
  124. self.mqtt_client.send('/'.join([self.topic, self.TX_TOPIC]), json.dumps({key: data}))
  125. else:
  126. if type(data) not in [str, bytes]:
  127. data = json.dumps(data)
  128. self.mqtt_client.send('/'.join([self.topic, key, self.TX_TOPIC]
  129. if len(self.TX_TOPIC) > 0 else [self.topic, key]), data)
  130. else:
  131. logger.error(
  132. "Unknown tx toptic. Set TX_TOPIC of class to a known value")
  133. def add_callback(self, key, data, callback):
  134. """
  135. key: key or None for all keys
  136. data: data or None for all data
  137. """
  138. cb_tup = (key, data, callback)
  139. if cb_tup not in self.callback_list:
  140. self.callback_list.append(cb_tup)
  141. def add_warning_callback(self, callback):
  142. self.warning_callback = callback
  143. def warning_call_condition(self):
  144. return False
  145. def callback_caller(self, key, data):
  146. for cb_key, cb_data, callback in self.callback_list:
  147. if (cb_key == key or cb_key is None) and (cb_data == data or cb_data is None) and callback is not None:
  148. callback(self, key, data)
  149. def warning_caller(self):
  150. if self.warning_call_condition():
  151. warn_txt = self.warning_text()
  152. logger.warning(warn_txt)
  153. if self.warning_callback is not None:
  154. self.warning_callback(self, warn_txt)
  155. def warning_text(self, data):
  156. return "default warning text - replace parent warning_text function"
  157. def previous_value(self, key):
  158. return self.__previous__.get(key)
  159. class shelly(base):
  160. KEY_OUTPUT_0 = "relay/0"
  161. KEY_OUTPUT_1 = "relay/1"
  162. KEY_INPUT_0 = "input/0"
  163. KEY_INPUT_1 = "input/1"
  164. KEY_LONGPUSH_0 = "longpush/0"
  165. KEY_LONGPUSH_1 = "longpush/1"
  166. KEY_TEMPERATURE = "temperature"
  167. KEY_OVERTEMPERATURE = "overtemperature"
  168. #
  169. TX_TOPIC = 'command'
  170. TX_TYPE = base.TX_VALUE
  171. TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1]
  172. #
  173. RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1,
  174. KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1,
  175. KEY_OVERTEMPERATURE, KEY_TEMPERATURE]
  176. RX_IGNORE_TOPICS = [KEY_OUTPUT_0 + '/' + "energy", KEY_OUTPUT_1 + '/' + "energy",
  177. 'input_event/0', 'input_event/1']
  178. RX_IGNORE_KEYS = ['temperature_f']
  179. RX_FILTER_DATA_KEYS = [KEY_INPUT_0, KEY_INPUT_1, KEY_LONGPUSH_0, KEY_LONGPUSH_1,
  180. KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OVERTEMPERATURE]
  181. def __init__(self, mqtt_client, topic):
  182. super().__init__(mqtt_client, topic)
  183. #
  184. # WARNING CALL
  185. #
  186. def warning_call_condition(self):
  187. return self.get(self.KEY_OVERTEMPERATURE)
  188. def warning_text(self):
  189. if self.overtemperature:
  190. if self.temperature is not None:
  191. return "Overtemperature detected for %s. Temperature was %.1f°C." % (self.topic, self.temperature)
  192. else:
  193. return "Overtemperature detected for %s." % self.topic
  194. #
  195. # RX
  196. #
  197. @property
  198. def output_0(self):
  199. """rv: [True, False]"""
  200. return self.get(self.KEY_OUTPUT_0)
  201. @property
  202. def output_1(self):
  203. """rv: [True, False]"""
  204. return self.get(self.KEY_OUTPUT_1)
  205. @property
  206. def input_0(self):
  207. """rv: [True, False]"""
  208. return self.get(self.KEY_INPUT_0)
  209. @property
  210. def input_1(self):
  211. """rv: [True, False]"""
  212. return self.get(self.KEY_INPUT_1)
  213. @property
  214. def longpush_0(self):
  215. """rv: [True, False]"""
  216. return self.get(self.KEY_LONGPUSH_0)
  217. @property
  218. def longpush_1(self):
  219. """rv: [True, False]"""
  220. return self.get(self.KEY_LONGPUSH_1)
  221. @property
  222. def temperature(self):
  223. """rv: numeric value"""
  224. return self.get(self.KEY_TEMPERATURE)
  225. #
  226. # TX
  227. #
  228. def set_output_0(self, state):
  229. """state: [True, False, 'toggle']"""
  230. self.pack(self.KEY_OUTPUT_0, state)
  231. def set_output_1(self, state):
  232. """state: [True, False, 'toggle']"""
  233. self.pack(self.KEY_OUTPUT_1, state)
  234. class silvercrest_powerplug(base):
  235. KEY_LINKQUALITY = "linkquality"
  236. KEY_OUTPUT_0 = "state"
  237. #
  238. TX_TOPIC = 'set'
  239. TX_TYPE = base.TX_DICT
  240. TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
  241. #
  242. RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0]
  243. RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
  244. def __init__(self, mqtt_client, topic):
  245. super().__init__(mqtt_client, topic)
  246. #
  247. # RX
  248. #
  249. @property
  250. def output_0(self):
  251. """rv: [True, False]"""
  252. return self.get(self.KEY_OUTPUT_0)
  253. @property
  254. def linkquality(self):
  255. """rv: numeric value"""
  256. return self.get(self.KEY_LINKQUALITY)
  257. #
  258. # TX
  259. #
  260. def set_output_0(self, state):
  261. """state: [True, False, 'toggle']"""
  262. self.pack(self.KEY_OUTPUT_0, state)
  263. class my_powerplug(base):
  264. KEY_OUTPUT_0 = "output/1"
  265. KEY_OUTPUT_1 = "output/2"
  266. KEY_OUTPUT_2 = "output/3"
  267. KEY_OUTPUT_3 = "output/4"
  268. KEY_OUTPUT_ALL = "output/all"
  269. KEY_OUTPUT_LIST = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
  270. #
  271. TX_TOPIC = 'set'
  272. TX_TYPE = base.TX_VALUE
  273. #
  274. RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
  275. def __init__(self, mqtt_client, topic):
  276. super().__init__(mqtt_client, topic)
  277. #
  278. # RX
  279. #
  280. @property
  281. def output_0(self):
  282. """rv: [True, False]"""
  283. return self.get(self.KEY_OUTPUT_0)
  284. @property
  285. def output_1(self):
  286. """rv: [True, False]"""
  287. return self.get(self.KEY_OUTPUT_1)
  288. @property
  289. def output_2(self):
  290. """rv: [True, False]"""
  291. return self.get(self.KEY_OUTPUT_2)
  292. @property
  293. def output_3(self):
  294. """rv: [True, False]"""
  295. return self.get(self.KEY_OUTPUT_3)
  296. #
  297. # TX
  298. #
  299. def set_output(self, key, state):
  300. if key in self.KEY_OUTPUT_LIST:
  301. self.pack(key, state)
  302. else:
  303. logging.error("Unknown key to set the output!")
  304. def set_output_0(self, state):
  305. """state: [True, False, 'toggle']"""
  306. self.pack(self.KEY_OUTPUT_0, state)
  307. def set_output_1(self, state):
  308. """state: [True, False, 'toggle']"""
  309. self.pack(self.KEY_OUTPUT_1, state)
  310. def set_output_2(self, state):
  311. """state: [True, False, 'toggle']"""
  312. self.pack(self.KEY_OUTPUT_2, state)
  313. def set_output_3(self, state):
  314. """state: [True, False, 'toggle']"""
  315. self.pack(self.KEY_OUTPUT_3, state)
  316. def set_output_all(self, state):
  317. """state: [True, False, 'toggle']"""
  318. self.pack(self.KEY_OUTPUT_ALL, state)
  319. class tradfri_light(base):
  320. KEY_LINKQUALITY = "linkquality"
  321. KEY_OUTPUT_0 = "state"
  322. KEY_BRIGHTNESS = "brightness"
  323. KEY_COLOR_TEMP = "color_temp"
  324. KEY_BRIGHTNESS_FADE = "brightness_move"
  325. #
  326. TX_TOPIC = 'set'
  327. TX_TYPE = base.TX_DICT
  328. TX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_BRIGHTNESS_FADE]
  329. #
  330. RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
  331. RX_IGNORE_KEYS = ['update', 'color_mode']
  332. RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
  333. def __init__(self, mqtt_client, topic):
  334. super().__init__(mqtt_client, topic)
  335. def unpack_filter(self, key):
  336. if key == self.KEY_BRIGHTNESS:
  337. self[key] = (self[key] - 1) * 100 / 254
  338. elif key == self.KEY_COLOR_TEMP:
  339. self[key] = (self[key] - 250) * 100 / 204
  340. else:
  341. super().unpack_filter(key)
  342. def pack_filter(self, key, data):
  343. if key == self.KEY_BRIGHTNESS:
  344. return data * 254 / 100 + 1
  345. elif key == self.KEY_COLOR_TEMP:
  346. return data * 204 / 100 + 250
  347. else:
  348. return super().pack_filter(key, data)
  349. #
  350. # RX
  351. #
  352. @property
  353. def output_0(self):
  354. """rv: [True, False]"""
  355. return self.get(self.KEY_OUTPUT_0, False)
  356. @property
  357. def linkquality(self):
  358. """rv: numeric value"""
  359. return self.get(self.KEY_LINKQUALITY, 0)
  360. @property
  361. def brightness(self):
  362. """rv: numeric value [0%, ..., 100%"""
  363. return self.get(self.KEY_BRIGHTNESS, 0)
  364. @property
  365. def color_temp(self):
  366. """rv: numeric value [0%, ..., 100%"""
  367. return self.get(self.KEY_COLOR_TEMP, 0)
  368. #
  369. # TX
  370. #
  371. def set_output_0(self, state):
  372. """state: [True, False, 'toggle']"""
  373. self.pack(self.KEY_OUTPUT_0, state)
  374. def set_brightness(self, brightness):
  375. """brightness: [0, ..., 100]"""
  376. self.pack(self.KEY_BRIGHTNESS, brightness)
  377. def default_inc(self, speed=40):
  378. self.pack(self.KEY_BRIGHTNESS_FADE, speed)
  379. def default_dec(self, speed=-40):
  380. self.default_inc(speed)
  381. def default_stop(self):
  382. self.default_inc(0)
  383. def set_color_temp(self, color_temp):
  384. """color_temp: [0, ..., 100]"""
  385. self.pack(self.KEY_COLOR_TEMP, color_temp)
  386. class tradfri_button(base):
  387. ACTION_TOGGLE = "toggle"
  388. ACTION_BRIGHTNESS_UP = "brightness_up_click"
  389. ACTION_BRIGHTNESS_DOWN = "brightness_down_click"
  390. ACTION_RIGHT = "arrow_right_click"
  391. ACTION_LEFT = "arrow_left_click"
  392. ACTION_BRIGHTNESS_UP_LONG = "brightness_up_hold"
  393. ACTION_BRIGHTNESS_UP_RELEASE = "brightness_up_release"
  394. ACTION_BRIGHTNESS_DOWN_LONG = "brightness_down_hold"
  395. ACTION_BRIGHTNESS_DOWN_RELEASE = "brightness_down_release"
  396. ACTION_RIGHT_LONG = "arrow_right_hold"
  397. ACTION_RIGHT_RELEASE = "arrow_right_release"
  398. ACTION_LEFT_LONG = "arrow_left_hold"
  399. ACTION_LEFT_RELEASE = "arrow_left_release"
  400. #
  401. KEY_LINKQUALITY = "linkquality"
  402. KEY_BATTERY = "battery"
  403. KEY_ACTION = "action"
  404. KEY_ACTION_DURATION = "action_duration"
  405. #
  406. TX_TOPIC = ''
  407. #
  408. RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_ACTION]
  409. RX_IGNORE_KEYS = ['update', KEY_ACTION_DURATION]
  410. def __init__(self, mqtt_client, topic):
  411. super().__init__(mqtt_client, topic)
  412. #
  413. # RX
  414. #
  415. @property
  416. def action(self):
  417. """rv: action_txt"""
  418. return self.get(self.KEY_ACTION)
  419. #
  420. # WARNING CALL
  421. #
  422. def warning_call_condition(self):
  423. return self.get(self.KEY_BATTERY) <= BATTERY_WARN_LEVEL
  424. def warning_text(self):
  425. return "Low battery level detected for %s. Battery level was %.0f%%." % (self.topic, self.get(self.KEY_BATTERY))
  426. class nodered_gui(base):
  427. KEY_FEEDBACK = "feedback"
  428. KEY_ENABLE = "enable"
  429. KEY_STATE = "state"
  430. KEY_BRIGHTNESS = "brightness"
  431. KEY_COLOR_TEMP = "color_temp"
  432. KEY_HEATING_BOOST = "heating_boost"
  433. KEY_HEATING_SETPOINT = "heating_setpoint"
  434. KEY_OFF_BUTTON = "off_button"
  435. #
  436. TX_TOPIC = 'set'
  437. TX_TYPE = base.TX_VALUE
  438. #
  439. RX_KEYS = [KEY_STATE, KEY_BRIGHTNESS, KEY_COLOR_TEMP, KEY_HEATING_BOOST, KEY_HEATING_SETPOINT, KEY_OFF_BUTTON]
  440. def __init__(self, mqtt_client, topic):
  441. super().__init__(mqtt_client, topic)
  442. #
  443. # RX
  444. #
  445. @property
  446. def state(self):
  447. """rv: [True, False]"""
  448. return self.get(self.KEY_STATE)
  449. @property
  450. def brightness(self):
  451. """rv: [0, ..., 100]"""
  452. return self.get(self.KEY_BRIGHTNESS)
  453. @property
  454. def color_temp(self):
  455. """rv: [0, ..., 100]"""
  456. return self.get(self.KEY_COLOR_TEMP)
  457. @property
  458. def heating_boost(self):
  459. """rv: [True, False]"""
  460. return self.get(self.KEY_HEATING_BOOST)
  461. @property
  462. def heating_(self):
  463. """rv: [5, ..., 30]"""
  464. return self.get(self.KEY_HEATING_SETPOINT)
  465. @property
  466. def off_button(self):
  467. """rv: [True, False]"""
  468. return self.get(self.KEY_OFF_BUTTON)
  469. #
  470. # TX
  471. #
  472. def set_feedback(self, data):
  473. self.pack(self.KEY_FEEDBACK, data)
  474. def enable(self, data):
  475. """data: [True, False]"""
  476. self.pack(self.KEY_ENABLE, data)
  477. class brennenstuhl_heatingvalve(base):
  478. KEY_LINKQUALITY = "linkquality"
  479. KEY_BATTERY = "battery"
  480. KEY_HEATING_SETPOINT = "current_heating_setpoint"
  481. KEY_TEMPERATURE = "local_temperature"
  482. #
  483. KEY_AWAY_MODE = "away_mode"
  484. KEY_CHILD_LOCK = "child_lock"
  485. KEY_PRESET = "preset"
  486. KEY_SYSTEM_MODE = "system_mode"
  487. KEY_VALVE_DETECTION = "valve_detection"
  488. KEY_WINDOW_DETECTION = "window_detection"
  489. #
  490. TX_TOPIC = 'set'
  491. TX_TYPE = base.TX_DICT
  492. #
  493. RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_HEATING_SETPOINT, KEY_TEMPERATURE]
  494. RX_IGNORE_KEYS = [KEY_AWAY_MODE, KEY_CHILD_LOCK, KEY_PRESET,
  495. KEY_SYSTEM_MODE, KEY_VALVE_DETECTION, KEY_WINDOW_DETECTION]
  496. def __init__(self, mqtt_client, topic):
  497. super().__init__(mqtt_client, topic)
  498. self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps(
  499. {self.KEY_WINDOW_DETECTION: "ON", self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat"}))
  500. def warning_call_condition(self):
  501. return self.get(self.KEY_BATTERY) <= BATTERY_WARN_LEVEL
  502. def warning_text(self):
  503. return "Low battery level detected for %s. Battery level was %.0f%%." % (self.topic, self.get(self.KEY_BATTERY))
  504. #
  505. # RX
  506. #
  507. @property
  508. def linkqulity(self):
  509. return self.get(self.KEY_LINKQUALITY)
  510. @property
  511. def heating_setpoint(self):
  512. return self.get(self.KEY_HEATING_SETPOINT)
  513. @property
  514. def temperature(self):
  515. return self.get(self.KEY_TEMPERATURE)
  516. #
  517. # TX
  518. #
  519. def set_heating_setpoint(self, setpoint):
  520. self.pack(self.KEY_HEATING_SETPOINT, setpoint)
  521. class remote(base):
  522. KEY_CD = "CD"
  523. KEY_LINE1 = "LINE1"
  524. KEY_LINE3 = "LINE3"
  525. KEY_MUTE = "MUTE"
  526. KEY_POWER = "POWER"
  527. KEY_VOLDOWN = "VOLDOWN"
  528. KEY_VOLUP = "VOLUP"
  529. #
  530. TX_TOPIC = ''
  531. TX_TYPE = base.TX_VALUE
  532. #
  533. RX_IGNORE_TOPICS = [KEY_CD, KEY_LINE1, KEY_LINE3, KEY_MUTE, KEY_POWER, KEY_VOLUP, KEY_VOLDOWN]
  534. def set_cd(self):
  535. self.pack(self.KEY_CD, None)
  536. def set_line1(self):
  537. self.pack(self.KEY_LINE1, None)
  538. def set_line3(self):
  539. self.pack(self.KEY_LINE3, None)
  540. def set_mute(self):
  541. self.pack(self.KEY_MUTE, None)
  542. def set_power(self):
  543. self.pack(self.KEY_POWER, None)
  544. def set_volume_up(self, data=False):
  545. """data: [True, False]"""
  546. self.pack(self.KEY_VOLUP, data)
  547. def set_volume_down(self, data=False):
  548. """data: [True, False]"""
  549. self.pack(self.KEY_VOLDOWN, data)
  550. def default_inc(self):
  551. self.set_volume_up(True)
  552. def default_dec(self):
  553. self.set_volume_down(True)
  554. def default_stop(self):
  555. self.set_volume_up(False)
  556. class status(base):
  557. KEY_STATE = "state"
  558. #
  559. TX_TOPIC = 'set'
  560. TX_TYPE = base.TX_VALUE
  561. #
  562. RX_KEYS = [KEY_STATE]
  563. def set_state(self, num, data):
  564. """data: [True, False]"""
  565. self.pack(self.KEY_STATE + "/" + str(num), data)
  566. class audio_status(status):
  567. KEY_TITLE = "title"
  568. #
  569. RX_KEYS = [status.KEY_STATE, KEY_TITLE]