From c0da477d0eace137fcd6e1d6ebd093a46f6aba2d Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 14:41:48 -0400 Subject: [PATCH 01/13] futurize, optimize imports, & reformat code --- script.service.hue/addon.xml | 22 +++++++++++-------- script.service.hue/default.py | 2 +- script.service.hue/resources/lib/KodiGroup.py | 3 +-- script.service.hue/resources/lib/core.py | 4 +--- script.service.hue/resources/lib/kodiHue.py | 15 +++++-------- .../resources/lib/kodilogging.py | 6 ++--- script.service.hue/resources/lib/kodiutils.py | 7 ++---- script.service.hue/resources/lib/language.py | 6 ++++- script.service.hue/resources/lib/qhue/qhue.py | 12 +++++----- script.service.hue/service.py | 2 +- 10 files changed, 39 insertions(+), 40 deletions(-) diff --git a/script.service.hue/addon.xml b/script.service.hue/addon.xml index e6a74ad8..9c6f11b2 100644 --- a/script.service.hue/addon.xml +++ b/script.service.hue/addon.xml @@ -1,8 +1,10 @@ - + + + @@ -14,18 +16,20 @@ - Philips Hue Service + Automate Hue lights with Kodi playback 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. - Automate Hue with Kodi + Automate Hue lights with Kodi playback all MIT License - v0.2.7: - - Support optional logging to external file - - Removed half translated French - v0.2.6: - - Improve logging system - +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 + resources/icons/icon.png resources/icons/fanart.jpg diff --git a/script.service.hue/default.py b/script.service.hue/default.py index 5bde5a9c..08947c9d 100644 --- a/script.service.hue/default.py +++ b/script.service.hue/default.py @@ -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) diff --git a/script.service.hue/resources/lib/KodiGroup.py b/script.service.hue/resources/lib/KodiGroup.py index a6beda9a..c3289d43 100644 --- a/script.service.hue/resources/lib/KodiGroup.py +++ b/script.service.hue/resources/lib/KodiGroup.py @@ -8,11 +8,10 @@ import xbmc from . import globals -#from . import kodilogging +# 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 diff --git a/script.service.hue/resources/lib/core.py b/script.service.hue/resources/lib/core.py index bd42e3a2..a0bfa5ec 100644 --- a/script.service.hue/resources/lib/core.py +++ b/script.service.hue/resources/lib/core.py @@ -3,14 +3,12 @@ import logging import sys -import xbmc - import xbmcgui -from .language import get_string as _ from . import globals from . import kodiHue from . import kodiutils +from .language import get_string as _ logger = logging.getLogger(globals.ADDONID) diff --git a/script.service.hue/resources/lib/kodiHue.py b/script.service.hue/resources/lib/kodiHue.py index f66db06b..85477249 100644 --- a/script.service.hue/resources/lib/kodiHue.py +++ b/script.service.hue/resources/lib/kodiHue.py @@ -5,23 +5,20 @@ ''' import logging -import requests +from builtins import str from socket import getfqdn - +import requests import xbmc - import xbmcgui -from xbmcgui import NOTIFICATION_ERROR,NOTIFICATION_WARNING, NOTIFICATION_INFO +from xbmcgui import NOTIFICATION_ERROR, NOTIFICATION_INFO +from . import KodiGroup from . import globals from . import kodiutils -from . import KodiGroup from . import qhue from .language import get_string as _ - - logger = logging.getLogger(globals.ADDONID) def createHueGroup(bridge): @@ -42,7 +39,7 @@ def deleteHueGroup(bridge): logger.debug("In kodiHue deleteHueGroup") group = selectHueGroup(bridge) if group: - confirm = xbmcgui.Dialog().yesno(_("Delete Hue Group"), _("Are you sure you want to delete this group: "), unicode(group[1])) + confirm = xbmcgui.Dialog().yesno(_("Delete Hue Group"), _("Are you sure you want to delete this group: "), str(group[1])) if group and confirm: groups=bridge.groups res=groups[group[0]](http_method='delete') @@ -80,7 +77,7 @@ def deleteHueScene(bridge): logger.debug("In kodiHue deleteHueScene") scene = selectHueScene(bridge) if scene: - confirm = xbmcgui.Dialog().yesno(_("Delete Hue Scene"), _("Are you sure you want to delete this scene: "), unicode(scene[1])) + confirm = xbmcgui.Dialog().yesno(_("Delete Hue Scene"), _("Are you sure you want to delete this scene: "), str(scene[1])) if scene and confirm: scenes=bridge.scenes res=scenes[scene[0]](http_method='delete') diff --git a/script.service.hue/resources/lib/kodilogging.py b/script.service.hue/resources/lib/kodilogging.py index f861005d..e089d4d7 100644 --- a/script.service.hue/resources/lib/kodilogging.py +++ b/script.service.hue/resources/lib/kodilogging.py @@ -2,17 +2,15 @@ from __future__ import unicode_literals +import logging import os +from builtins import str -import logging import xbmc from resources.lib import globals from resources.lib.kodiutils import get_setting_as_bool - - - prefix = b"[{}]".format(globals.ADDONID) formatter = logging.Formatter(prefix + b'[%(module)s][%(funcName)s](%(lineno)d): %(message)s') fileFormatter = logging.Formatter(b'%(asctime)s %(levelname)s [%(module)s][%(funcName)s](%(lineno)d): %(message)s') diff --git a/script.service.hue/resources/lib/kodiutils.py b/script.service.hue/resources/lib/kodiutils.py index 8711cf1a..992a3e88 100644 --- a/script.service.hue/resources/lib/kodiutils.py +++ b/script.service.hue/resources/lib/kodiutils.py @@ -1,13 +1,10 @@ # -*- coding: utf-8 -*- import logging +from builtins import str -import xbmcgui import xbmc -import os -from datetime import datetime -from logging.handlers import RotatingFileHandler - +import xbmcgui from . import globals diff --git a/script.service.hue/resources/lib/language.py b/script.service.hue/resources/lib/language.py index 93de3e43..d902cad3 100644 --- a/script.service.hue/resources/lib/language.py +++ b/script.service.hue/resources/lib/language.py @@ -1,8 +1,12 @@ #! /usr/bin/python +from __future__ import absolute_import +from __future__ import print_function + import os import sys +from builtins import range -from globals import STRDEBUG +from .globals import STRDEBUG ######### Based upon: https://raw.githubusercontent.com/Quihico/handy.stuff/master/language.py ######### https://forum.kodi.tv/showthread.php?tid=268081&highlight=generate+.po+python+gettext diff --git a/script.service.hue/resources/lib/qhue/qhue.py b/script.service.hue/resources/lib/qhue/qhue.py index 999ec0ae..d369c242 100644 --- a/script.service.hue/resources/lib/qhue/qhue.py +++ b/script.service.hue/resources/lib/qhue/qhue.py @@ -3,12 +3,14 @@ import json import re -from socket import getfqdn import sys +from builtins import input +from builtins import object +from builtins import str +from socket import getfqdn import requests - # for hostname retrieval for registering with the bridge __all__ = ('Bridge', 'QhueException', 'create_new_username') @@ -41,7 +43,7 @@ def __call__(self, *args, **kwargs): # then send them as parameters to the bridge. This allows for # "escaping" of keywords that might conflict with Python syntax # or with the specially-handled keyword "http_method". - kwargs = {(k[:-1] if k.endswith('_') else k): v for k, v in kwargs.items()} + kwargs = {(k[:-1] if k.endswith('_') else k): v for k, v in list(kwargs.items())} if http_method == 'put': r = requests.put(url, data=json.dumps(kwargs, default=list), timeout=self.timeout) elif http_method == 'post': @@ -89,9 +91,9 @@ def create_new_username(ip, devicetype=None, timeout=_DEFAULT_TIMEOUT): prompt = "Press the Bridge button, then press Return: " # Deal with one of the sillier python3 changes if sys.version_info.major == 2: - _ = raw_input(prompt) + _ = eval(input(prompt)) else: - _ = input(prompt) + _ = eval(input(prompt)) if devicetype is None: devicetype = "qhue#{}".format(getfqdn()) diff --git a/script.service.hue/service.py b/script.service.hue/service.py index 664c63b3..fd448c2f 100644 --- a/script.service.hue/service.py +++ b/script.service.hue/service.py @@ -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) From 209a60d74d0a958f60a3da876539a38e0be35999 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 15:16:23 -0400 Subject: [PATCH 02/13] futurize 2->3 bugfixing --- .gitignore | 4 +- script.service.hue/resources/lib/KodiGroup.py | 7 +- script.service.hue/resources/lib/core.py | 65 +++++++++---------- script.service.hue/resources/lib/globals.py | 31 ++++----- script.service.hue/resources/lib/kodiHue.py | 8 +-- .../resources/lib/kodilogging.py | 4 +- 6 files changed, 57 insertions(+), 62 deletions(-) diff --git a/.gitignore b/.gitignore index 41966326..1e2831ff 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ *.pyo /.pydevproject /.project -/.settings/ -/.idea/ +/.settings +/.idea testing.py \ No newline at end of file diff --git a/script.service.hue/resources/lib/KodiGroup.py b/script.service.hue/resources/lib/KodiGroup.py index c3289d43..c54010e5 100644 --- a/script.service.hue/resources/lib/KodiGroup.py +++ b/script.service.hue/resources/lib/KodiGroup.py @@ -3,12 +3,11 @@ ''' -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 @@ -24,7 +23,7 @@ state = 0 -logger = logging.getLogger(globals.ADDONID) +logger = getLogger(globals.ADDONID) class KodiGroup(xbmc.Player): diff --git a/script.service.hue/resources/lib/core.py b/script.service.hue/resources/lib/core.py index a0bfa5ec..1efc6db0 100644 --- a/script.service.hue/resources/lib/core.py +++ b/script.service.hue/resources/lib/core.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -import logging import sys +from logging import getLogger import xbmcgui @@ -10,10 +10,10 @@ from . import kodiutils from .language import get_string as _ -logger = logging.getLogger(globals.ADDONID) +logger = getLogger(globals.ADDONID) def menu(): - + monitor = kodiHue.HueMonitor() if len(sys.argv) >1: @@ -22,20 +22,18 @@ def menu(): args = "" logger.info("menu started, version: {}, Arguments: {}".format(globals.ADDON.getAddonInfo('version'), args)) - - if args == "discover": logger.debug("Started with Discovery") bridge = kodiHue.bridgeDiscover(monitor) - if bridge: + if bridge is not None: logger.debug("Found bridge, starting service.") service() #restart service elif args == "createHueGroup": logger.debug("Started with createGroup") bridge = kodiHue.connectBridge(monitor, silent=True) - if bridge: + if bridge is not None: kodiHue.createHueGroup(bridge) else: logger.debug("Menu() createGroup: No bridge") @@ -44,7 +42,7 @@ def menu(): elif args == "deleteHueGroup": logger.debug("Started with deleteGroup.") bridge = kodiHue.connectBridge(monitor, silent=True) # don't rediscover, proceed silently - if bridge: + if bridge is not None: kodiHue.deleteHueGroup(bridge) else: logger.debug("No bridge found. deleteGroup cancelled.") @@ -53,70 +51,70 @@ def menu(): elif args.startswith("groupSelect"): kgroup = args.split("=", 1)[1] logger.debug("Started with groupSelect. args: {}, kgroup: {}".format(args, kgroup)) - + bridge = kodiHue.connectBridge(monitor, silent=True) # don't rediscover, proceed silently - if bridge: + if bridge is not None: kodiHue.configureGroup(bridge, kgroup) else: logger.debug("No bridge found. Select group cancelled.") xbmcgui.Dialog().notification(_("Hue Service"), _("Check Hue Bridge configuration")) - + elif args == "createHueScene": logger.debug("Started with {}".format(args)) bridge = kodiHue.connectBridge(monitor, silent=True) # don't rediscover, proceed silently - if bridge: + if bridge is not None: kodiHue.createHueScene(bridge) else: logger.debug("No bridge found. createHueScene cancelled.") xbmcgui.Dialog().notification(_("Hue Service"), _("Check Hue Bridge configuration")) - + elif args == "deleteHueScene": logger.debug("Started with {}".format(args)) bridge = kodiHue.connectBridge(monitor, silent=True) # don't rediscover, proceed silently - if bridge: + if bridge is not None: kodiHue.deleteHueScene(bridge) else: logger.debug("No bridge found. deleteHueScene cancelled.") xbmcgui.Dialog().notification(_("Hue Service"), _("Check Hue Bridge configuration")) - + elif args == "sceneSelect": # sceneSelect=kgroup,action / sceneSelect=0,play kgroup = sys.argv[2] action = sys.argv[3] logger.debug("Started with {}, kgroup: {}, kaction: {}".format(args, kgroup, action)) - + bridge = kodiHue.connectBridge(monitor, silent=True) # don't rediscover, proceed silently - if bridge: + if bridge is not None: kodiHue.configureScene(bridge, kgroup, action) - + #TODO: save selection else: logger.debug("No bridge found. sceneSelect cancelled.") xbmcgui.Dialog().notification(_("Hue Service"), _("Check Hue Bridge configuration")) - + else: #bridge = kodiHue.connectBridge(monitor, silent=True) #sceneUI=CreateSceneUI(bridge) #del sceneUI #No command globals.ADDON.openSettings() - + return - + def service(): logger.info("service started, version: {}".format(globals.ADDON.getAddonInfo('version'))) - - + + monitor = kodiHue.HueMonitor() - + initialFlash = kodiutils.get_setting_as_bool("initialFlash") globals.forceOnSunset = kodiutils.get_setting_as_bool("forceOnSunset") globals.daylightDisable = kodiutils.get_setting_as_bool("daylightDisable") bridge = kodiHue.connectBridge(monitor,silent=False) - if bridge: + if bridge is not None: globals.settingsChanged = False globals.daylight = kodiHue.getDaylight(bridge) kgroups = kodiHue.setupGroups(bridge,initialFlash) @@ -125,15 +123,15 @@ def service(): # #Ready to go! Start running until Kodi exit. logger.debug('Main service loop starting') while globals.connected and not monitor.abortRequested(): - + if globals.settingsChanged: reloadFlash = kodiutils.get_setting_as_bool("reloadFlash") globals.forceOnSunset = kodiutils.get_setting_as_bool("forceOnSunset") globals.daylightDisable = kodiutils.get_setting_as_bool("daylightDisable") - + kgroups = kodiHue.setupGroups(bridge, reloadFlash) globals.settingsChanged = False - + timer = timer + 1 if timer > 59: try: @@ -141,7 +139,7 @@ def service(): #logger.debug('Daylight check: current: {}, previous: {}'.format(globals.daylight, previousDaylight)) except Exception as error: logger.error('Get daylight exception: {}'.format(error)) - + if globals.daylight != previousDaylight : @@ -149,16 +147,15 @@ def service(): globals.daylight = kodiHue.getDaylight(bridge) if not globals.daylight: kodiHue.sunset(bridge,kgroups) - - + + timer = 1 - + monitor.waitForAbort(1) logger.debug('Process exiting...') return - + else: logger.debug('No connected bridge, exiting...') return - \ No newline at end of file diff --git a/script.service.hue/resources/lib/globals.py b/script.service.hue/resources/lib/globals.py index ef707c8d..a283f91b 100644 --- a/script.service.hue/resources/lib/globals.py +++ b/script.service.hue/resources/lib/globals.py @@ -1,29 +1,26 @@ -import xbmcaddon -from xbmc import getInfoLabel -from xbmc import translatePath -global settingsChanged -global connected -global forceOnSunset -global daylightDisable -global separateLogFile - - -settingsChanged = False -connected = False -daylight = False -forceOnSunset = True -daylightDisable = True -separateLogFile = False +from logging import getLogger +from xbmcaddon import Addon +from xbmc import getInfoLabel, translatePath NUM_GROUPS = 1 STRDEBUG = False #Show string ID in UI DEBUG = False # Enable python remote debug REMOTE_DBG_SUSPEND = False #Auto suspend thread when debugger attached -ADDON = xbmcaddon.Addon() +ADDON = Addon() ADDONID = ADDON.getAddonInfo('id') ADDONDIR = translatePath(ADDON.getAddonInfo('profile').decode('utf-8')) ADDONVERSION = ADDON.getAddonInfo('version') KODIVERSION = getInfoLabel('System.BuildVersion') +logger = getLogger(ADDONID) + +settingsChanged = False +connected = False +daylight = False +forceOnSunset = True +daylightDisable = True +separateLogFile = False + + diff --git a/script.service.hue/resources/lib/kodiHue.py b/script.service.hue/resources/lib/kodiHue.py index 85477249..8ebe4934 100644 --- a/script.service.hue/resources/lib/kodiHue.py +++ b/script.service.hue/resources/lib/kodiHue.py @@ -4,7 +4,7 @@ ''' -import logging +from logging import getLogger from builtins import str from socket import getfqdn @@ -19,7 +19,7 @@ from . import qhue from .language import get_string as _ -logger = logging.getLogger(globals.ADDONID) +logger = getLogger(globals.ADDONID) def createHueGroup(bridge): logger.debug("In kodiHue createHueGroup") @@ -429,13 +429,13 @@ def connectBridge(monitor,silent=False): logger.debug("Bridge not responding") kodiutils.notification(_("Hue Service"), _("Bridge connection failed"), icon=NOTIFICATION_ERROR) globals.connected = False - return False + return None else: logger.debug("Bridge not configured") kodiutils.notification(_("Hue Service"), _("Bridge not configured"), icon=NOTIFICATION_ERROR) globals.connected = False - return False + return None class HueMonitor(xbmc.Monitor): diff --git a/script.service.hue/resources/lib/kodilogging.py b/script.service.hue/resources/lib/kodilogging.py index e089d4d7..a50ce667 100644 --- a/script.service.hue/resources/lib/kodilogging.py +++ b/script.service.hue/resources/lib/kodilogging.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import logging +from logging.handlers import TimedRotatingFileHandler import os from builtins import str @@ -57,7 +58,8 @@ def config(): xbmc.log("Hue Service: Log: can't create directory: " + globals.ADDONDIR.encode('utf-8'), level=xbmc.LOGERROR) xbmc.log("Exception: " + str(e.message).encode('utf-8'), xbmc.LOGERROR) - fileHandler = logging.handlers.TimedRotatingFileHandler(os.path.join(globals.ADDONDIR, 'kodiHue.log'), when="midnight", backupCount=2) + + fileHandler = TimedRotatingFileHandler(os.path.join(globals.ADDONDIR, 'kodiHue.log'), when="midnight", backupCount=2) fileHandler.setLevel(logging.DEBUG) fileHandler.setFormatter(fileFormatter) logger.addHandler(fileHandler) From 147b7a66e6121ad297e3a5a13e6628609ceffbc9 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 15:19:22 -0400 Subject: [PATCH 03/13] update --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1e2831ff..29990afc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ /.project /.settings /.idea -testing.py \ No newline at end of file +testing.py +*.bak \ No newline at end of file From 11ed07980f9b88aa15f0ec12dbe237caaddcce4f Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 15:53:30 -0400 Subject: [PATCH 04/13] kodi_six, py2/3 bug fixing --- script.service.hue/addon.xml | 4 +- script.service.hue/resources/lib/globals.py | 8 +- .../resources/lib/kodilogging.py | 14 +- script.service.hue/resources/lib/kodiutils.py | 137 +----------------- 4 files changed, 18 insertions(+), 145 deletions(-) diff --git a/script.service.hue/addon.xml b/script.service.hue/addon.xml index 9c6f11b2..474879cc 100644 --- a/script.service.hue/addon.xml +++ b/script.service.hue/addon.xml @@ -3,10 +3,10 @@ + - - + diff --git a/script.service.hue/resources/lib/globals.py b/script.service.hue/resources/lib/globals.py index a283f91b..a9fa4245 100644 --- a/script.service.hue/resources/lib/globals.py +++ b/script.service.hue/resources/lib/globals.py @@ -2,7 +2,9 @@ from logging import getLogger from xbmcaddon import Addon -from xbmc import getInfoLabel, translatePath +#getInfoLabel, translatePath + +from kodi_six import xbmcaddon, xbmc NUM_GROUPS = 1 STRDEBUG = False #Show string ID in UI @@ -11,9 +13,9 @@ ADDON = Addon() ADDONID = ADDON.getAddonInfo('id') -ADDONDIR = translatePath(ADDON.getAddonInfo('profile').decode('utf-8')) +ADDONDIR = xbmc.translatePath(ADDON.getAddonInfo('profile')) #.decode('utf-8')) ADDONVERSION = ADDON.getAddonInfo('version') -KODIVERSION = getInfoLabel('System.BuildVersion') +KODIVERSION = xbmc.getInfoLabel('System.BuildVersion') logger = getLogger(ADDONID) settingsChanged = False diff --git a/script.service.hue/resources/lib/kodilogging.py b/script.service.hue/resources/lib/kodilogging.py index a50ce667..80a950fd 100644 --- a/script.service.hue/resources/lib/kodilogging.py +++ b/script.service.hue/resources/lib/kodilogging.py @@ -12,9 +12,9 @@ from resources.lib import globals from resources.lib.kodiutils import get_setting_as_bool -prefix = b"[{}]".format(globals.ADDONID) -formatter = logging.Formatter(prefix + b'[%(module)s][%(funcName)s](%(lineno)d): %(message)s') -fileFormatter = logging.Formatter(b'%(asctime)s %(levelname)s [%(module)s][%(funcName)s](%(lineno)d): %(message)s') +prefix = "[{}]".format(globals.ADDONID) +formatter = logging.Formatter(prefix + '[%(module)s][%(funcName)s](%(lineno)d): %(message)s') +fileFormatter = logging.Formatter('%(asctime)s %(levelname)s [%(module)s][%(funcName)s](%(lineno)d): %(message)s') class KodiLogHandler(logging.StreamHandler): @@ -50,13 +50,13 @@ def config(): if separateLogFile: if not os.path.isdir(globals.ADDONDIR): - xbmc.log("Hue Service: profile directory doesn't exist: " + globals.ADDONDIR.encode('utf-8') + " Trying to create.", level=xbmc.LOGNOTICE) + xbmc.log("Hue Service: profile directory doesn't exist: " + globals.ADDONDIR + " Trying to create.", level=xbmc.LOGNOTICE) try: os.mkdir(globals.ADDONDIR) - xbmc.log("Hue Service: profile directory created: " + globals.ADDONDIR.encode('utf-8'), level=xbmc.LOGNOTICE) + xbmc.log("Hue Service: profile directory created: " + globals.ADDONDIR, level=xbmc.LOGNOTICE) except OSError as e: - xbmc.log("Hue Service: Log: can't create directory: " + globals.ADDONDIR.encode('utf-8'), level=xbmc.LOGERROR) - xbmc.log("Exception: " + str(e.message).encode('utf-8'), xbmc.LOGERROR) + xbmc.log("Hue Service: Log: can't create directory: " + globals.ADDONDIR, level=xbmc.LOGERROR) + xbmc.log("Exception: " + str(e.message), xbmc.LOGERROR) fileHandler = TimedRotatingFileHandler(os.path.join(globals.ADDONDIR, 'kodiHue.log'), when="midnight", backupCount=2) diff --git a/script.service.hue/resources/lib/kodiutils.py b/script.service.hue/resources/lib/kodiutils.py index 992a3e88..8a80b3b5 100644 --- a/script.service.hue/resources/lib/kodiutils.py +++ b/script.service.hue/resources/lib/kodiutils.py @@ -3,141 +3,12 @@ import logging from builtins import str -import xbmc -import xbmcgui +from kodi_six import xbmc, xbmcgui +#import xbmcgui from . import globals -# read settings - -def configLog(): - - - global setting_LogLevel - global setting_SeparateLogFile - - setting_LogLevel = int(globals.ADDON.getSetting("logLevel")) - setting_SeparateLogFile = int(globals.ADDON.getSetting("separateLogFile")) - - __addonworkdir__ = xbmc.translatePath(globals.ADDON.getAddonInfo('profile').decode('utf-8')) - - formatter = logging.Formatter(b'[{}][%(funcName)s] %(filename)s(%(lineno)d): %(message)s\n'.format(globals.ADDONID)) - kodilogger = logging.getLogger(globals.ADDONID) - - - - - - a=1+1 - -# kodilogger.setFormatter(formatter) - - - # prepare datadir - # directory and file is local to the filesystem - # no need to use xbmcvfs -#=============================================================================== -# if not os.path.isdir(__addonworkdir__): -# xbmc.log("Hue: profile directory doesn't exist: " + __addonworkdir__.encode('utf-8') + " Trying to create.", level=xbmc.LOGNOTICE) -# try: -# os.mkdir(__addonworkdir__) -# xbmc.log("Hue: profile directory created: " + __addonworkdir__.encode('utf-8'), level=xbmc.LOGNOTICE) -# except OSError as e: -# xbmc.log("Hue: Log: can't create directory: " + __addonworkdir__.encode('utf-8'), level=xbmc.LOGERROR) -# xbmc.log("Exception: " + str(e.message).encode('utf-8'), xbmc.LOGERROR) -# -# # prepare external log handler -# # https://docs.python.org/2/library/logging.handlers.html -# global filelogger -# filelogger = logging.getLogger(__name__) -# loghandler = logging.handlers.TimedRotatingFileHandler(os.path.join(__addonworkdir__, 'kodiHue.log',), when="midnight", interval=1, backupCount=2) -# -# # rootlogger = logging.getLogger() -# -# filelogger.addHandler(loghandler) -# formatter = logging.Formatter(b'[{}][%(funcName)s] %(filename)s(%(lineno)d): %(message)s\n'.format(globals.ADDONID)) -#=============================================================================== - -# filelogger.setFormatter(formatter) - - - - # xbmc loglevels: https://forum.kodi.tv/showthread.php?tid=324570&pid=2671926#pid2671926 - # 0 = LOGDEBUG - # 1 = LOGINFO - # 2 = LOGNOTICE - # 3 = LOGWARNING - # 4 = LOGERROR - # 5 = LOGSEVERE - # 6 = LOGFATAL - # 7 = LOGNONE - - - - - -def log(message,level): - prefix = b"[%s] " % globals.ADDONID - formatter = prefix + b'%(name)s: %(message)s' - try: - xbmc.log(formatter, level) - except UnicodeEncodeError: - xbmc.log(formatter.encode( - 'utf-8', 'ignore'), level) - -#=============================================================================== -# def log(message, severity=xbmc.LOGDEBUG): -# """Log message to internal Kodi log or external log file. -# -# Arguments: -# message {str} -- message text -# -# Keyword Arguments: -# severity {int} -- log level (default: {xbmc.LOGDEBUG}) -# """ -# -# # get log level settings -# setting_LogLevel = int(globals.ADDON.getSetting("logLevel")) -# setting_SeparateLogFile = int(globals.ADDON.getSetting("separateLogFile")) -# -# if severity >= setting_LogLevel: -# # log the message to Log -# if setting_SeparateLogFile == 0: -# # use kodi.log for logging -# # check if string is str -# if isinstance(message, str): -# # convert to unicode string -# message = message.decode('utf-8') -# # re-encode to utf-8 -# xbmc.log("[SCRIPT.SERVICE.HUE]: " + message.encode('utf-8'), level=xbmc.LOGNONE) -# else: -# # use smangler's own log file located in addon's datadir -# # construct log text -# # cut last 3 trailing zero's from timestamp -# logtext = str(datetime.now)[:-3] -# if severity == xbmc.LOGDEBUG: -# logtext += " DEBUG: " -# elif severity == xbmc.LOGINFO: -# logtext += " INFO: " -# elif severity == xbmc.LOGNOTICE: -# logtext += " NOTICE: " -# elif severity == xbmc.LOGWARNING: -# logtext += " WARNING: " -# elif severity == xbmc.LOGERROR: -# logtext += " ERROR: " -# elif severity == xbmc.LOGSEVERE: -# logtext += " SEVERE: " -# elif severity == xbmc.LOGFATAL: -# logtext += " FATAL: " -# else: -# logtext += " NONE: " -# logtext += message -# # append line to external log file -# # logging via warning level to prevent filtering of messages by default filtering level of ROOT logger -# filelogger.warning(logtext) -#=============================================================================== - def notification(header, message, time=5000, icon=globals.ADDON.getAddonInfo('icon'), sound=True): xbmcgui.Dialog().notification(header, message, icon, time, sound) @@ -148,7 +19,7 @@ def show_settings(): def get_setting(setting): - return globals.ADDON.getSetting(setting).strip().decode('utf-8') + return globals.ADDON.getSetting(setting).strip() def set_setting(setting, value): @@ -174,5 +45,5 @@ def get_setting_as_int(setting): def get_string(string_id): - return globals.ADDON.getLocalizedString(string_id).encode('utf-8', 'ignore') + return globals.ADDON.getLocalizedString(string_id) From 2f4c5e6aa76491ca2466132d2eda163d8f40d4c6 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 16:14:44 -0400 Subject: [PATCH 05/13] fix language system --- script.service.hue/addon.xml | 4 ++-- script.service.hue/resources/lib/language.py | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/script.service.hue/addon.xml b/script.service.hue/addon.xml index 474879cc..de9f5213 100644 --- a/script.service.hue/addon.xml +++ b/script.service.hue/addon.xml @@ -2,9 +2,9 @@ - + - + diff --git a/script.service.hue/resources/lib/language.py b/script.service.hue/resources/lib/language.py index d902cad3..611c8fb0 100644 --- a/script.service.hue/resources/lib/language.py +++ b/script.service.hue/resources/lib/language.py @@ -6,7 +6,8 @@ import sys from builtins import range -from .globals import STRDEBUG +from .globals import STRDEBUG,ADDON + ######### Based upon: https://raw.githubusercontent.com/Quihico/handy.stuff/master/language.py ######### https://forum.kodi.tv/showthread.php?tid=268081&highlight=generate+.po+python+gettext @@ -66,10 +67,9 @@ m.msgctxt.replace("#", "").strip()) f.write(line) else: + import xbmc def get_string(t): - import xbmc, xbmcaddon - ADDON = xbmcaddon.Addon() -# ADDON_ID = ADDON.getAddonInfo("id") + id = _strings.get(t.lower()) if not id: xbmc.log("LANGUAGE: missing translation for '%s'" % t.lower()) @@ -104,17 +104,7 @@ def get_string(t): _strings['global settings'] = 2100 _strings['advanced'] = 32101 _strings['debug logs'] = 32102 -_strings['log destination'] = 32105 -_strings['default (kodi.log)'] = 32106 -_strings['separate (kodihue.log)'] = 32107 -_strings['logging level'] = 32108 -_strings['debug'] = 32301 -_strings['info'] = 32302 -_strings['notice'] = 32303 -_strings['warning'] = 32304 -_strings['error'] = 32305 -_strings['severe'] = 32306 -_strings['fatal'] = 32307 +_strings['separate debug log'] = 32105 _strings['initial flash'] = 5110 _strings['flash on settings reload'] = 5111 _strings['group'] = 6000 From a57f7681638c95a0206a5562f1d9e9ef132a7f4d Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 16:38:42 -0400 Subject: [PATCH 06/13] fix cancel delete Scene dialogue not closing when no scene is selected --- script.service.hue/resources/lib/KodiGroup.py | 18 ++++++++---------- script.service.hue/resources/lib/kodiHue.py | 6 +++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/script.service.hue/resources/lib/KodiGroup.py b/script.service.hue/resources/lib/KodiGroup.py index c54010e5..6195ef65 100644 --- a/script.service.hue/resources/lib/KodiGroup.py +++ b/script.service.hue/resources/lib/KodiGroup.py @@ -50,7 +50,6 @@ def readSettings(self): def setup(self,bridge,kgroupID,flash = False): self.bridge = bridge - self.lights = bridge.lights self.kgroupID=kgroupID @@ -65,7 +64,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)) @@ -106,23 +104,23 @@ def onPlayBackStarted(self, saveInitial=False): self.saveInitialState() if self.enabled 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): - + if self.stopBehavior == BEHAVIOR_ADJUST: try: self.groupResource.action(scene=self.stopScene) @@ -167,12 +165,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: diff --git a/script.service.hue/resources/lib/kodiHue.py b/script.service.hue/resources/lib/kodiHue.py index 8ebe4934..c31cbaab 100644 --- a/script.service.hue/resources/lib/kodiHue.py +++ b/script.service.hue/resources/lib/kodiHue.py @@ -76,7 +76,7 @@ def createHueScene(bridge): def deleteHueScene(bridge): logger.debug("In kodiHue deleteHueScene") scene = selectHueScene(bridge) - if scene: + if scene is not None: confirm = xbmcgui.Dialog().yesno(_("Delete Hue Scene"), _("Are you sure you want to delete this scene: "), str(scene[1])) if scene and confirm: scenes=bridge.scenes @@ -361,8 +361,8 @@ def selectHueScene(bridge): selectedId = index[selected] hSceneName=hueScenes[selectedId]['name'] logger.debug("In selectHueScene: selected: {}".format(selected)) - - if selectedId: + + if selected > -1: return selectedId, hSceneName; else: return None From 34ad38428adfbf822a39a704f88a52a0eb6ad6a0 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 17:05:41 -0400 Subject: [PATCH 07/13] Add audio group strings & settings --- .gitignore | 17 +++--- .../resource.language.en_GB/strings.po | 20 ++++--- script.service.hue/resources/lib/KodiGroup.py | 16 ++++- script.service.hue/resources/lib/globals.py | 2 +- script.service.hue/resources/lib/kodiHue.py | 58 +++++++++---------- script.service.hue/resources/settings.xml | 46 ++++++++++++++- 6 files changed, 106 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 29990afc..cdeba3e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ -*.pyc -*.pyo -/.pydevproject -/.project -/.settings -/.idea -testing.py -*.bak \ No newline at end of file +*.pyc +*.pyo +/.pydevproject +/.project +/.settings +/.idea +testing.py +*.bak +/check.bat diff --git a/script.service.hue/resources/language/resource.language.en_GB/strings.po b/script.service.hue/resources/language/resource.language.en_GB/strings.po index 026dcef7..29821dcc 100644 --- a/script.service.hue/resources/language/resource.language.en_GB/strings.po +++ b/script.service.hue/resources/language/resource.language.en_GB/strings.po @@ -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" diff --git a/script.service.hue/resources/lib/KodiGroup.py b/script.service.hue/resources/lib/KodiGroup.py index 6195ef65..4f9abeb1 100644 --- a/script.service.hue/resources/lib/KodiGroup.py +++ b/script.service.hue/resources/lib/KodiGroup.py @@ -21,6 +21,7 @@ STATE_PAUSED = 2 state = 0 +mediaType = 0 #0=video, 1=audio logger = getLogger(globals.ADDONID) @@ -98,7 +99,8 @@ 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 if saveInitial: self.saveInitialState() @@ -117,7 +119,7 @@ def onPlayBackStarted(self, saveInitial=False): def onPlayBackStopped(self): self.state = STATE_IDLE - logger.info("In KodiGroup[{}], onPlaybackStopped() ".format(self.kgroupID)) + logger.info("In KodiGroup[{}], onPlaybackStopped() , isPlayingVideo: {}, isPlayingAudio: {} ".format(self.kgroupID,self.isPlayingVideo(),self.isPlayingAudio())) if self.enabled and not (globals.daylightDisable == globals.daylight): @@ -137,7 +139,7 @@ def onPlayBackStopped(self): def onPlayBackPaused(self): self.state = STATE_PAUSED - logger.info("In KodiGroup[{}], onPlaybackPaused()".format(self.kgroupID)) + logger.info("In KodiGroup[{}], onPlaybackPaused() , isPlayingVideo: {}, isPlayingAudio: {}".format(self.kgroupID,self.isPlayingVideo(),self.isPlayingAudio())) if self.enabled and not (globals.daylightDisable == globals.daylight): @@ -182,3 +184,11 @@ def sunset(self): self.forceOn = previousForce + + +class KodiVideoGroup(KodiGroup): + def __init__(self): + super(KodiGroup,self).__init__() + + def onPlayBackStarted(self, saveInitial=False): + pass diff --git a/script.service.hue/resources/lib/globals.py b/script.service.hue/resources/lib/globals.py index a9fa4245..561f41a3 100644 --- a/script.service.hue/resources/lib/globals.py +++ b/script.service.hue/resources/lib/globals.py @@ -6,7 +6,7 @@ from kodi_six import xbmcaddon, xbmc -NUM_GROUPS = 1 +NUM_GROUPS = 2 #group0= video, group1=audio STRDEBUG = False #Show string ID in UI DEBUG = False # Enable python remote debug REMOTE_DBG_SUSPEND = False #Auto suspend thread when debugger attached diff --git a/script.service.hue/resources/lib/kodiHue.py b/script.service.hue/resources/lib/kodiHue.py index c31cbaab..a25f7785 100644 --- a/script.service.hue/resources/lib/kodiHue.py +++ b/script.service.hue/resources/lib/kodiHue.py @@ -120,15 +120,15 @@ def bridgeDiscover(monitor): #bridgeIP = discoverBridgeIP.. progressBar.update(10, _("nupnp discovery... ")) bridgeIP =_discoverNupnp() - + if connectionTest(bridgeIP): progressBar.update(100, _("Found bridge: ") + bridgeIP) monitor.waitForAbort(1) - + bridgeUser = createUser(monitor, bridgeIP, progressBar) if bridgeUser: progressBar.update(90,_("User Found!"),_("Saving settings")) - + kodiutils.set_setting("bridgeIP",bridgeIP) kodiutils.set_setting("bridgeUser",bridgeUser) complete = True @@ -137,14 +137,14 @@ def bridgeDiscover(monitor): monitor.waitForAbort(5) progressBar.close() return True - + else: progressBar.update(100, _("User not found"),_("Check your bridge and network")) monitor.waitForAbort(5) complete = True - + progressBar.close() - + else: progressBar.update(100, _("Bridge not found"),_("Check your bridge and network")) monitor.waitForAbort(5) @@ -155,8 +155,8 @@ def bridgeDiscover(monitor): progressBar.update(100,_("Cancelled")) complete = True progressBar.close() - - + + def connectionTest(bridgeIP): logger.debug("in ConnectionTest() Attempt initial connection") b = qhue.qhue.Resource("http://{}/api".format(bridgeIP)) @@ -183,7 +183,7 @@ def userTest(bridgeIP,bridgeUser): zigbeechan = b.config()['zigbeechannel'] except: return False - + if zigbeechan: logger.info("Hue User Authorized. Bridge Zigbee Channel: {}".format(zigbeechan)) return True @@ -199,7 +199,7 @@ def discoverBridgeIP(monitor): bridgeIP = None if bridgeIP is None: bridgeIP = _discoverNupnp() - + if connectionTest(bridgeIP): return bridgeIP else: @@ -217,14 +217,14 @@ def createUser(monitor, bridgeIP, progressBar=False): progress=0 if progressBar: progressBar.update(progress,_("Press link button on bridge"),_("Waiting for 90 seconds...")) #press link button on bridge - - + + while 'link button not pressed' in res and timeout <= 90 and not monitor.abortRequested() and not progressBar.iscanceled(): logger.debug("In create_user: abortRquested: {}, timer: {}".format(str(monitor.abortRequested()),timeout) ) if progressBar: progressBar.update(progress,_("Press link button on bridge")) #press link button on bridge - #notification(get_string(9000), get_string(9001), time=1000, icon=xbmcgui.NOTIFICATION_WARNING) #9002: Press link button on bridge + req = requests.post('http://{}/api'.format(bridgeIP), data=data) res = req.text @@ -256,7 +256,7 @@ def configureScene(bridge,kGroupID,action): #group0_startSceneID kodiutils.set_setting("group{}_{}SceneID".format(kGroupID, action),scene[0]) kodiutils.set_setting("group{}_{}SceneName".format(kGroupID,action), scene[1]) - + globals.ADDON.openSettings() @@ -265,7 +265,7 @@ def configureScene(bridge,kGroupID,action): def selectHueLights(bridge): logger.debug("In selectHueLights{}") hueLights=bridge.lights() - + xbmc.executebuiltin('ActivateWindow(busydialognocancel)') items=[] index=[] @@ -287,23 +287,18 @@ def selectHueLights(bridge): for s in selected: lightIDs.append(index[s]) - - logger.debug("In selectHueGroup: selected: {}".format(selected)) + + logger.debug("selected: {}".format(selected)) if lightIDs: return lightIDs; else: return None - - - if selected: return selected else: return None - - def selectHueGroup(bridge): logger.debug("In selectHueGroup{}") hueGroups=bridge.groups() @@ -349,12 +344,12 @@ def selectHueScene(bridge): hScene=hueScenes[scene] hSceneName=hScene['name'] - + #logger.debug("In selectHueGroup: {}, {}".format(hgroup,name)) if hScene['version'] == 2 and hScene["recycle"] is False and hScene["type"] == "LightScene": index.append(scene) items.append(xbmcgui.ListItem(label=hSceneName)) - + xbmc.executebuiltin('Dialog.Close(busydialognocancel)') selected = xbmcgui.Dialog().select("Select Hue scene...",items) if selected > -1 : @@ -381,7 +376,7 @@ def sunset(bridge,kgroups): g.sunset() return - + def setupGroups(bridge,flash=False): logger.debug("in setupGroups()") @@ -392,7 +387,6 @@ def setupGroups(bridge,flash=False): kgroups.append(KodiGroup.KodiGroup()) kgroups[g].setup(bridge, g, flash) g = g + 1 - return kgroups @@ -403,7 +397,7 @@ def connectBridge(monitor,silent=False): bridgeUser = kodiutils.get_setting("bridgeUser") logger.debug("in Connect() with settings: bridgeIP: {}, bridgeUser: {}".format(bridgeIP,bridgeUser)) - + if bridgeIP and bridgeUser: if connectionTest(bridgeIP): logger.debug("in Connect(): Bridge responding to connection test.") @@ -414,8 +408,8 @@ def connectBridge(monitor,silent=False): if bridgeIP: logger.debug("in Connect(): New IP found: {}. Saving".format(bridgeIP)) kodiutils.set_setting("bridgeIP",bridgeIP) - - + + if bridgeIP: logger.debug("in Connect(): Checking User") if userTest(bridgeIP, bridgeUser): @@ -430,14 +424,14 @@ def connectBridge(monitor,silent=False): kodiutils.notification(_("Hue Service"), _("Bridge connection failed"), icon=NOTIFICATION_ERROR) globals.connected = False return None - + else: logger.debug("Bridge not configured") kodiutils.notification(_("Hue Service"), _("Bridge not configured"), icon=NOTIFICATION_ERROR) globals.connected = False return None - - + + class HueMonitor(xbmc.Monitor): def __init__(self): super(xbmc.Monitor,self).__init__() diff --git a/script.service.hue/resources/settings.xml b/script.service.hue/resources/settings.xml index 68ee9674..6dd7a291 100644 --- a/script.service.hue/resources/settings.xml +++ b/script.service.hue/resources/settings.xml @@ -24,7 +24,7 @@ - + @@ -60,6 +60,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From bef0a5ea20d3a20845dda583ecf9d51989225ea0 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 17:41:35 -0400 Subject: [PATCH 08/13] fix audio group settings menu actions --- script.service.hue/resources/settings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script.service.hue/resources/settings.xml b/script.service.hue/resources/settings.xml index 6dd7a291..dbbdedd7 100644 --- a/script.service.hue/resources/settings.xml +++ b/script.service.hue/resources/settings.xml @@ -74,7 +74,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -92,7 +92,7 @@ - + From 2a307c9ba79036bc0b862b04a126416d711ecf70 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 17:57:10 -0400 Subject: [PATCH 09/13] Support multiple media types in KodiGroup --- script.service.hue/resources/lib/KodiGroup.py | 27 ++++++++++++------- script.service.hue/resources/lib/globals.py | 1 + script.service.hue/resources/lib/kodiHue.py | 27 ++++++++++++++----- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/script.service.hue/resources/lib/KodiGroup.py b/script.service.hue/resources/lib/KodiGroup.py index 4f9abeb1..38805c5e 100644 --- a/script.service.hue/resources/lib/KodiGroup.py +++ b/script.service.hue/resources/lib/KodiGroup.py @@ -20,8 +20,8 @@ STATE_PLAYING = 1 STATE_PAUSED = 2 -state = 0 -mediaType = 0 #0=video, 1=audio +VIDEO=1 +AUDIO=2 logger = getLogger(globals.ADDONID) @@ -37,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)) @@ -48,8 +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 @@ -100,12 +100,13 @@ def flash(self): def onPlayBackStarted(self, saveInitial=False): 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: @@ -121,7 +122,7 @@ 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 not (globals.daylightDisable == globals.daylight): + if self.enabled and self.mediaType == globals.lastMediaType and not (globals.daylightDisable == globals.daylight): if self.stopBehavior == BEHAVIOR_ADJUST: try: @@ -141,8 +142,8 @@ 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 not (globals.daylightDisable == globals.daylight): - + 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) @@ -186,6 +187,14 @@ 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(KodiGroup,self).__init__() diff --git a/script.service.hue/resources/lib/globals.py b/script.service.hue/resources/lib/globals.py index 561f41a3..de0cb2b2 100644 --- a/script.service.hue/resources/lib/globals.py +++ b/script.service.hue/resources/lib/globals.py @@ -24,5 +24,6 @@ forceOnSunset = True daylightDisable = True separateLogFile = False +lastMediaType=0 diff --git a/script.service.hue/resources/lib/kodiHue.py b/script.service.hue/resources/lib/kodiHue.py index a25f7785..8028cfe3 100644 --- a/script.service.hue/resources/lib/kodiHue.py +++ b/script.service.hue/resources/lib/kodiHue.py @@ -19,6 +19,7 @@ from . import qhue from .language import get_string as _ + logger = getLogger(globals.ADDONID) def createHueGroup(bridge): @@ -381,12 +382,26 @@ def sunset(bridge,kgroups): def setupGroups(bridge,flash=False): logger.debug("in setupGroups()") kgroups= [] - g=0 - while g < globals.NUM_GROUPS: - if kodiutils.get_setting_as_bool("group{}_enabled".format(g)): - kgroups.append(KodiGroup.KodiGroup()) - kgroups[g].setup(bridge, g, flash) - g = g + 1 + + + + if kodiutils.get_setting_as_bool("group0_enabled".format(0)): #VIDEO Group + kgroups.append(KodiGroup.KodiGroup()) + kgroups[0].setup(bridge, 0, flash,KodiGroup.VIDEO) + + if kodiutils.get_setting_as_bool("group1_enabled".format(1)): #Audio Group + kgroups.append(KodiGroup.KodiGroup()) + kgroups[1].setup(bridge, 1, flash,KodiGroup.AUDIO) + + #=========================================================================== + # g=0 + # while g < globals.NUM_GROUPS: + # if kodiutils.get_setting_as_bool("group{}_enabled".format(g)): + # kgroups.append(KodiGroup.KodiGroup()) + # kgroups[g].setup(bridge, g, flash) + # g = g + 1 + #=========================================================================== + return kgroups From 1accacc5146dec97f418c381cdaec160bde18e20 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 18:06:53 -0400 Subject: [PATCH 10/13] bump version number --- script.service.hue/addon.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/script.service.hue/addon.xml b/script.service.hue/addon.xml index de9f5213..02cf4fdb 100644 --- a/script.service.hue/addon.xml +++ b/script.service.hue/addon.xml @@ -1,4 +1,4 @@ - + @@ -22,6 +22,8 @@ all MIT License +v0.3.0: + - Support different behaviours for different media types v0.2.8: - Python 2/3 support v0.2.7: From 67eeace3a3ca8ed40a59e61db9894e32655ecfc2 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 18:09:21 -0400 Subject: [PATCH 11/13] update travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 19726aee..b84275f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ deploy: file_glob: true file: $RELEASE_ZIP skip_cleanup: true - prerelease: false + prerelease: true draft: false on: all_branches: true From 5d29a33388957aee9b49ca6f01c6aeb6c6945843 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 18:25:11 -0400 Subject: [PATCH 12/13] Codacy fixes --- script.service.hue/resources/lib/KodiGroup.py | 6 +++--- script.service.hue/resources/lib/globals.py | 2 +- script.service.hue/resources/lib/kodiHue.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/script.service.hue/resources/lib/KodiGroup.py b/script.service.hue/resources/lib/KodiGroup.py index 38805c5e..075b4c83 100644 --- a/script.service.hue/resources/lib/KodiGroup.py +++ b/script.service.hue/resources/lib/KodiGroup.py @@ -189,15 +189,15 @@ def sunset(self): def playbackType(self): if self.isPlayingVideo(): - mediaType=VIDEO + mediaType=VIDEO elif self.isPlayingAudio(): mediaType=AUDIO return mediaType - + class KodiVideoGroup(KodiGroup): def __init__(self): - super(KodiGroup,self).__init__() + super(KodiVideoGroup,self).__init__() def onPlayBackStarted(self, saveInitial=False): pass diff --git a/script.service.hue/resources/lib/globals.py b/script.service.hue/resources/lib/globals.py index de0cb2b2..54c0d3cd 100644 --- a/script.service.hue/resources/lib/globals.py +++ b/script.service.hue/resources/lib/globals.py @@ -2,7 +2,7 @@ from logging import getLogger from xbmcaddon import Addon -#getInfoLabel, translatePath + from kodi_six import xbmcaddon, xbmc diff --git a/script.service.hue/resources/lib/kodiHue.py b/script.service.hue/resources/lib/kodiHue.py index 8028cfe3..75d672ae 100644 --- a/script.service.hue/resources/lib/kodiHue.py +++ b/script.service.hue/resources/lib/kodiHue.py @@ -385,11 +385,11 @@ def setupGroups(bridge,flash=False): - if kodiutils.get_setting_as_bool("group0_enabled".format(0)): #VIDEO Group + if kodiutils.get_setting_as_bool("group0_enabled"): #VIDEO Group kgroups.append(KodiGroup.KodiGroup()) kgroups[0].setup(bridge, 0, flash,KodiGroup.VIDEO) - if kodiutils.get_setting_as_bool("group1_enabled".format(1)): #Audio Group + if kodiutils.get_setting_as_bool("group1_enabled"): #Audio Group kgroups.append(KodiGroup.KodiGroup()) kgroups[1].setup(bridge, 1, flash,KodiGroup.AUDIO) @@ -398,7 +398,7 @@ def setupGroups(bridge,flash=False): # while g < globals.NUM_GROUPS: # if kodiutils.get_setting_as_bool("group{}_enabled".format(g)): # kgroups.append(KodiGroup.KodiGroup()) - # kgroups[g].setup(bridge, g, flash) + # kgroups[g].setup(bridge, g, flash) # g = g + 1 #=========================================================================== From ec9c2648b6704077c62fe9e72360071b8dd2d334 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sun, 23 Jun 2019 18:27:55 -0400 Subject: [PATCH 13/13] fix whitespace --- script.service.hue/resources/lib/kodilogging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.service.hue/resources/lib/kodilogging.py b/script.service.hue/resources/lib/kodilogging.py index 80a950fd..4c74804f 100644 --- a/script.service.hue/resources/lib/kodilogging.py +++ b/script.service.hue/resources/lib/kodilogging.py @@ -58,7 +58,7 @@ def config(): xbmc.log("Hue Service: Log: can't create directory: " + globals.ADDONDIR, level=xbmc.LOGERROR) xbmc.log("Exception: " + str(e.message), xbmc.LOGERROR) - + fileHandler = TimedRotatingFileHandler(os.path.join(globals.ADDONDIR, 'kodiHue.log'), when="midnight", backupCount=2) fileHandler.setLevel(logging.DEBUG) fileHandler.setFormatter(fileFormatter)