Skip to content

Commit

Permalink
Merge pull request #23 from zim514/dev
Browse files Browse the repository at this point in the history
v0.7.10
  • Loading branch information
Snapcase authored Aug 20, 2019
2 parents 6764d74 + f5d5c9e commit 1faad53
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 56 deletions.
2 changes: 1 addition & 1 deletion script.service.hue/addon.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<addon id="script.service.hue" name="Hue Service" provider-name="zim514" version="0.7.9">
<addon id="script.service.hue" name="Hue Service" provider-name="zim514" version="0.7.10">
<requires>
<import addon="xbmc.python" version="2.26.0" />
<import addon="script.module.requests" version="2.22.0" />
Expand Down
18 changes: 10 additions & 8 deletions script.service.hue/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
kodilogging.config()
logger = logging.getLogger(globals.ADDONID)

if globals.DEBUG:
try:
import sys;sys.path.append("e:\dev\pysrc")
import pydevd
pydevd.settrace('localhost', stdoutToServer=False, stderrToServer=False, suspend=globals.REMOTE_DBG_SUSPEND,
trace_only_current_thread=False, overwrite_prev_trace=True, patch_multiprocessing=True)
except ImportError:
logger.exception("Kodi Hue Remote Debug Error: You must add org.python.pydev.debug.pysrc to your PYTHONPATH, or disable DEBUG")
#===============================================================================
# if globals.DEBUG:
# try:
# import sys;sys.path.append("e:\dev\pysrc")
# import pydevd
# pydevd.settrace('localhost', stdoutToServer=False, stderrToServer=False, suspend=globals.REMOTE_DBG_SUSPEND,
# trace_only_current_thread=False, overwrite_prev_trace=True, patch_multiprocessing=True)
# except ImportError:
# logger.exception("Kodi Hue Remote Debug Error: You must add org.python.pydev.debug.pysrc to your PYTHONPATH, or disable DEBUG")
#===============================================================================

logger.info("Starting default.py, version {}, Kodi: {}".format(globals.ADDONVERSION, globals.KODIVERSION ))
try:
Expand Down
11 changes: 5 additions & 6 deletions script.service.hue/resources/lib/AmbiGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from . import globals
from . import KodiGroup
from .KodiGroup import VIDEO,AUDIO,ALLMEDIA,STATE_IDLE,STATE_PAUSED,STATE_PLAYING
from .KodiGroup import VIDEO,AUDIO,ALLMEDIA,STATE_STOPPED,STATE_PAUSED,STATE_PLAYING
from . import kodiHue

from .globals import logger
Expand All @@ -25,6 +25,7 @@ def onAVStarted(self):
logger.info("Ambilight Settings. Colours: {}, Interval: {}, transitionTime: {}".format(self.numColors,self.updateInterval,self.transitionTime))
logger.info("Ambilight Settings. enabled: {}, forceOn: {}, setBrightness: {}, Brightness: {}".format(self.enabled,self.forceOn,self.setBrightness,self.brightness))
self.state = STATE_PLAYING

if self.isPlayingVideo():
self.videoInfoTag=self.getVideoInfoTag()
if self.enabled and self.checkActiveTime() and self.checkVideoActivation(self.videoInfoTag):
Expand All @@ -43,23 +44,22 @@ def onAVStarted(self):
except QhueException as e:
logger.debug("Ambi: Initial Hue call fail: {}".format(e))

self.state = STATE_PLAYING
self.ambiRunning.set()
ambiLoopThread=Thread(target=self._ambiLoop,name="_ambiLoop")
ambiLoopThread.daemon = True
ambiLoopThread.start()


def onPlayBackStopped(self):
logger.info("In ambiGroup[{}], onPlaybackStopped()".format(self.kgroupID))
self.state = STATE_STOPPED
self.ambiRunning.clear()
self.state = STATE_IDLE


def onPlayBackPaused(self):
logger.info("In ambiGroup[{}], onPlaybackPaused()".format(self.kgroupID))
self.ambiRunning.clear()
self.state = STATE_PAUSED

self.ambiRunning.clear()


def loadSettings(self):
Expand Down Expand Up @@ -200,7 +200,6 @@ def _updateHueRGB(self,r,g,b,light,transitionTime):
self.ambiLights[light].update(prevxy=xy)



def _updateHueXY(self,xy,light,transitionTime):
gamut=self.ambiLights[light].get('gamut')
prevxy=self.ambiLights[light].get('prevxy')
Expand Down
62 changes: 34 additions & 28 deletions script.service.hue/resources/lib/KodiGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@



STATE_IDLE = 0
STATE_STOPPED = 0
STATE_PLAYING = 1
STATE_PAUSED = 2

Expand Down Expand Up @@ -47,7 +47,7 @@ def loadSettings(self):

def setup(self,bridge,kgroupID,flash = False, mediaType=VIDEO):
if not hasattr(self,"state"):
self.state = STATE_IDLE
self.state = STATE_STOPPED
self.bridge = bridge
self.mediaType = mediaType

Expand All @@ -72,47 +72,54 @@ def flash(self):

def onAVStarted(self):
logger.info("In KodiGroup[{}], onPlaybackStarted. Group enabled: {},startBehavior: {} , isPlayingVideo: {}, isPlayingAudio: {}, self.mediaType: {},self.playbackType(): {}".format(self.kgroupID, self.enabled,self.startBehavior, self.isPlayingVideo(),self.isPlayingAudio(),self.mediaType,self.playbackType()))
#If video group, check video activation. Otherwise it's audio so ignore this and check other conditions.
if self.isPlayingVideo() and self.mediaType == VIDEO:
self.state = STATE_PLAYING
globals.lastMediaType = self.playbackType()

if self.isPlayingVideo() and self.mediaType == VIDEO: #If video group, check video activation. Otherwise it's audio so ignore this and check other conditions.
self.videoInfoTag=self.getVideoInfoTag()
if not self.checkVideoActivation(self.videoInfoTag):
return
else:
self.videoInfoTag = None
globals.lastMediaType = self.playbackType()


if self.enabled and self.checkActiveTime() and self.startBehavior and self.mediaType == self.playbackType():
try:
self.state = STATE_PLAYING
self.groupResource.action(scene=self.startScene)
except QhueException as e:
logger.error("onAVStarted: Hue call fail: {}".format(e))


def onPlayBackStopped(self):
logger.info("In KodiGroup[{}], onPlaybackStopped() , mediaType: {}, lastMediaType: {} ".format(self.kgroupID,self.mediaType,globals.lastMediaType))
if self.state == STATE_PLAYING or self.state==STATE_PAUSED:
if self.enabled and self.checkActiveTime() and self.stopBehavior and self.mediaType == globals.lastMediaType:
try:
xbmc.sleep(200) #sleep for any left over ambilight calls to complete first.
self.state = STATE_IDLE
self.groupResource.action(scene=self.stopScene)
except QhueException as e:
logger.error("onPlaybackStopped: Hue call fail: {}".format(e))
self.state = STATE_STOPPED

if self.mediaType == VIDEO and not self.checkVideoActivation(self.videoInfoTag):#If video group, check video activation. Otherwise it's audio so ignore this and check other conditions.
return

if self.enabled and self.checkActiveTime() and self.stopBehavior and self.mediaType == globals.lastMediaType:
try:
xbmc.sleep(200) #sleep for any left over ambilight calls to complete first.
self.groupResource.action(scene=self.stopScene)
except QhueException as e:
logger.error("onPlaybackStopped: Hue call fail: {}".format(e))


def onPlayBackPaused(self):
logger.info("In KodiGroup[{}], onPlaybackPaused() , isPlayingVideo: {}, isPlayingAudio: {}".format(self.kgroupID,self.isPlayingVideo(),self.isPlayingAudio()))
if self.state == STATE_PLAYING:
if self.enabled and self.checkActiveTime() and self.pauseBehavior and self.mediaType == self.playbackType():
self.lastMediaType = self.playbackType()
if self.mediaType == VIDEO and not self.checkVideoActivation(self.videoInfoTag):
return
try:
xbmc.sleep(200) #sleep for any left over ambilight calls to complete first.
self.state = STATE_PAUSED
self.groupResource.action(scene=self.pauseScene)
except QhueException as e:
logger.error("onPlaybackStopped: Hue call fail: {}".format(e))
self.state = STATE_PAUSED

if self.mediaType == VIDEO and not self.checkVideoActivation(self.videoInfoTag):#If video group, check video activation. Otherwise it's audio so ignore this and check other conditions.
return

if self.enabled and self.checkActiveTime() and self.pauseBehavior and self.mediaType == self.playbackType():
self.lastMediaType = self.playbackType()
try:
xbmc.sleep(200) #sleep for any left over ambilight calls to complete first.

self.groupResource.action(scene=self.pauseScene)
except QhueException as e:
logger.error("onPlaybackStopped: Hue call fail: {}".format(e))


def onPlayBackResumed(self):
Expand All @@ -132,12 +139,11 @@ def onPlayBackEnded(self):
def sunset(self):
logger.info("In KodiGroup[{}], in sunset()".format(self.kgroupID))

if self.state == STATE_PLAYING:
if self.state == STATE_PLAYING: #if Kodi is playing any file, start up
self.onAVStarted()
elif self.state == STATE_PAUSED:
self.onPlayBackPaused()
elif self.state == STATE_IDLE:
#self.onPlayBackStopped()
else:
#if not playing and sunset happens, probably should do nothing.
logger.debug("In KodiGroup[{}], in sunset(). playback stopped, doing nothing. ".format(self.kgroupID))

Expand Down
2 changes: 1 addition & 1 deletion script.service.hue/resources/lib/colorgram/colorgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _process(samples,pixels,x,y,top_two_bits):
samples[packed + 1] += g
samples[packed + 2] += b
samples[packed + 3] += 1
return samples
return

def pick_used(samples):
used = []
Expand Down
9 changes: 4 additions & 5 deletions script.service.hue/resources/lib/kodiHue.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ def configureScene(bridge,kGroupID,action):
#group0_startSceneID
globals.ADDON.setSettingString("group{}_{}SceneID".format(kGroupID, action),scene[0])
globals.ADDON.setSettingString("group{}_{}SceneName".format(kGroupID,action), scene[1])

globals.ADDON.openSettings()


Expand All @@ -288,10 +287,10 @@ def configureAmbiLights(bridge,kGroupID):
colorLights=[]
if lights is not None:
for L in lights:
gamut = getLightGamut(bridge, L)
if gamut == "A" or gamut== "B" or gamut == "C": #defaults to C if unknown model
lightNames.append(_getLightName(bridge,L))
colorLights.append(L)
#gamut = getLightGamut(bridge, L)
#if gamut == "A" or gamut== "B" or gamut == "C": #defaults to C if unknown model
lightNames.append(_getLightName(bridge,L))
colorLights.append(L)

globals.ADDON.setSettingString("group{}_Lights".format(kGroupID),','.join(colorLights))
globals.ADDON.setSettingString("group{}_LightNames".format(kGroupID),','.join(lightNames))
Expand Down
16 changes: 9 additions & 7 deletions script.service.hue/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
kodilogging.config()
logger = logging.getLogger(globals.ADDONID)

if globals.DEBUG:
try:
import pydevd
pydevd.settrace('localhost', stdoutToServer=True, stderrToServer=True, suspend=False,
trace_only_current_thread=False, overwrite_prev_trace=False, patch_multiprocessing=False)
except ImportError:
logger.exception("Kodi Hue Remote Debug Error: You must add org.python.pydev.debug.pysrc to your PYTHONPATH, or disable DEBUG")
#===============================================================================
# if globals.DEBUG:
# try:
# import pydevd
# pydevd.settrace('localhost', stdoutToServer=True, stderrToServer=True, suspend=False,
# trace_only_current_thread=False, overwrite_prev_trace=False, patch_multiprocessing=False)
# except ImportError:
# logger.exception("Kodi Hue Remote Debug Error: You must add org.python.pydev.debug.pysrc to your PYTHONPATH, or disable DEBUG")
#===============================================================================

logger.info("Starting service.py, version {}, Kodi: {}".format(globals.ADDONVERSION, globals.KODIVERSION))
try:
Expand Down

0 comments on commit 1faad53

Please sign in to comment.