Device definitions and intialisation
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devdi import topic as props
  5. from devdi.topic import topic_by_props
  6. import devices
  7. import logging
  8. import sys
  9. try:
  10. from config import APP_NAME as ROOT_LOGGER_NAME
  11. except ImportError:
  12. ROOT_LOGGER_NAME = 'root'
  13. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  14. class base(dict):
  15. def __init__(self, mqtt_client):
  16. super().__init__(self)
  17. def __dty_repr__(self, dty):
  18. return {
  19. props.DTY_SHY_SW1: devices.shelly_sw1,
  20. props.DTY_TLI_Sxx: devices.tradfri_sw,
  21. props.DTY_TLI_SBx: devices.tradfri_sw_br,
  22. props.DTY_TLI_SBT: devices.tradfri_sw_br_ct,
  23. props.DTY_TIN_5xx: devices.tradfri_button,
  24. props.DTY_LLI_SBT: devices.livarno_sw_br_ct,
  25. props.DTY_BVL_xxx: devices.brennenstuhl_heatingvalve,
  26. props.DTY_SPP_SW1: devices.silvercrest_powerplug,
  27. props.DTY_SMS_xxx: devices.silvercrest_motion_sensor,
  28. props.DTY_MPP_4xx: devices.my_powerplug,
  29. props.DTY_MAS_xxx: devices.audio_status,
  30. props.DTY_MRE_xxx: devices.remote,
  31. props.DTY_MAM_THP: devices.my_ambient,
  32. }.get(dty)
  33. def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None):
  34. """Method to initilise a device
  35. Args:
  36. stg (numeric): Source transmittion group (see SIS_* in props)
  37. loc (numeric): Location (see LOC_* in props)
  38. roo (numeric): Room (see ROO_* in props)
  39. fun (numeric): Function (see FUN_* in props)
  40. dty (numeric): Device type (see DTP_* in props)
  41. num (numeric): Device number in case of multiple devices
  42. """
  43. def get_device(dty, mqtt_client, topic):
  44. dev_class = self.__dty_repr__(dty)
  45. if dev_class is None:
  46. logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
  47. else:
  48. return dev_class(mqtt_client, topic)
  49. topic = str(topic_by_props(stg, loc, roo, fun))
  50. if num is None:
  51. this_device = get_device(dty, mqtt_client, topic)
  52. if this_device is None:
  53. logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
  54. else:
  55. self[topic] = this_device
  56. logger.debug("Added a device type=%s, topic=%s", dty, topic)
  57. else:
  58. dg = []
  59. for i in range(1, num + 1):
  60. device_topic = topic + '_%d' % i
  61. dg.append(get_device(dty, mqtt_client, device_topic))
  62. self[topic] = devices.group(*dg)
  63. logger.debug("Added a devicegroup type=%s, topic=%s", dty, topic + '_<num>')
  64. def get(self, stg, loc, roo, fun):
  65. """Method to get a device
  66. Args:
  67. stg (numeric): Source transmittion group (see SIS_* in props)
  68. loc (numeric): Location (see LOC_* in props)
  69. roo (numeric): Room (see ROO_* in props)
  70. fun (numeric): Function (see FUN_* in props)
  71. """
  72. topic = topic_by_props(stg, loc, roo, fun)
  73. return self[topic]
  74. def get_str(self, stg, loc, roo, fun):
  75. """Method to get a device by str version of props
  76. Args:
  77. stg (str): Source transmittion group (see SIS_* in props)
  78. loc (str): Location (see LOC_* in props)
  79. roo (str): Room (see ROO_* in props)
  80. fun (str): Function (see FUN_* in props)
  81. """
  82. return self.get(getattr(props, stg), getattr(props, loc), getattr(props, roo), getattr(props, fun))
  83. class physical_devices(base):
  84. """
  85. Class to create and store physical smarthome devices
  86. """
  87. def __init__(self, mqtt_client):
  88. super().__init__(self)
  89. self.__init_gfw__(mqtt_client)
  90. self.__init_ffw__(mqtt_client)
  91. self.__init_ffe__(mqtt_client)
  92. self.__init_stw__(mqtt_client)
  93. self.__init_gar__(mqtt_client)
  94. def __init_gfw__(self, mqtt_client):
  95. loc = props.LOC_GFW
  96. # MARION
  97. roo = props.ROO_MAR
  98. #
  99. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  100. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  101. # FLOOR
  102. roo = props.ROO_FLO
  103. #
  104. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  105. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT, 2) # Tradfri Main Light
  106. # DIRK
  107. roo = props.ROO_DIR
  108. #
  109. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  110. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  111. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_INP, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons
  112. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_MPP, props.DTY_MPP_4xx) # My 4 port Powerplug
  113. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DEL, props.DTY_TLI_SBT) # Tradfri Desklight
  114. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DCK, props.DTY_SPP_SW1) # Tradfri 1 port Powerplug
  115. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx) # Remote Control IR Amplifier
  116. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx) # Audio status Spotify
  117. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx) # Audio status MPD
  118. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASB, props.DTY_MAS_xxx) # Audio status Bluetooth
  119. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  120. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_AMB, props.DTY_MAM_THP) # My Ambient information
  121. def __init_gar__(self, mqtt_client):
  122. loc = props.LOC_GAR
  123. # GARDEN
  124. roo = props.ROO_GAR
  125. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1) # Powerplugs Garden
  126. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_REP, props.DTY_SPP_SW1) # WiFi Garden
  127. def __init_ffw__(self, mqtt_client):
  128. loc = props.LOC_FFW
  129. # FLOOR
  130. roo = props.ROO_FLO
  131. #
  132. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  133. # JULIAN
  134. roo = props.ROO_JUL
  135. #
  136. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  137. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  138. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  139. # BATH
  140. roo = props.ROO_BAT
  141. #
  142. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  143. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  144. # LIVINGROOM
  145. roo = props.ROO_LIV
  146. #
  147. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  148. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  149. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  150. # SLEEP
  151. roo = props.ROO_SLP
  152. #
  153. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  154. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx) # Tradfri Main Light
  155. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  156. def __init_ffe__(self, mqtt_client):
  157. loc = props.LOC_FFE
  158. # FLOOR
  159. roo = props.ROO_FLO
  160. #
  161. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  162. # KITCHEN
  163. roo = props.ROO_KIT
  164. #
  165. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  166. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1) # Shelly Main Light
  167. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  168. # DININGROOM
  169. roo = props.ROO_DIN
  170. #
  171. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  172. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1) # Powerplug Floor Light
  173. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1) # Powerplug Garland
  174. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  175. # SLEEP
  176. roo = props.ROO_SLP
  177. #
  178. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  179. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  180. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_INP, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons
  181. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx) # Tradfri Bed Light Dirk
  182. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1) # Powerplug Bed Light Marion
  183. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  184. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_WLI, props.DTY_TLI_SBx) # Tradfri Wardobe light
  185. # LIVINGROOM
  186. roo = props.ROO_LIV
  187. #
  188. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  189. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  190. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT, 6) # Tradfri Floorlamp
  191. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1) # X-Mas Tree
  192. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1) # X-Mas Star
  193. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  194. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_AMB, props.DTY_MAM_THP) # My Ambient information
  195. def __init_stw__(self, mqtt_client):
  196. loc = props.LOC_STW
  197. # FLOOR
  198. #
  199. self.add(mqtt_client, props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  200. self.add(mqtt_client, props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE, props.DTY_SMS_xxx) # Motion Sensor First Floor
  201. self.add(mqtt_client, props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE, props.DTY_SMS_xxx) # Motion Sensor Ground Floor
  202. class videv_devices(base):
  203. """
  204. Class to create and store videv smarthome devices
  205. """
  206. def __init__(self, mqtt_client):
  207. super().__init__(self)
  208. self.__init_gfw__(mqtt_client)
  209. self.__init_ffw__(mqtt_client)
  210. self.__init_ffe__(mqtt_client)
  211. self.__init_stw__(mqtt_client)
  212. def __init_gfw__(self, mqtt_client):
  213. loc = props.LOC_GFW
  214. # TODO: Add devices
  215. def __init_ffw__(self, mqtt_client):
  216. loc = props.LOC_FFW
  217. # TODO: Add devices
  218. def __init_ffe__(self, mqtt_client):
  219. loc = props.LOC_FFE
  220. # TODO: Add devices
  221. def __init_stw__(self, mqtt_client):
  222. loc = props.LOC_STW
  223. # TODO: Add devices