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.

devices.py 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. }.get(dty)
  32. def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None):
  33. """Method to initilise a device
  34. Args:
  35. stg (numeric): Source transmittion group (see SIS_* in props)
  36. loc (numeric): Location (see LOC_* in props)
  37. roo (numeric): Room (see ROO_* in props)
  38. fun (numeric): Function (see FUN_* in props)
  39. dty (numeric): Device type (see DTP_* in props)
  40. num (numeric): Device number in case of multiple devices
  41. """
  42. def get_device(dty, mqtt_client, topic):
  43. dev_class = self.__dty_repr__(dty)
  44. if dev_class is None:
  45. logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
  46. else:
  47. return dev_class(mqtt_client, topic)
  48. topic = str(topic_by_props(stg, loc, roo, fun))
  49. if num is None:
  50. this_device = get_device(dty, mqtt_client, topic)
  51. if this_device is None:
  52. logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
  53. else:
  54. self[topic] = this_device
  55. else:
  56. dg = []
  57. for i in num:
  58. device_topic = topic + '_%d' % i
  59. dg.append(get_device(dty, mqtt_client, device_topic))
  60. self[topic] = devices.group(*dg)
  61. def get(self, stg, loc, roo, fun):
  62. """Method to get a device
  63. Args:
  64. stg (numeric): Source transmittion group (see SIS_* in props)
  65. loc (numeric): Location (see LOC_* in props)
  66. roo (numeric): Room (see ROO_* in props)
  67. fun (numeric): Function (see FUN_* in props)
  68. num (numeric): Device number in case of multiple devices
  69. """
  70. topic = self.__topic__(stg, loc, roo, fun)
  71. return self[topic]
  72. class physical_devices(base):
  73. """
  74. Class to create and store physical smarthome devices
  75. """
  76. def __init__(self, mqtt_client):
  77. super().__init__(self)
  78. self.__init_gfw__(mqtt_client)
  79. self.__init_ffw__(mqtt_client)
  80. self.__init_ffe__(mqtt_client)
  81. self.__init_stw__(mqtt_client)
  82. def __init_gfw__(self, mqtt_client):
  83. loc = props.LOC_GFW
  84. # MARION
  85. roo = props.ROO_MAR
  86. #
  87. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  88. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  89. # FLOOR
  90. roo = props.ROO_FLO
  91. #
  92. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  93. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT) # Tradfri Main Light
  94. # DIRK
  95. roo = props.ROO_DIR
  96. #
  97. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  98. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  99. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_INP, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons
  100. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_MPP, props.DTY_MPP_4xx) # My 4 port Powerplug
  101. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DEL, props.DTY_TLI_SBT) # Tradfri Desklight
  102. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx) # Remote Control IR Amplifier
  103. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx) # Audio status Spotify
  104. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx) # Audio status MPD
  105. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  106. # GARDEN
  107. self.add(mqtt_client, props.STG_ZGW, props.LOC_GAR, props.ROO_GAR, props.FUN_GAR, props.DTY_SPP_SW1)
  108. def __init_ffw__(self, mqtt_client):
  109. loc = props.LOC_FFW
  110. # JULIAN
  111. roo = props.ROO_JUL
  112. #
  113. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  114. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  115. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  116. # BATH
  117. roo = props.ROO_BAT
  118. #
  119. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  120. # LIVINGROOM
  121. roo = props.ROO_LIV
  122. #
  123. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  124. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  125. # SLEEP
  126. roo = props.ROO_SLP
  127. #
  128. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  129. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx) # Tradfri Main Light
  130. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  131. def __init_ffe__(self, mqtt_client):
  132. loc = props.LOC_FFE
  133. # FLOOR
  134. roo = props.ROO_FLO
  135. #
  136. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  137. # KITCHEN
  138. roo = props.ROO_KIT
  139. #
  140. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  141. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1) # Shelly Main Light
  142. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  143. # DININGROOM
  144. roo = props.ROO_DIN
  145. #
  146. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  147. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1) # Powerplug Floor Light
  148. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1) # Powerplug Garland
  149. self.add(mqtt_client, props.STG_ZFE, 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_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  155. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_INP, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons
  156. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx) # Tradfri Bed Light Dirk
  157. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1) # Powerplug Bed Light Marion
  158. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  159. # LIVINGROOM
  160. roo = props.ROO_LIV
  161. #
  162. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  163. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  164. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT) # Tradfri Main Light
  165. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1) # Tradfri Main Light
  166. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1) # Tradfri Main Light
  167. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  168. def __init_stw__(self, mqtt_client):
  169. loc = props.LOC_STW
  170. # FLOOR
  171. #
  172. self.add(mqtt_client, props.STG_SHE, loc, props.ROO_STF, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  173. self.add(mqtt_client, props.STG_ZFE, loc, props.ROO_STF, props.FUN_MSE, props.DTY_SMS_xxx) # Motion Sensor First Floor
  174. self.add(mqtt_client, props.STG_ZGW, loc, props.ROO_STG, props.FUN_MSE, props.DTY_SMS_xxx) # Motion Sensor Ground Floor
  175. class videv_devices(base):
  176. """
  177. Class to create and store videv smarthome devices
  178. """
  179. def __init__(self, mqtt_client):
  180. super().__init__(self)
  181. self.__init_gfw__(mqtt_client)
  182. self.__init_ffw__(mqtt_client)
  183. self.__init_ffe__(mqtt_client)
  184. self.__init_stw__(mqtt_client)
  185. def __init_gfw__(self, mqtt_client):
  186. loc = props.LOC_GFW
  187. # TODO: Add devices
  188. def __init_ffw__(self, mqtt_client):
  189. loc = props.LOC_FFW
  190. # TODO: Add devices
  191. def __init_ffe__(self, mqtt_client):
  192. loc = props.LOC_FFE
  193. # TODO: Add devices
  194. def __init_stw__(self, mqtt_client):
  195. loc = props.LOC_STW
  196. # TODO: Add devices