Advertisement
Guest User

Untitled

a guest
Mar 1st, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.74 KB | None | 0 0
  1. # This module's future home should be inside userdata/addon_data/script.cinema.experience/ha_scripts
  2. # to make sure it does not get over written when updating the script
  3.  
  4.  
  5. import xbmc, xbmcaddon
  6. import sys, urllib2, os, httplib
  7. from threading import Thread
  8. from urllib import urlencode
  9.  
  10. __script__ = sys.modules[ "__main__" ].__script__
  11. __scriptID__ = sys.modules[ "__main__" ].__scriptID__
  12. triggers = sys.modules[ "__main__" ].triggers
  13. ha_settings = sys.modules[ "__main__" ].ha_settings
  14. BASE_RESOURCE_PATH = sys.modules["__main__"].BASE_RESOURCE_PATH
  15. sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib" ) )
  16. import utils
  17.  
  18. class Domoticz:
  19. def __init__(self):
  20. self.host='192.168.1.4:8080'
  21.  
  22. def _request(self, url):
  23. urllib2.urlopen(url)
  24.  
  25. def turn_on(self, _id):
  26. url='http://%s/json.htm?type=command&param=switchlight&idx=%s&switchcmd=On' % (self.host, _id)
  27. self._request(url)
  28.  
  29. def turn_off(self, _id):
  30. url='http://%s/json.htm?type=command&param=switchlight&idx=%s&switchcmd=Off&level=0' % (self.host, _id)
  31. self._request(url)
  32.  
  33. def dim(self, _id, level):
  34. f = urllib.urlencode({ 'type' : 'command', 'param' : 'switchlight' , 'idx' : _id , 'switchcmd' : 'Set Level' , 'level' : level })
  35. url='http://%s/json.htm?' % (self.host) + f
  36. self._request(url)
  37.  
  38.  
  39. class Automate:
  40. def __init__( self ):
  41. pass
  42.  
  43. def activate_ha( self, trigger = None, prev_trigger = None, mode="normal" ):
  44. if ha_settings[ "ha_enable" ]:
  45. if ha_settings[ "ha_multi_trigger" ] and prev_trigger == trigger:
  46. pass
  47. elif mode != "thread":
  48. self.activate_on( trigger )
  49. else:
  50. thread = Thread( name='ha_trigger', target=self.activate_on, args=( trigger, ) )
  51. thread.start()
  52. prev_trigger = trigger
  53. return prev_trigger
  54.  
  55. def activate_on( self, trigger = None ):
  56. """
  57. Scripting to trigger almost anything(HA, other scripts, etc...) when videos start.
  58.  
  59. Usage:
  60. activate_on( "Movie" )
  61. will trigger code that is set under the Movie heading.
  62.  
  63. """
  64. if not trigger:
  65. utils.log( " - [ home_automation.py ] - No Trigger Sent, Returning", xbmc.LOGNOTICE )
  66. return
  67. utils.log( " - [ home_automation.py ] - activate_on( %s ) Triggered" % trigger, xbmc.LOGNOTICE )
  68. if trigger in triggers:
  69. utils.log( " - [ home_automation.py ] - Trigger %s" % trigger, xbmc.LOGNOTICE )
  70. # Script Start
  71. if trigger == "Script Start" and ha_settings[ "ha_script_start" ]:
  72. # place code below this line
  73. pass
  74. # Trivia Intro
  75. elif trigger == "Trivia Intro" and ha_settings[ "ha_trivia_intro" ]:
  76. # place code below this line
  77. pass
  78. # Trivia
  79. elif trigger == "Trivia" and ha_settings[ "ha_trivia_start" ]:
  80. # place code below this line
  81. pass
  82. # Trivia Outro
  83. elif trigger == "Trivia Outro" and ha_settings[ "ha_trivia_outro" ]:
  84. # place code below this line
  85. pass
  86. # Movie Theatre Intro
  87. elif trigger == "Movie Theater Intro" and ha_settings[ "ha_mte_intro" ]:
  88. # place code below this line
  89. pass
  90. # Coming Attractions Intro
  91. elif trigger == "Coming Attractions Intro" and ha_settings[ "ha_cav_intro" ]:
  92. # place code below this line
  93. pass
  94. # Trailer
  95. elif trigger == "Movie Trailer" and ha_settings[ "ha_trailer_start" ]:
  96. # place code below this line
  97. pass
  98. # Coming Attractions Outro
  99. elif trigger == "Coming Attractions Outro" and ha_settings[ "ha_cav_outro" ]:
  100. # place code below this line
  101. pass
  102. # Feature Presentation Intro
  103. elif trigger == "Feature Presentation Intro" and ha_settings[ "ha_fpv_intro" ]:
  104. # place code below this line
  105. pass
  106. #3D Intro
  107. elif trigger == "3D Intro" and ha_setting [ "ha_3d_intro" ]:
  108. # place code below this line
  109. pass
  110. #3D Trailers
  111. elif trigger == "3D Movie Trailer" and ha_setting [ "ha_3d_trailer" ]:
  112. # place code below this line
  113. pass
  114. #3D Outro
  115. elif trigger == "3D Outro" and ha_setting [ "ha_3d_outro" ]:
  116. # place code below this line
  117. pass
  118. # MPAA Rating
  119. elif trigger == "MPAA Rating" and ha_settings[ "ha_mpaa_rating" ]:
  120. # place code below this line
  121. pass
  122. # Countdown
  123. elif trigger == "Countdown" and ha_settings[ "ha_countdown_video" ]:
  124. # place code below this line
  125. pass
  126. # Audio Format
  127. elif trigger == "Audio Format" and ha_settings[ "ha_audio_format" ]:
  128. # place code below this line
  129. pass
  130. # Movie
  131. elif trigger == "Movie" and ha_settings[ "ha_movie" ]:
  132. # place code below this line
  133. p=None
  134. p=Domoticz()
  135. p.turn_off(2)
  136. p.turn_off(3)
  137. # Feature Presentation Outro
  138. elif trigger == "Feature Presentation Outro" and ha_settings[ "ha_fpv_outro" ]:
  139. # place code below this line
  140. pass
  141. # Movie Theatre Intro
  142. elif trigger == "Movie Theatre Outro" and ha_settings[ "ha_mte_outro" ]:
  143. # place code below this line
  144. pass
  145. # Intermission
  146. elif trigger == "Intermission" and ha_settings[ "ha_intermission" ]:
  147. # place code below this line
  148. pass
  149. # Script End
  150. elif trigger == "Script End" and ha_settings[ "ha_script_end" ]:
  151. # place code below this line
  152. pass
  153. # Paused
  154. elif trigger == "Pause" and ha_settings[ "ha_paused" ]:
  155. # place code below this line
  156. pass
  157. # Resumed
  158. elif trigger == "Resume" and ha_settings[ "ha_resumed" ]:
  159. # place code below this line
  160. pass
  161. else:
  162. utils.log( " - [ home_automation.py ] - Opps. Something happened", xbmc.LOGNOTICE )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement