Skip to content

Commit

Permalink
Merge pull request #7 from zim514/dev
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
Snapcase authored Jun 23, 2019
2 parents 3afba13 + ec9c264 commit 03127aa
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 332 deletions.
16 changes: 9 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.pyc
*.pyo
/.pydevproject
/.project
/.settings/
/.idea/
testing.py
*.pyc
*.pyo
/.pydevproject
/.project
/.settings
/.idea
testing.py
*.bak
/check.bat
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ deploy:
file_glob: true
file: $RELEASE_ZIP
skip_cleanup: true
prerelease: false
prerelease: true
draft: false
on:
all_branches: true
Expand Down
28 changes: 17 additions & 11 deletions script.service.hue/addon.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<addon id="script.service.hue" name="Hue Service" provider-name="zim514" version="0.2.7">
<addon id="script.service.hue" name="Hue Service" provider-name="zim514" version="0.3.0">

<requires>
<import addon="xbmc.python" version="2.26.0" />
<import addon="script.module.requests" version="2.22.0"/>
<import addon="script.module.requests" version="2.22.0" />
<import addon="script.module.future" version="0.16.0.4" />
<import addon="script.module.kodi-six" version="0.1.0" />
</requires>

<extension point="xbmc.service" name="service.hue" library="service.py">
</extension>
<extension point="xbmc.python.script" library="default.py">
Expand All @@ -14,18 +16,22 @@

<extension point="xbmc.addon.metadata">

<summary lang="en_GB">Philips Hue Service</summary>
<summary lang="en_GB">Automate Hue lights with Kodi playback</summary>
<description lang="en_GB">Automate your Philips Hue lights with Kodi. Create multi-room scenes that run when you Play, Pause or Stop media playback. Create and delete multi-room scenes from add-on settings then select which to apply for different Playback events. Can use Hue's sunrise and sunset times to automatically disable the service during daytime and turn on the lights at sunset during playback.</description>
<disclaimer lang="en_GB">Automate Hue with Kodi</disclaimer>
<disclaimer lang="en_GB">Automate Hue lights with Kodi playback</disclaimer>
<platform>all</platform>
<license>MIT License</license>
<news>
v0.2.7:
- Support optional logging to external file
- Removed half translated French
v0.2.6:
- Improve logging system
</news>
v0.3.0:
- Support different behaviours for different media types
v0.2.8:
- Python 2/3 support
v0.2.7:
- Support optional logging to external file
- Removed half translated French
v0.2.6:
- Improve logging system
</news>
<assets>
<icon>resources/icons/icon.png</icon>
<fanart>resources/icons/fanart.jpg</fanart>
Expand Down
2 changes: 1 addition & 1 deletion script.service.hue/default.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
import logging

from resources.lib import core
from resources.lib import globals
from resources.lib import kodilogging
from resources.lib import core

kodilogging.config()
logger = logging.getLogger(globals.ADDONID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ msgid "Light Groups"
msgstr "Light Groups"

msgctxt "#32100"
msgid "Player Actions"
msgstr "Player Actions"
msgid "Video Actions"
msgstr "Video Actions"

msgctxt "#32102"
msgid "Audio Actions"
msgstr "Audio Actions"

msgctxt "#32201"
msgid "Start/Resume Video"
msgstr "Start/Resume Video"
msgid "Start/Resume"
msgstr "Start/Resume"

msgctxt "#32202"
msgid "Pause Video"
msgstr "Pause Video"
msgid "Pause"
msgstr "Pause"

msgctxt "#32203"
msgid "Stop Video"
msgstr "Stop Video"
msgid "Stop"
msgstr "Stop"

msgctxt "#32510"
msgid "Scene Name"
Expand Down
65 changes: 40 additions & 25 deletions script.service.hue/resources/lib/KodiGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
'''
import logging
from logging import getLogger

import xbmc

from . import globals
#from . import kodilogging

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


BEHAVIOR_NOTHING = 0
BEHAVIOR_ADJUST = 1
BEHAVIOR_OFF = 2
Expand All @@ -22,10 +20,11 @@
STATE_PLAYING = 1
STATE_PAUSED = 2

state = 0
VIDEO=1
AUDIO=2


logger = logging.getLogger(globals.ADDONID)
logger = getLogger(globals.ADDONID)


class KodiGroup(xbmc.Player):
Expand All @@ -38,7 +37,6 @@ def readSettings(self):
self.fadeTime=get_setting_as_int("group{}_fadeTime".format(self.kgroupID)) * 10 #Stored as seconds, but Hue API expects multiples of 100ms.
self.forceOn=get_setting_as_bool("group{}_forceOn".format(self.kgroupID))


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

Expand All @@ -49,9 +47,9 @@ def readSettings(self):
self.stopScene=get_setting("group{}_stopSceneID".format(self.kgroupID))


def setup(self,bridge,kgroupID,flash = False):
def setup(self,bridge,kgroupID,flash = False, mediaType=VIDEO):
self.bridge = bridge

self.mediaType = mediaType

self.lights = bridge.lights
self.kgroupID=kgroupID
Expand All @@ -67,7 +65,6 @@ def setup(self,bridge,kgroupID,flash = False):
self.flash()



def saveInitialState(self):
#TODO: Get scene lights to save initial state
logger.debug("In KodiGroup[{}], save initial state".format(self.kgroupID))
Expand Down Expand Up @@ -102,29 +99,31 @@ def flash(self):
self.groupResource.action(alert="select")

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

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

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

if self.startBehavior == BEHAVIOR_ADJUST:
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() ".format(self.kgroupID))
if self.enabled and not (globals.daylightDisable == globals.daylight):
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:
try:
self.groupResource.action(scene=self.stopScene)
Expand All @@ -141,10 +140,10 @@ def onPlayBackStopped(self):

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

if self.enabled and not (globals.daylightDisable == globals.daylight):
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:
try:
self.groupResource.action(scene=self.pauseScene)
Expand All @@ -169,12 +168,12 @@ def onPlayBackError(self):
def onPlayBackEnded(self):
logger.info("In KodiGroup[{}], onPlaybackEnded()".format(self.kgroupID))
self.onPlayBackStopped()

def sunset(self):
logger.info("In KodiGroup[{}], in sunset()".format(self.kgroupID))
previousForce = self.forceOn
self.forceOn = True

if self.state == STATE_PLAYING:
self.onPlayBackStarted()
elif self.state == STATE_PAUSED:
Expand All @@ -186,3 +185,19 @@ def sunset(self):


self.forceOn = previousForce


def playbackType(self):
if self.isPlayingVideo():
mediaType=VIDEO
elif self.isPlayingAudio():
mediaType=AUDIO
return mediaType


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

def onPlayBackStarted(self, saveInitial=False):
pass
Loading

0 comments on commit 03127aa

Please sign in to comment.