Device definitions and intialisation
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

__init__.py 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devdi import props
  5. import logging
  6. import sys
  7. try:
  8. from config import APP_NAME as ROOT_LOGGER_NAME
  9. except ImportError:
  10. ROOT_LOGGER_NAME = 'root'
  11. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  12. class devices(dict):
  13. """
  14. Class to select a device and hold the device information
  15. """
  16. def __init__(self, mqtt_client):
  17. dict.__init__(self)
  18. #######
  19. # GFW #
  20. #######
  21. loc = props.LOC_GFW
  22. # MARION
  23. roo = props.ROO_MAR
  24. #
  25. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  26. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  27. # FLOOR
  28. roo = props.ROO_FLO
  29. #
  30. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  31. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT, 1) # Tradfri Main Light
  32. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_LLI_SBT, 2) # Tradfri Main Light
  33. # DIRK
  34. roo = props.ROO_DIR
  35. #
  36. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  37. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  38. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_CTR, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons
  39. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_MPP, props.DTY_MPP_4xx) # My 4 port Powerplug
  40. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_DEL, props.DTY_TLI_SBT) , # Tradfri Desklight
  41. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_RCA, props.DTY_MRE_xxx) # Remote Control IR Amplifier
  42. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASS, props.DTY_MAS_xxx) # Audio status Spotify
  43. self.add(mqtt_client, props.STG_MYA, loc, roo, props.FUN_ASM, props.DTY_MAS_xxx) # Audio status MPD
  44. self.add(mqtt_client, props.STG_ZGW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  45. #######
  46. # FFW #
  47. #######
  48. loc = props.LOC_FFW
  49. # JULIAN
  50. roo = props.ROO_JUL
  51. #
  52. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  53. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  54. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  55. # BATH
  56. roo = props.ROO_BAT
  57. #
  58. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  59. # LIVINGROOM
  60. roo = props.ROO_LIV
  61. #
  62. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  63. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  64. # SLEEP
  65. roo = props.ROO_SLP
  66. #
  67. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  68. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MAL, props.DTY_TLI_SBx) # Tradfri Main Light
  69. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  70. #######
  71. # FFE #
  72. #######
  73. loc = props.LOC_FFE
  74. # FLOOR
  75. roo = props.ROO_FLO
  76. #
  77. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  78. # KITCHEN
  79. roo = props.ROO_KIT
  80. #
  81. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  82. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_CIR, props.DTY_SHY_SW1) # Shelly Main Light
  83. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  84. # DININGROOM
  85. roo = props.ROO_DIN
  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_ZFE, loc, roo, props.FUN_FLL, props.DTY_SPP_SW1) # Powerplug Floor Light
  89. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_GAR, props.DTY_SPP_SW1) # Powerplug Garland
  90. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  91. # SLEEP
  92. roo = props.ROO_SLP
  93. #
  94. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  95. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  96. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_CTR, props.DTY_TIN_5xx) # Tradfri Input Device 5 Buttons
  97. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLD, props.DTY_TLI_SBx) # Tradfri Bed Light Dirk
  98. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_BLM, props.DTY_SPP_SW1) # Powerplug Bed Light Marion
  99. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  100. # LIVINGROOM
  101. roo = props.ROO_LIV
  102. #
  103. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  104. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MAL, props.DTY_TLI_SBT) # Tradfri Main Light
  105. for i in range(1, 7):
  106. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_FLL, props.DTY_TLI_SBT, i) # Tradfri Main Light
  107. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XTR, props.DTY_SPP_SW1) # Tradfri Main Light
  108. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_XST, props.DTY_SPP_SW1) # Tradfri Main Light
  109. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_HEA, props.DTY_BVL_xxx) # Brennenstuhl Heatingvalve
  110. #######
  111. # STW #
  112. #######
  113. loc = props.LOC_STW
  114. # FLOOR
  115. roo = props.ROO_STW
  116. #
  117. self.add(mqtt_client, props.STG_SHE, loc, roo, props.FUN_MAL, props.DTY_SHY_SW1) # Shelly Main Light
  118. self.add(mqtt_client, props.STG_ZFW, loc, roo, props.FUN_MSE, props.DTY_SMS_xxx, 1) # Motion Sensor Ground Floor
  119. self.add(mqtt_client, props.STG_ZFE, loc, roo, props.FUN_MSE, props.DTY_SMS_xxx, 2) # Motion Sensor Ground Floor
  120. def add(self, mqtt_client, stg, loc, roo, fun, dty, num=None):
  121. """Method to initilise a device
  122. Args:
  123. stg (numeric): Source transmittion group (see SIS_* in props)
  124. loc (numeric): Location (see LOC_* in props)
  125. roo (numeric): Room (see ROO_* in props)
  126. fun (numeric): Function (see FUN_* in props)
  127. dty (numeric): Device type (see DTP_* in props)
  128. num (numeric): Device number in case of multiple devices
  129. """
  130. topic = self.__topic__(stg, loc, roo, fun, num)
  131. dev_class = props.dty_repr(dty)
  132. if dev_class is None:
  133. logger.warning('Device type %d is not yet implemented. Topic %s will not be supported.', dty, topic)
  134. else:
  135. self[topic] = dev_class(mqtt_client, topic)
  136. def get(self, stg, loc, roo, fun, num=None):
  137. """Method to get a device
  138. Args:
  139. stg (numeric): Source transmittion group (see SIS_* in props)
  140. loc (numeric): Location (see LOC_* in props)
  141. roo (numeric): Room (see ROO_* in props)
  142. fun (numeric): Function (see FUN_* in props)
  143. num (numeric): Device number in case of multiple devices
  144. """
  145. return self[self.__topic__(stg, loc, roo, fun, num)]
  146. def __topic__(self, stg, loc, roo, fun, num):
  147. if num is None:
  148. postfix = ""
  149. else:
  150. postfix = "_%d" % num
  151. #
  152. if stg in [props.STG_ZFE, props.STG_ZFW, props.STG_ZGW]:
  153. # Temporary to fit to current implementation
  154. return '/'.join([
  155. props.stg_repr(stg),
  156. props.roo_repr(roo),
  157. props.fun_repr(fun)
  158. ]) + postfix
  159. else:
  160. return '/'.join([
  161. props.stg_repr(stg),
  162. props.loc_repr(loc),
  163. props.roo_repr(roo),
  164. props.fun_repr(fun)
  165. ]) + postfix