Skip to content

Commit

Permalink
Merge pull request #9 from zim514/dev
Browse files Browse the repository at this point in the history
v0.3.5
  • Loading branch information
Snapcase authored Jun 27, 2019
2 parents 2ff6467 + dfffc3f commit 2fcd829
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 81 deletions.
8 changes: 5 additions & 3 deletions 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.3.4">
<addon id="script.service.hue" name="Hue Service" provider-name="zim514" version="0.3.5">

<requires>
<import addon="xbmc.python" version="2.26.0" />
Expand All @@ -22,9 +22,11 @@
<platform>all</platform>
<license>MIT License</license>
<news>
v0.3.4:
v0.3.5:
- Make media type detection more reliable
- Remove unused settings
- Remove deprecated settings
- Change some settings to booleans
- Fix broken daytime settings
v0.3.2:
- Crash fix
v0.3.1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ msgid "Stop"
msgstr "Stop"

msgctxt "#32510"
msgid "Scene Name"
msgstr "Scene Name"
msgid "Scene Name:"
msgstr "Scene Name:"

msgctxt "#32511"
msgid "Scene ID"
msgstr "Scene ID"

msgctxt "#32512"
msgid "Select Scene"
msgstr "Select Scene"
msgid "Select Scene..."
msgstr "Select Scene..."

msgctxt "#1200"
msgid "Bridge"
Expand Down
88 changes: 33 additions & 55 deletions script.service.hue/resources/lib/KodiGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import xbmc
from . import globals

from .kodiutils import get_setting, get_setting_as_bool, get_setting_as_int
from .kodiutils import get_setting, get_setting_as_bool
from .qhue import QhueException


BEHAVIOR_NOTHING = 0
BEHAVIOR_ADJUST = 1
BEHAVIOR_OFF = 2
Expand All @@ -35,13 +36,13 @@ def readSettings(self):

self.enabled=get_setting_as_bool("group{}_enabled".format(self.kgroupID))

self.startBehavior=get_setting_as_int("group{}_startBehavior".format(self.kgroupID))
self.startBehavior=get_setting_as_bool("group{}_startBehavior".format(self.kgroupID))
self.startScene=get_setting("group{}_startSceneID".format(self.kgroupID))

self.pauseBehavior=get_setting_as_int("group{}_pauseBehavior".format(self.kgroupID))
self.pauseBehavior=get_setting_as_bool("group{}_pauseBehavior".format(self.kgroupID))
self.pauseScene=get_setting("group{}_pauseSceneID".format(self.kgroupID))

self.stopBehavior=get_setting_as_int("group{}_stopBehavior".format(self.kgroupID))
self.stopBehavior=get_setting_as_bool("group{}_stopBehavior".format(self.kgroupID))
self.stopScene=get_setting("group{}_stopSceneID".format(self.kgroupID))


Expand All @@ -57,14 +58,15 @@ def setup(self,bridge,kgroupID,flash = False, mediaType=VIDEO):
self.groupResource=bridge.groups[0]
#TODO: Get scene lights to save initial state
self.lightIDs=self.groupResource()["lights"]
self.saveInitialState()


if flash:
self.flash()


def saveInitialState(self):
def _saveInitialState(self):
#TODO: Get scene lights to save initial state
#This method no longer works
logger.debug("In KodiGroup[{}], save initial state".format(self.kgroupID))
initialState = {}
lights = self.lights
Expand All @@ -76,7 +78,8 @@ def saveInitialState(self):

self.initialState=initialState

def applyInitialState(self):
def _applyInitialState(self):
#Deprecated with new scene support
logger.debug("In KodiGroup[{}], apply initial state".format(self.kgroupID))
initialState = self.initialState
lights = self.lights
Expand All @@ -96,68 +99,50 @@ def flash(self):
logger.debug("in KodiGroup Flash")
self.groupResource.action(alert="select")

def onAVStarted(self, saveInitial=False):
logger.info("In KodiGroup[{}], onPlaybackStarted. Group enabled: {}, , isPlayingVideo: {}, isPlayingAudio: {}".format(self.kgroupID, self.enabled, self.isPlayingVideo(),self.isPlayingAudio()))

self.state = STATE_PLAYING
globals.lastMediaType = self.playbackType()
if saveInitial:
self.saveInitialState()

if self.enabled and self.mediaType == self.playbackType() and not (globals.daylightDisable == globals.daylight) :

if self.startBehavior == BEHAVIOR_ADJUST:
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 globals.daylightDisable and globals.daylight:
return
else:
self.state = STATE_PLAYING
globals.lastMediaType = self.playbackType()

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

elif self.startBehavior == BEHAVIOR_OFF:
self.groupResource.action(on=False)


def onPlayBackStopped(self):
self.state = STATE_IDLE
logger.info("In KodiGroup[{}], onPlaybackStopped() , isPlayingVideo: {}, isPlayingAudio: {} ".format(self.kgroupID,self.isPlayingVideo(),self.isPlayingAudio()))

if self.enabled and self.mediaType == globals.lastMediaType and not (globals.daylightDisable == globals.daylight):

if self.stopBehavior == BEHAVIOR_ADJUST:
logger.info("In KodiGroup[{}], onPlaybackStopped() , mediaType: {}, lastMediaType: {} ".format(self.kgroupID,self.mediaType,globals.lastMediaType))
if globals.daylightDisable and globals.daylight:
return
else:
self.state = STATE_IDLE
if self.enabled and self.stopBehavior and self.mediaType == globals.lastMediaType:
try:
self.groupResource.action(scene=self.stopScene)
except QhueException as e:
logger.error("onPlaybackStopped: Hue call fail: {}".format(e))


elif self.stopBehavior == BEHAVIOR_OFF:
self.groupResource.action(on=False)

elif self.stopBehavior == BEHAVIOR_INITIAL:
self.applyInitialState()


def onPlayBackPaused(self):
self.state = STATE_PAUSED
logger.info("In KodiGroup[{}], onPlaybackPaused() , isPlayingVideo: {}, isPlayingAudio: {}".format(self.kgroupID,self.isPlayingVideo(),self.isPlayingAudio()))

if self.enabled and self.mediaType == self.playbackType() and not (globals.daylightDisable == globals.daylight):
self.lastMediaType = self.playbackType()
if self.pauseBehavior == BEHAVIOR_ADJUST:
if globals.daylightDisable and globals.daylight:
return
else:
self.state = STATE_PAUSED
if self.enabled and self.pauseBehavior and self.mediaType == self.playbackType():
self.lastMediaType = self.playbackType()
try:
self.groupResource.action(scene=self.pauseScene)
except QhueException as e:
logger.error("onPlaybackStopped: Hue call fail: {}".format(e))

elif self.startBehavior == BEHAVIOR_OFF:
self.groupResource.action(on=False)

elif self.startBehavior == BEHAVIOR_INITIAL:
self.applyInitialState()


def onPlayBackResumed(self):
logger.info("In KodiGroup[{}], onPlaybackResumed()".format(self.kgroupID))
self.onPlayBackStarted(saveInitial=False)
self.onAVStarted()

def onPlayBackError(self):
logger.info("In KodiGroup[{}], onPlaybackError()".format(self.kgroupID))
Expand All @@ -171,7 +156,7 @@ def sunset(self):
logger.info("In KodiGroup[{}], in sunset()".format(self.kgroupID))

if self.state == STATE_PLAYING:
self.onPlayBackStarted()
self.onAVStarted()
elif self.state == STATE_PAUSED:
self.onPlayBackPaused()
elif self.state == STATE_IDLE:
Expand All @@ -188,10 +173,3 @@ def playbackType(self):
mediaType=None
return mediaType


class KodiVideoGroup(KodiGroup):
def __init__(self):
super(KodiVideoGroup,self).__init__()

def onPlayBackStarted(self, saveInitial=False):
pass
36 changes: 18 additions & 18 deletions script.service.hue/resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,28 @@
<!-- Group playback start setting -->
<!-- Visible when group behaviour is enabled-->
<setting type="lsep" label="32201" visible="eq(-1,1)" />
<setting id="group0_startBehavior" type="select" label="6201" lvalues="6202|6210" visible="eq(-2,true)" />
<setting id="group0_startBehavior" type="bool" label="6201" visible="eq(-2,true)" />
<!--HERE-->
<setting id="group0_startSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,0,start)" visible="eq(-1,1) + eq(-3,true)" option="close" />
<setting id="group0_startSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,1) + eq(-4,true)" />
<setting id="group0_startSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,0,start)" visible="eq(-1,true) + eq(-3,true)" option="close" />
<setting id="group0_startSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,true) + eq(-4,true)" />
<setting id="group0_startSceneID" type="text" label="32511" default="-1" subsetting="true" enable="false" visible="false" />

<!-- Group playback pause setting -->
<!-- Visible when group behaviour is enabled-->
<setting type="lsep" label="32202" visible="eq(-6,1)"/>
<setting id="group0_pauseBehavior" type="select" label="6201" lvalues="6202|6210" visible="eq(-7,true)" />
<setting id="group0_pauseBehavior" type="bool" label="6201" visible="eq(-7,true)" />
<!-- Visible when group_event_start is Adjust (1) + group_behavior is Adjust (1) -->
<setting id="group0_pauseSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,0,pause)" visible="eq(-1,1) + eq(-8,true)" option="close"/>
<setting id="group0_pauseSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,1) + eq(-9,true)" />
<setting id="group0_pauseSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,0,pause)" visible="eq(-1,true) + eq(-8,true)" option="close"/>
<setting id="group0_pauseSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,true) + eq(-9,true)" />
<setting id="group0_pauseSceneID" type="text" label="32511" default="-1" subsetting="true" enable="false" visible="false" />

<!-- Group playback stop setting -->
<!-- Visible when group behaviour is enabled-->
<setting type="lsep" label="32203" visible="eq(-11,1)"/>
<setting id="group0_stopBehavior" type="select" label="6201" lvalues="6202|6210" visible="eq(-12,true)"/>
<setting id="group0_stopBehavior" type="bool" label="6201" visible="eq(-12,true)"/>
<!-- Visible when group_event_start is Adjust (1) + group_behavior is Adjust (1) -->
<setting id="group0_stopSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,0,stop)" visible="eq(-1,1) + eq(-13,true)" option="close"/>
<setting id="group0_stopSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,1) + eq(-14,true)" />
<setting id="group0_stopSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,0,stop)" visible="eq(-1,true) + eq(-13,true)" option="close"/>
<setting id="group0_stopSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,true) + eq(-14,true)" />
<setting id="group0_stopSceneID" type="text" label="32511" default="-1" subsetting="true" enable="false" visible="false" />

</category>
Expand All @@ -72,28 +72,28 @@
<!-- Group playback start setting -->
<!-- Visible when group behaviour is enabled-->
<setting type="lsep" label="32201" visible="eq(-1,1)" />
<setting id="group1_startBehavior" type="select" label="6201" lvalues="6202|6210" visible="eq(-2,true)" />
<setting id="group1_startBehavior" type="bool" label="6201" visible="eq(-2,true)" />
<!--HERE-->
<setting id="group1_startSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,1,start)" visible="eq(-1,1) + eq(-3,true)" option="close" />
<setting id="group1_startSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,1) + eq(-4,true)" />
<setting id="group1_startSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,1,start)" visible="eq(-1,true) + eq(-3,true)" option="close" />
<setting id="group1_startSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,true) + eq(-4,true)" />
<setting id="group1_startSceneID" type="text" label="32511" default="-1" subsetting="true" enable="false" visible="false" />

<!-- Group playback pause setting -->
<!-- Visible when group behaviour is enabled-->
<setting type="lsep" label="32202" visible="eq(-6,1)"/>
<setting id="group1_pauseBehavior" type="select" label="6201" lvalues="6202|6210" visible="eq(-7,true)" />
<setting id="group1_pauseBehavior" type="bool" label="6201" visible="eq(-7,true)" />
<!-- Visible when group_event_start is Adjust (1) + group_behavior is Adjust (1) -->
<setting id="group1_pauseSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,1,pause)" visible="eq(-1,1) + eq(-8,true)" option="close"/>
<setting id="group1_pauseSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,1) + eq(-9,true)" />
<setting id="group1_pauseSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,1,pause)" visible="eq(-1,true) + eq(-8,true)" option="close"/>
<setting id="group1_pauseSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,true) + eq(-9,true)" />
<setting id="group1_pauseSceneID" type="text" label="32511" default="-1" subsetting="true" enable="false" visible="false" />

<!-- Group playback stop setting -->
<!-- Visible when group behaviour is enabled-->
<setting type="lsep" label="32203" visible="eq(-11,1)"/>
<setting id="group1_stopBehavior" type="select" label="6201" lvalues="6202|6210" visible="eq(-12,true)"/>
<setting id="group1_stopBehavior" type="bool" label="6201" visible="eq(-12,true)"/>
<!-- Visible when group_event_start is Adjust (1) + group_behavior is Adjust (1) -->
<setting id="group1_stopSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,1,stop)" visible="eq(-1,1) + eq(-13,true)" option="close"/>
<setting id="group1_stopSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,1) + eq(-14,true)" />
<setting id="group1_stopSelectScene" type="action" label="32512" subsetting="true" action="RunScript(script.service.hue,sceneSelect,1,stop)" visible="eq(-1,true) + eq(-13,true)" option="close"/>
<setting id="group1_stopSceneName" type="text" label="32510" default="Not selected" subsetting="true" enable="false" visible="eq(-2,true) + eq(-14,true)" />
<setting id="group1_stopSceneID" type="text" label="32511" default="-1" subsetting="true" enable="false" visible="false" />

</category>
Expand Down
2 changes: 1 addition & 1 deletion script.service.hue/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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=True, overwrite_prev_trace=True, patch_multiprocessing=True)
trace_only_current_thread=False, overwrite_prev_trace=True, patch_multiprocessing=True)

except ImportError:
logger.critical("Kodi Hue Remote Debug Error: You must add org.python.pydev.debug.pysrc to your PYTHONPATH, or disable DEBUG")
Expand Down

0 comments on commit 2fcd829

Please sign in to comment.