diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..f23368e --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +__author__ = 'dominik' diff --git a/script.homepilot/__init__.py b/script.homepilot/__init__.py new file mode 100644 index 0000000..f23368e --- /dev/null +++ b/script.homepilot/__init__.py @@ -0,0 +1 @@ +__author__ = 'dominik' diff --git a/script.homepilot/default.py b/script.homepilot/default.py index c6c9bca..04f97cd 100644 --- a/script.homepilot/default.py +++ b/script.homepilot/default.py @@ -1,12 +1,29 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import sys import os +import sys +import threading +import time + import xbmc -import xbmcgui import xbmcaddon -import threading +import xbmcgui +from resources.lib import homepilot_client +from resources.lib import settings +from resources.lib import statics +from resources.lib.Views.empty_view import EmptyView +from resources.lib.Views.favoriten_view import FavoritenView +from resources.lib.Views.geraetetyp_view import GeraetetypView +from resources.lib.Views.parametrized_geraete_view import ParametrizedGeraeteView +from resources.lib.Views.szenen_list_view import SzenenListView +from resources.lib.Views.szenentyp_view import SzenentypView +from resources.lib.Windows.degree_window import DegreeWindow +from resources.lib.Windows.error_window import ErrorWindow +from resources.lib.Windows.meter_window import MeterWindow +from resources.lib.Windows.percentage_window import PercentageWindow +from resources.lib.Windows.switch_window import SwitchWindow +from resources.lib.Windows import scene_window as szene """ Implementation of an XBMC Script Addon @@ -15,133 +32,68 @@ and offers buttons to change ist. """ - __addon__ = xbmcaddon.Addon(id='script.homepilot') -__cwd__ = xbmc.translatePath( __addon__.getAddonInfo('path') ).decode("utf-8") +__cwd__ = xbmc.translatePath(__addon__.getAddonInfo('path').decode("utf-8")) # add lib directory to sys.path as this doesn't happen automatically -__resource__ = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'lib' ) ).decode("utf-8") -sys.path.append (__resource__) +__resource__ = xbmc.translatePath(os.path.join(__cwd__, 'resources', 'lib').decode("utf-8")) +sys.path.append(__resource__) -import homepilot_client -import homepilot_views -import settings -import time -from homepilot_utils import ROLLADEN, SCHALTER, DIMMER, THERMOSTATE, TORE, SZENEN_MANUELL, SZENEN_NICHT_MANUELL, \ - SZENEN_ALLE, SZENENTYPEN, SZENEN_DETAILS, SENSOREN, ALLE, FAVORITEN, GRUPPEN, FAVORITEN_LOKAL -from device_windows import MeterWindow, PercentageWindow, SwitchWindow, DegreeWindow, ErrorWindow -from scene_window import SzenenDetailWindow - -FAVORITEN_VIEW = str(FAVORITEN) + "_view" -FAVORITEN_LOKAL_VIEW = str(FAVORITEN_LOKAL) + "_view" -GERAETETYP_VIEW = "geraetetyp_view" # String wird so noch irgendwo anders verwendet Anpassung nicht trivial str(GERAETE) + "_view" -DEVICE_GRUPPEN_VIEW = str(GRUPPEN) + "_view" -DEVICE_ALLE_VIEW = str(ALLE) + "_view" -SENSOREN_VIEW = str(SENSOREN) + "_view" - -DEVICE_ROLLADEN_VIEW = str(ROLLADEN) + "_view" -DEVICE_SCHALTER_VIEW = str(SCHALTER) + "_view" -DEVICE_DIMMER_VIEW = str(DIMMER) + "_view" -DEVICE_THERMOSTATE_VIEW = str(THERMOSTATE) + "_view" -DEVICE_TORE_VIEW = str(TORE) + "_view" -SZENEN_MANUELL_VIEW = str(SZENEN_MANUELL) + "_view" -SZENEN_NICHT_MANUELL_VIEW = str(SZENEN_NICHT_MANUELL) + "_view" -SZENEN_ALLE_VIEW = str(SZENEN_ALLE) + "_view" -SZENENTYP_VIEW = str(SZENENTYPEN) + "_view" -SZENEN_DETAILS_VIEW = str(SZENEN_DETAILS) + "_view" -EMPTY_VIEW = "empty_view" - -#Original Links -ACTION_NAV_BACK = 92 -ACTION_BACKSPACE = 110 -ACTION_MOVE_LEFT = 1 -MOUSE_LEFT_CLICK = 100 -ENTER = 135 -MOVE_RIGHT = 2 - -#Tastaturnummern buttoncode() -HP_VK_DOWN = 61569 -HP_VK_UP = 61568 -HP_VK_LEFT = 61570 -HP_VK_RIGHT = 61571 -HP_VK_ENTER = 61453 -#BC_HP_VK_ENTER_NUM = -HP_VK_BACK = 61448 -HP_VK_ESC = 61467 - -#CEC Befehle (Grundig) -HP_CEC_DOWN = 167 -HP_CEC_UP = 166 -HP_CEC_LEFT = 169 -HP_CEC_RIGHT = 168 -HP_CEC_ENTER = 11 -HP_CEC_BACK = 216 -#HP_CEC_ESC = - -#Action IDs > sollen allgemein richtig sein -AID_DOWN = 4 -AID_UP = 3 -AID_LEFT = 1 -AID_RIGHT = 2 -AID_ENTER = 7 -AID_BACK = 92 -AID_ESC = 10 - -#FocusIds -FOCUS_LIST_FAV = 95 -FOCUS_LIST_DEVICES = 96 -FOCUS_LIST_DEVICE_TYP = 257 -FOCUS_LIST_DEVICE_GROUP = 4 -FOCUS_LIST_SCENES = 94 -FOCUS_LIST_SENSOR = 97 -FOCUS_LIST_CONFIG = 98 -FOCUS_LIST_SENSORLIST = 5 -FOCUS_LIST_FAVLIST_AKTOREN = 255 -FOCUS_LIST_FAVLIST_SZENEN = 264 -FOCUS_LIST_SCENE_LIST = 258 -FOCUS_SCROLL_FAVLIST_DEV = 993 -FOCUS_SCROLL_FAVLIST_SCN = 226 -#FOCUS_SCROLL_DEVTYP = -FOCUS_SCROLL_DEVGROUP = 998 -FOCUS_SCROLL_DEVLIST = 999 -FOCUS_SCROLL_SCENELIST = 259 # tail -f /home/root/.xbmc/temp/xbmc.log | grep PMM--- # ps aux | grep xbmc.bin -class StatusUpdater (threading.Thread): - - def __init__(self, initialView, menuControl, title, window): +class StatusUpdater(threading.Thread): + def __init__(self, initialView, menuControl, title, x): + xbmc.log("PMM--- StatusUpdater: __init__", level=xbmc.LOGDEBUG) self.window = window threading.Thread.__init__(self) - self.set_current_view(initialView, menuControl) + self.currentView = initialView + self.menuControl = menuControl self.is_running = True self.current_window = None self.title = title - def set_current_view (self, currentView, menuControl): + def set_current_view(self, currentView, menuControl): + xbmc.log("PMM--- StatusUpdater: set_currentView: currentView:" + str(currentView) + " menuControl: " + str( + menuControl), level=xbmc.LOGDEBUG) self.currentView = currentView self.menuControl = menuControl def set_current_window(self, currentWindow): + xbmc.log("PMM--- StatusUpdater: set_current_window: currentWindow: " + str(currentWindow), level=xbmc.LOGDEBUG) self.current_window = currentWindow - def set_is_running (self, is_running): - self.is_running = is_running - def run(self): - self.is_running = 'True' - self.currentView.visualize (self.window, __addon__, self.title) + """ + run läuft alle 1,5 Sekunden und ruft die Updatemethode des aktuellen Windows und der aktuellen View auf. + """ + self.is_running = True + self.currentView.visualize(self.window, __addon__, self.title) + views = [statics.FAVORITEN_VIEW, statics.FAVORITEN_LOKAL_VIEW, + statics.DEVICE_ROLLADEN_VIEW, statics.DEVICE_DIMMER_VIEW, + statics.DEVICE_SCHALTER_VIEW, statics.DEVICE_THERMOSTATE_VIEW, + statics.DEVICE_TORE_VIEW, statics.SENSOREN_VIEW, statics.DEVICE_ALLE_VIEW] while self.is_running: time.sleep(1.5) - if self.current_window is not None and not self.current_window.is_closed(): + xbmc.log("PMM--- StatusUpdater: run: is_running", level=xbmc.LOGDEBUG) + if self.currentView is not None and self.current_window is not None: + xbmc.log("PMM--- StatusUpdater: run: \n" + + "Window: " + repr(self.current_window) + "\n" + + "View: " + repr(self.currentView), + level=xbmc.LOGDEBUG) self.current_window.update() - v_id = self.currentView.get_id() - if v_id == FAVORITEN_VIEW or v_id == FAVORITEN_LOKAL_VIEW or v_id == DEVICE_ROLLADEN_VIEW or v_id == DEVICE_SCHALTER_VIEW \ - or v_id == DEVICE_DIMMER_VIEW or v_id == DEVICE_THERMOSTATE_VIEW or v_id == DEVICE_TORE_VIEW or v_id == SENSOREN_VIEW: - self.currentView.update(self.window, __addon__, self.menuControl) - - + v_id = self.currentView.get_id() + if v_id in views: + self.currentView.update(self.window, __addon__, self.menuControl) + elif self.currentView is not None: + v_id = self.currentView.get_id() + xbmc.log("PMM--- StatusUpdater: run: No Window but a view. \nView: " + repr(self.currentView) + + "\nv_id: " + repr(v_id), level=xbmc.LOGDEBUG) + if v_id in views: + self.currentView.update(self.window, __addon__, self.menuControl) + else: + xbmc.log("PMM--- StatusUpdater: run: No window or view.", level=xbmc.LOGDEBUG) class GuiController(xbmcgui.WindowXMLDialog): @@ -149,37 +101,45 @@ class GuiController(xbmcgui.WindowXMLDialog): representing a window with the HomePilot controls """ - def __init__( self, *args, **kwargs ): + def __init__(self, *args, **kwargs): """ constructor of the class """ - xbmcgui.WindowXMLDialog.__init__( self ) + xbmc.log("PMM--- GuiController: __init__", level=xbmc.LOGDEBUG) + xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs) self.settings_dialog_manager = settings.SettingsDialogManager() ip_address = self.settings_dialog_manager.get_ip_address(__addon__) self.client = homepilot_client.HomepilotClient(ip_address) - self._wait_for_visualization = False - self._isScene = False + uselocalfavorites = self.settings_dialog_manager.use_local_favorites(__addon__) + if uselocalfavorites == "true": + self.uselocalfavorites_bool = True + else: + self.uselocalfavorites_bool = False + xbmc.log("PMM--- GuiController: __init__: uselocalfavorites_bool: " + repr(self.uselocalfavorites_bool), + level=xbmc.LOGDEBUG) + self.currentView = None + self.status_updater = None def onInit(self): """ initializes the window """ self.setProperty('windowLabel', __addon__.getLocalizedString(32383)) - menu_control = self.getControl(95) - uselocalfavorites = self.settings_dialog_manager.use_local_favorites(__addon__) - if uselocalfavorites == "true": - favoritenView = homepilot_views.FavoritenView(self.client, FAVORITEN_LOKAL, menu_control) + menu_control = self.getControl(statics.FOCUS_LIST_FAV) + xbmc.log("PMM--- GuiController: onInit: localfavorites: " + repr(self.uselocalfavorites_bool), + level=xbmc.LOGDEBUG) + if self.uselocalfavorites_bool: + favoriten_view = FavoritenView(self.client, self.uselocalfavorites_bool, menu_control) else: - favoritenView = homepilot_views.FavoritenView(self.client, FAVORITEN, menu_control) - title = self.__get_favorite_view_title(uselocalfavorites) + favoriten_view = FavoritenView(self.client, self.uselocalfavorites_bool, menu_control) + title = self.__get_favorite_view_title(self.uselocalfavorites_bool) self.setFocus(menu_control) - self.currentView = favoritenView - self.status_updater = StatusUpdater (favoritenView, menu_control, title, self) + self.currentView = favoriten_view + self.status_updater = StatusUpdater(favoriten_view, menu_control, title, self) self.status_updater.start() - def shutdown(self): """ closes the window @@ -188,470 +148,440 @@ def shutdown(self): self.close() def __get_favorite_view_title(self, useLocalFavorites): + """ + Abhängig von der gewählten Favoritenart, wird ein Titel gewählt. + :param useLocalFavorites: + :return: + """ + xbmc.log("PMM--- GuiController: __get_favorite_view_title: useLocalFavorites: " + repr(useLocalFavorites), + level=xbmc.LOGDEBUG) label = __addon__.getLocalizedString(32004) - if useLocalFavorites == "true": - label += " (" + __addon__.getLocalizedString(32385) + ")" + if useLocalFavorites: + fav_id = 32385 else: - label += " (" + __addon__.getLocalizedString(32382) + ")" + fav_id = 32382 + label += " (" + __addon__.getLocalizedString(fav_id) + ")" + xbmc.log("PMM--- GuiController: __get_favorite_view_title: id: " + repr(fav_id) + " label: " + repr(label), + level=xbmc.LOGDEBUG) return label - - # Helper Funktion für Debugging - def getViewstring(self, view): - if view == FAVORITEN_VIEW: - return "Favoriten View" - elif view == FAVORITEN_LOKAL_VIEW: - return "Favoriten Lokal View" - elif view == GERAETETYP_VIEW: - return "Geraetetyp View" - elif view == SZENENTYP_VIEW: - return "Szenentyp View" - elif view == SZENEN_MANUELL_VIEW: - return "Szenen Manu View" - elif view == SZENEN_NICHT_MANUELL_VIEW: - return "Szenen nicht Manu View" - elif view == SZENEN_ALLE_VIEW: - return "Szenen alle View" - elif view == SENSOREN_VIEW: - return "Sensoren View" - elif view == EMPTY_VIEW: - return "Einstellungen View" - else: - return "unbekannt:" + str(view) - - # Helper Funktion für Debugging - def getFocusIdstring(self, id): - if id == FOCUS_LIST_FAV: - return "FavMenü" - elif id == FOCUS_LIST_DEVICES: - return "GeraeteMenu" - elif id == FOCUS_LIST_DEVICE_TYP: - return "Geraetetypen" - elif id == FOCUS_LIST_DEVICE_GROUP: - return "GeraeteGruppen" - elif id == FOCUS_LIST_SCENES: - return "SzenenMenü" - elif id == FOCUS_LIST_SENSOR: - return "SensorMenue" - elif id == FOCUS_LIST_CONFIG: - return "ConfigMenue" - elif id == FOCUS_LIST_SENSORLIST: - return "Sensorliste" - elif id == FOCUS_LIST_FAVLIST_AKTOREN: - return "FavAktorenliste" - elif id == FOCUS_LIST_FAVLIST_SZENEN: - return "FavSzenenliste" - elif id == FOCUS_LIST_SCENE_LIST: - return "SzenenTypliste" - elif id == FOCUS_SCROLL_FAVLIST_DEV: - return "Scrollbar FavList Aktoren" - elif id == FOCUS_SCROLL_FAVLIST_SCN: - return "Scrollbar FavList Szenen" - elif id == FOCUS_SCROLL_DEVGROUP: - return "Scrollbar Geraetetyp Aktoren" - elif id == FOCUS_SCROLL_DEVLIST: - return "Scrollbar Aktoren,Sensoren" - elif id == FOCUS_SCROLL_SCENELIST: - return "Scrollbar Szenen" - #elif id == FOCUS_SCROLL_DEVTYP: - # return "SzenenTypliste" - else: - return "unbekannt:" + str(id) - - # Helper Funktion für Debugging - def getButtonCodestring(self, button): - if button == HP_VK_DOWN: - return "VK Down" - elif button == HP_VK_UP: - return "VK Up" - elif button == HP_VK_LEFT: - return "VK Left" - elif button == HP_VK_RIGHT: - return "VK Right" - elif button == HP_VK_ENTER: - return "VK Enter" - elif button == HP_VK_BACK: - return "VK Back" - elif button == HP_VK_ESC: - return "VK ESC" - elif button == HP_CEC_DOWN: - return "CEC Down" - elif button == HP_CEC_UP: - return "CEC Up" - elif button == HP_CEC_LEFT: - return "CEC Left" - elif button == HP_CEC_RIGHT: - return "CEC Right" - elif button == HP_CEC_ENTER: - return "CEC Ok" - elif button == HP_CEC_BACK: - return "CEC Exit" - else: - return "unbekannt:" + str(button) - - # Helper Funktion für Debugging - def getActionIDstring(self, actionid): - if actionid == AID_DOWN: - return "Down" - elif actionid == AID_UP: - return "Up" - elif actionid == AID_LEFT: - return "Left" - elif actionid == AID_RIGHT: - return "Right" - elif actionid == AID_ENTER: - return "Enter" - elif actionid == AID_BACK: - return "Back" - elif actionid == AID_ESC: - return "ESC" - else: - return "unbekannt:" + str(actionid) - - + # Helper Funktion um Quellcode besser lesen zu können def switchDevicetypeBack(self, view, focusid): + """ + Funktion um die Gerätetypenliste anzuzeigen, nachdem man von der Geräteliste zurück geht. + :param view: + :param focusid: + :return: + """ self.__show_geraetetyp_view() self.__set_geraetetyp_list_focus(view) self.setFocusId(focusid) - + # Helper Funktion um Quellcode besser lesen zu können def isKeyBackbutton(self, button): - return button == HP_VK_BACK or button == HP_VK_LEFT or button == HP_CEC_BACK or button == HP_CEC_LEFT - + xbmc.log("PMM--- GuiController: isKeyBackbutton button: " + repr(button), level=xbmc.LOGDEBUG) + return button == statics.HP_VK_BACK or button == statics.HP_VK_LEFT or button == statics.HP_CEC_BACK or button == statics.HP_CEC_LEFT + def isActionBack(self, actionid): - return actionid == AID_LEFT or actionid == AID_BACK - + # Left Button pressed + xbmc.log("PMM--- GuiController: isActionBack actionid: " + repr(actionid), level=xbmc.LOGDEBUG) + return actionid == statics.AID_LEFT or actionid == statics.AID_BACK or actionid == statics.ACTION_NAV_BACK + # Helper Funktion um Quellcode besser lesen zu können def isKeyEnterbutton(self, button): - return button == HP_CEC_ENTER or button == MOUSE_LEFT_CLICK or button == HP_VK_ENTER + xbmc.log("PMM--- GuiController: isKeyEnterbutton button: " + repr(button), level=xbmc.LOGDEBUG) + return button == statics.HP_CEC_ENTER or button == statics.MOUSE_LEFT_CLICK or button == statics.HP_VK_ENTER def isActionEnter(self, actionid): - return actionid == AID_ENTER - + xbmc.log("PMM--- GuiController: isActionEnter actionid: " + repr(actionid), level=xbmc.LOGDEBUG) + return actionid == statics.AID_ENTER + # Eventhandling def onAction(self, action): + """ + Wird aufgerufen wenn eine Action (Taste) ausgeführt wird. + :param action: + :return: + """ view = self.currentView.get_id() focusid = self.getFocusId() - - # Debug Log Start Event Handling - xbmc.log("PMM---default.py-- START View: " + self.getViewstring(view) + " - Action: " + self.getActionIDstring(action.getId()) + " - FocusId: " + self.getFocusIdstring(focusid) + " - Szene: " + str(self._isScene), level=xbmc.LOGNOTICE) - - #Shutdown ermöglichen, wenn in oberer Schicht - if focusid == FOCUS_LIST_FAV or focusid == FOCUS_LIST_DEVICES or focusid == FOCUS_LIST_SCENES or focusid == FOCUS_LIST_SENSOR or focusid == FOCUS_LIST_CONFIG: - if action.getId() == AID_BACK: + deviceset = statics.DEVICESET + scene_set = statics.SCENE_SET + action_id = action.getId() + # Shutdown ermöglichen, wenn in oberer Schicht + self.on_action_shutdown(focusid, action_id) + + xbmc.log("PMM--- GuiController: onAction: \nview: " + str(view) + + "\naction:" + repr(action.getId()) + + "\nfocusid: " + repr(focusid), level=xbmc.LOGDEBUG) + + # Menüsteuerung, abhängig von der aktuellen View wird eine Methode geöffnet, die den aktuellen Focus, + # also die Auswahl, und die gedrückte Taste, Action, bekommt. + if view == statics.FAVORITEN_VIEW or view == statics.FAVORITEN_LOKAL_VIEW: # Favoriten + self.on_action_favoriten(action_id, focusid) + elif view == statics.GERAETETYP_VIEW: # Geräte + self.on_action_geraetetyp_view(action_id, focusid) + elif view in deviceset: # Ein Device ist offen + self.on_action_deviceset(action_id, focusid, view) + elif view == statics.DEVICE_GRUPPEN_VIEW: #Gerätegruppen + self.on_action_device_gruppen_view(action_id, focusid) + elif view in scene_set: # Szene offen + self.on_action_szene_set(action_id, focusid) + elif view == statics.SZENENTYP_VIEW: + self.on_action_szenentypview(action_id, focusid) + elif view == statics.SENSOREN_VIEW: # Sensoren + self.on_action_sensoren_view(action_id, focusid) + + # XBMC has lost focus, set a new one + if self.getFocusId() == 0 and action.getButtonCode() != 0: + self.on_action_focuslost(view) + + def on_action_favoriten(self, action_id, focusid): + xbmc.log("PMM--- GuiController: on_action_favoriten", level=xbmc.LOGDEBUG) + if self.isActionBack(action_id): + if focusid == statics.FOCUS_LIST_FAV: # Zurück ins Menü + self.setFocusId(statics.FOCUS_LIST_FAV) + + def on_action_geraetetyp_view(self, action_id, focusid): + xbmc.log("PMM--- GuiController: on_action_geraetetyp_view", level=xbmc.LOGDEBUG) + if self.isActionBack(action_id): + if focusid == statics.FOCUS_LIST_DEVICE_TYP: + self.setFocusId(statics.FOCUS_LIST_DEVICES) + elif self.isActionEnter(action_id): + if focusid == statics.FOCUS_LIST_DEVICE_TYP: + self.focus_list_device_typ() + elif focusid == statics.FOCUS_LIST_DEVICE_GROUP: + self.focus_list_device_group() + + def on_action_deviceset(self, action_id, focusid, view): + xbmc.log("PMM--- GuiController: on_action_deviceset", level=xbmc.LOGDEBUG) + if self.isActionBack(action_id): + if focusid == statics.FOCUS_SCROLL_DEVLIST: + con = self.getControl(statics.FOCUS_LIST_SENSORLIST) + self.setFocus(con) + elif focusid != statics.FOCUS_SCROLL_SCENELIST: + self.switchDevicetypeBack(view, statics.FOCUS_LIST_DEVICE_TYP) + + def on_action_device_gruppen_view(self, action_id, focusid): + xbmc.log("PMM--- GuiController: on_action_device_gruppen_view", level=xbmc.LOGDEBUG) + if self.isActionBack(action_id): + group_id = self.currentView.get_id() + self.__set_gruppen_list_focus(group_id) + + def on_action_szene_set(self, action_id, focusid): + xbmc.log("PMM--- GuiController: on_action_szene_set", level=xbmc.LOGDEBUG) + if self.isActionBack(action_id): + if focusid == statics.FOCUS_LIST_SCENE_LIST: + scene_id = self.currentView.stype + self.__set_scenen_list_focus(scene_id) + if focusid == statics.FOCUS_SCROLL_SCENELIST: + controll = self.getControl(statics.FOCUS_LIST_SCENE_LIST) + self.setFocus(controll) + elif self.isActionEnter(action_id): + self.setFocusId(statics.FOCUS_LIST_SCENES) + + def on_action_sensoren_view(self, action_id, focusid): + xbmc.log("PMM--- GuiController: on_action_sensoren_view", level=xbmc.LOGDEBUG) + if self.isActionBack(action_id): + if focusid == statics.FOCUS_LIST_SENSOR: + self.setFocusId(statics.FOCUS_LIST_SENSOR) + elif focusid == statics.FOCUS_SCROLL_DEVLIST: + con = self.getControl(statics.FOCUS_LIST_SENSORLIST) + self.setFocus(con) + + def on_action_shutdown(self, focusid, action): + """ + Ermöglicht den Shutdow, , egal was gerade für eine View oder Fenster präsent sind. + """ + if focusid in statics.SHUTDOWN_SET: + if action == statics.AID_BACK or action == statics.ACTION_NAV_BACK: xbmc.log("PMM---default.py-- shutdown via FocusID", level=xbmc.LOGNOTICE) self.shutdown() # Mit ESC wird Addon komplett geschlossen - if action.getId() == AID_ESC: + if action == statics.AID_ESC: xbmc.log("PMM---default.py-- shutdown via ESC", level=xbmc.LOGNOTICE) self.shutdown() - - #Menüsteuerung - #Favoriten - if view == FAVORITEN_VIEW or view == FAVORITEN_LOKAL_VIEW: - if self.isActionBack(action.getId()): - self.setFocusId(FOCUS_LIST_FAV) - elif view == GERAETETYP_VIEW: - if not self.isActionBack(action.getId()): - if focusid == FOCUS_LIST_DEVICES: - self._isScene = False - elif focusid == FOCUS_LIST_SCENES: - self._isScene = True - if self.isActionBack(action.getId()): - if self._isScene == False: - self.setFocusId(FOCUS_LIST_DEVICES) - else: - self.setFocusId(FOCUS_LIST_SCENES) - elif self.isActionEnter(action.getId()): - if self._isScene == False: - self.__on_action_geraetetypview(action) - else: - xbmc.log("PMM--- Enter hilfe Quellcode schauen", level=xbmc.LOGNOTICE) - elif view == DEVICE_ROLLADEN_VIEW: - if self.isActionBack(action.getId()): - self.switchDevicetypeBack(view, FOCUS_LIST_DEVICE_TYP) - elif view == DEVICE_SCHALTER_VIEW: - if self.isActionBack(action.getId()): - self.switchDevicetypeBack(view, FOCUS_LIST_DEVICE_TYP) - elif view == DEVICE_DIMMER_VIEW: - if self.isActionBack(action.getId()): - self.switchDevicetypeBack(view, FOCUS_LIST_DEVICE_TYP) - elif view == DEVICE_THERMOSTATE_VIEW: - if self.isActionBack(action.getId()): - self.switchDevicetypeBack(view, FOCUS_LIST_DEVICE_TYP) - elif view == DEVICE_TORE_VIEW: - if self.isActionBack(action.getId()): - self.switchDevicetypeBack(view, FOCUS_LIST_DEVICE_TYP) - elif view == DEVICE_ALLE_VIEW: - if self.isActionBack(action.getId()): - self.switchDevicetypeBack(view, FOCUS_LIST_DEVICE_TYP) - elif view == DEVICE_GRUPPEN_VIEW: - if self.isActionBack(action.getId()): - group_id = self.currentView.get_group() - self.__show_geraetetyp_view() - self.__set_gruppen_list_focus(group_id) - #Szenen - elif view == SZENENTYP_VIEW: - self._isScene = True - if self.isActionBack(action.getId()): - self.setFocusId(FOCUS_LIST_SCENES) - elif self.getFocusId() == FOCUS_LIST_DEVICE_TYP and self.isActionEnter(action.getId()):#Gerätetyptabelle - type_list = self.getControl(FOCUS_LIST_DEVICE_TYP) - item = type_list.getSelectedItem() - next_view = self.currentView.handle_click(item) - self.currentView.remove_everything(self) - szenen_view = homepilot_views.SzenenListView(self.client, next_view) - menu_control = self.getControl(FOCUS_LIST_SCENES) - szenen_view.visualize(self, __addon__) - self.currentView = szenen_view - self.status_updater.set_current_view(szenen_view, menu_control) - elif view == SZENEN_MANUELL_VIEW or view == SZENEN_NICHT_MANUELL_VIEW or view == SZENEN_ALLE_VIEW: - if self.isActionBack(action.getId()): - self.setFocusId(FOCUS_LIST_SCENES) - #Sensoren - elif view == SENSOREN_VIEW: - if self.isActionBack(action.getId()): - self.setFocusId(FOCUS_LIST_SENSOR) - #Einstellungen - #elif view == EMPTY_VIEW: - - #XBMC has lost focus, set a new one - if self.getFocusId() == 0 and action.getButtonCode() != 0: - xbmc.log("PMM---default.py-- focus lost", level=xbmc.LOGNOTICE) - if view == SENSOREN_VIEW: - self.setFocusId(5) - elif view == FAVORITEN_VIEW or view == FAVORITEN_LOKAL_VIEW: - self.setFocusId(255) - elif view == GERAETETYP_VIEW: - self.setFocusId(257) - else: - self.setFocusId(95) - - # Debug Log END Event Handling - xbmc.log("PMM---default.py-- ENDE View: " + self.getViewstring(view) + " - Action: " + self.getActionIDstring(action.getId()) + " - FocusId: " + self.getFocusIdstring(focusid) + " - Szene: " + str(self._isScene), level=xbmc.LOGNOTICE) - #xbmc.log("PMM---default.py-- ENDE View: " + self.getViewstring(view) + " - Action: " + self.getActionIDstring(action.getId()) + " - Key: " + self.getButtonCodestring(action.getButtonCode()) + " - FocusId: " + self.getFocusIdstring(focusid) + " - Szene: " + str(self._isScene), level=xbmc.LOGNOTICE) - - def __on_action_geraetetypview (self, action): - if self.getFocusId() == FOCUS_LIST_DEVICE_TYP: - # Einmal tiefer ins Menü - if self.isActionEnter(action.getId()):#Gerätetyptabelle - gruppen_list = self.getControl(FOCUS_LIST_DEVICE_TYP) - position = gruppen_list.getSelectedItem() - next_view = self.currentView.handle_click(position) - if next_view is not None: - self.currentView.remove_everything(self) - geraete_view = homepilot_views.ParametrizedGeraeteView(self.client, next_view) - menu_control = self.getControl(FOCUS_LIST_DEVICES) - geraete_view.visualize(self, __addon__) - self.currentView = geraete_view - self.status_updater.set_current_view(geraete_view, menu_control) - elif self.getFocusId() == FOCUS_LIST_DEVICE_GROUP: - # Einmal tiefer ins Menü - if self.isActionEnter(action.getId()):#Gruppentabelle - gruppen_list = self.getControl(FOCUS_LIST_DEVICE_GROUP) - position = gruppen_list.getSelectedPosition() - list_item = gruppen_list.getListItem(position) - gruppen_id = list_item.getProperty("gid") - gruppen_name = list_item.getLabel() - self.currentView.remove_everything(self) - geraete_view = homepilot_views.ParametrizedGeraeteView(self.client, GRUPPEN, gruppen_id) - menu_control = self.getControl(FOCUS_LIST_DEVICES) - geraete_view.visualize(self, __addon__, gruppen_name) - self.currentView = geraete_view - self.status_updater.set_current_view(geraete_view, menu_control) - - def __on_action_scenetypview (self, action): - if self.getFocusId() == FOCUS_LIST_DEVICE_TYP: - # Einmal tiefer ins Menü - if self.isActionEnter(action.getId()):#Gerätetyptabelle - gruppen_list = self.getControl(FOCUS_LIST_DEVICE_TYP) - position = gruppen_list.getSelectedItem() - next_view = self.currentView.handle_click(position) - if next_view is not None: - self.currentView.remove_everything(self) - geraete_view = homepilot_views.ParametrizedGeraeteView(self.client, next_view) - menu_control = self.getControl(FOCUS_LIST_DEVICES) - geraete_view.visualize(self, __addon__) - self.currentView = geraete_view - self.status_updater.set_current_view(geraete_view, menu_control) + + def focus_list_device_typ(self): + xbmc.log("PMM--- focus_list_device_typ", level=xbmc.LOGDEBUG) + # Einmal tiefer ins Menü + gruppen_list = self.getControl(statics.FOCUS_LIST_DEVICE_TYP) + position = gruppen_list.getSelectedItem() + next_view = self.currentView.handle_click(position) + if next_view is not None: + self.currentView.remove_everything(self) + geraete_view = ParametrizedGeraeteView(self.client, next_view) + menu_control = self.getControl(statics.FOCUS_LIST_DEVICES) + geraete_view.visualize(self, __addon__) + self.currentView = geraete_view + self.status_updater.set_current_view(geraete_view, menu_control) + + def focus_list_device_group(self): + xbmc.log("PMM--- focus_list_device_group", level=xbmc.LOGDEBUG) + gruppen_list = self.getControl(statics.FOCUS_LIST_DEVICE_GROUP) + position = gruppen_list.getSelectedPosition() + list_item = gruppen_list.getListItem(position) + gruppen_id = list_item.getProperty("gid") + gruppen_name = list_item.getLabel() + self.currentView.remove_everything(self) + geraete_view = ParametrizedGeraeteView(self.client, statics.GRUPPEN, gruppen_id) + menu_control = self.getControl(statics.FOCUS_LIST_DEVICES) + geraete_view.visualize(self, __addon__, gruppen_name) + self.currentView = geraete_view + self.status_updater.set_current_view(geraete_view, menu_control) + + def on_action_szenentypview(self, action_id, focus_id): + xbmc.log("PMM--- GuiController: on_action_szenentypview", level=xbmc.LOGDEBUG) + if self.isActionBack(action_id): + self.setFocusId(statics.FOCUS_LIST_SCENES) + elif self.isActionEnter(action_id): + type_list = self.getControl(statics.FOCUS_LIST_DEVICE_TYP) + item = type_list.getSelectedItem() + next_view = self.currentView.handle_click(item) + self.currentView.remove_everything(self) + szenen_view = SzenenListView(self.client, next_view) + menu_control = self.getControl(statics.FOCUS_LIST_SCENES) + szenen_view.visualize(self, __addon__) + self.currentView = szenen_view + self.status_updater.set_current_view(szenen_view, menu_control) + + def on_action_focuslost(self, view): + if view == statics.SENSOREN_VIEW: + xbmc.log("PMM--- GuiController: onAction: LostFocus to 5", level=xbmc.LOGDEBUG) + self.setFocusId(5) + elif view == statics.FAVORITEN_VIEW or view == statics.FAVORITEN_LOKAL_VIEW: + xbmc.log("PMM--- GuiController: onAction: LostFocus to 255", level=xbmc.LOGDEBUG) + self.setFocusId(255) + elif view == statics.GERAETETYP_VIEW: + xbmc.log("PMM--- GuiController: onAction: LostFocus to 257", level=xbmc.LOGDEBUG) + self.setFocusId(257) + else: + xbmc.log("PMM--- GuiController: onAction: LostFocus to 95", level=xbmc.LOGDEBUG) + self.setFocusId(95) def onFocus(self, control): - if not self._wait_for_visualization: - if control == FOCUS_LIST_CONFIG: #menüpunkt Einstellungen - if self.currentView.get_id() != EMPTY_VIEW: - self.currentView.remove_everything (self) - empty_view = homepilot_views.EmptyView() - menu_control = self.getControl(FOCUS_LIST_CONFIG) - empty_view.visualize(self, __addon__) - self.currentView = empty_view - self.status_updater.set_current_view(empty_view, menu_control) - elif control == FOCUS_LIST_FAV: #Menüpunkt Favoriten - if self.currentView.get_id() != FAVORITEN_VIEW and self.currentView.get_id != FAVORITEN_LOKAL_VIEW: + """ + Bekommt eine ID (controll) und öffnet die passende View. Das passiert aus dem Hauptmenü. + :param control: + :return: + """ + xbmc.log("PMM--- GuiController: onFocus: control: " + str(control) + " Last View ID: " + str( + self.currentView.get_id()), + level=xbmc.LOGDEBUG) + if not self._wait_for_visualization and control is not None: + if control == statics.FOCUS_LIST_CONFIG: # menüpunkt Einstellungen + xbmc.log("PMM--- GuiController: onFocus: control: Einstellungen", level=xbmc.LOGDEBUG) + if self.currentView.get_id != statics.EMPTY_VIEW: + self.__show_config_view() + elif control == statics.FOCUS_LIST_FAV: # Menüpunkt Favoriten + xbmc.log("PMM--- GuiController: onFocus: control: Favoriten", level=xbmc.LOGDEBUG) + if self.currentView.get_id() != statics.FAVORITEN_VIEW and self.currentView.get_id != statics.FAVORITEN_LOKAL_VIEW: self.__show_favoriten_view() - elif control == FOCUS_LIST_DEVICES: #Menüpunkt Geräte - if self.currentView.get_id() != GERAETETYP_VIEW: - previous_view = self.currentView.get_id() + elif control == statics.FOCUS_LIST_DEVICES: # Menüpunkt Geräte + xbmc.log("PMM--- GuiController: onFocus: control: Geräte", level=xbmc.LOGDEBUG) + if self.currentView.get_id() != statics.GERAETETYP_VIEW: self.__show_geraetetyp_view() - elif control == FOCUS_LIST_SENSOR: # Menüpunkt sensoren - if self.currentView.get_id() != SENSOREN_VIEW: - self.currentView.remove_everything (self) - geraete_view = homepilot_views.ParametrizedGeraeteView(self.client, SENSOREN) - menu_control = self.getControl(FOCUS_LIST_SENSOR) - geraete_view.visualize (self, __addon__) + elif control == statics.FOCUS_LIST_SCENES: # Menüpunkt Szenentypen + xbmc.log("PMM--- GuiController: onFocus: control: Szenentypen", level=xbmc.LOGDEBUG) + if self.currentView.get_id() != statics.SZENENTYP_VIEW: + self.__show_szenentyp_view() + elif control == statics.FOCUS_LIST_SENSOR: # Menüpunkt sensoren + xbmc.log("PMM--- GuiController: onFocus: control: Sensoren", level=xbmc.LOGDEBUG) + if self.currentView.get_id() != statics.SENSOREN_VIEW: + geraete_view = ParametrizedGeraeteView(self.client, statics.SENSOREN) + self.currentView.remove_everything(self) + menu_control = self.getControl(statics.FOCUS_LIST_SENSOR) + geraete_view.visualize(self, __addon__) self.currentView = geraete_view self.status_updater.set_current_view(geraete_view, menu_control) - elif control == FOCUS_LIST_SCENES: # Menüpunkt Szenentypen - if self.currentView.get_id() != SZENENTYP_VIEW: - self.__show_szenentyp_view() + else: + xbmc.log("PMM--- GuiController: onFocus: Keine neue View. ", level=xbmc.LOGDEBUG) def onClick(self, control): + """ + Öffnet ein Window für ein Gerät oder eine Szene. + :param control: + :return: + """ view_id = self.currentView.get_id() - if control == FOCUS_LIST_SENSORLIST: - if view_id == SENSOREN_VIEW: - geraete_listcontrol = self.getControl(FOCUS_LIST_SENSORLIST) - list_item = geraete_listcontrol.getSelectedItem() - did = list_item.getProperty("did") + xbmc.log("PMM--- GuiController: onClick: " + str(control) + + "\nview_id: " + repr(view_id), level=xbmc.LOGDEBUG) + + if control == statics.FOCUS_LIST_SENSORLIST: + xbmc.log("PMM--- GuiController: onClick: FOCUS_LIST_SENSORLIST", level=xbmc.LOGDEBUG) + geraete_listcontrol = self.getControl(statics.FOCUS_LIST_SENSORLIST) + list_item = geraete_listcontrol.getSelectedItem() + did = list_item.getProperty(statics.DID) + if view_id == statics.SENSOREN_VIEW: meter_window = MeterWindow('device_window.xml', __cwd__, client=self.client, did=did, parent=self) self.status_updater.set_current_window(meter_window) meter_window.doModal() - elif view_id == DEVICE_ALLE_VIEW or view_id == DEVICE_ROLLADEN_VIEW or view_id == DEVICE_SCHALTER_VIEW or view_id == DEVICE_DIMMER_VIEW \ - or view_id == DEVICE_THERMOSTATE_VIEW or view_id == DEVICE_TORE_VIEW: - geraete_listcontrol = self.getControl(FOCUS_LIST_SENSORLIST) - list_item = geraete_listcontrol.getSelectedItem() - did = list_item.getProperty("did") + elif view_id == statics.DEVICE_ALLE_VIEW or view_id == statics.DEVICE_ROLLADEN_VIEW or \ + view_id == statics.DEVICE_SCHALTER_VIEW or view_id == statics.DEVICE_DIMMER_VIEW \ + or view_id == statics.DEVICE_THERMOSTATE_VIEW or view_id == statics.DEVICE_TORE_VIEW \ + or view_id == statics.DEVICE_GRUPPEN_VIEW: self.__open_device_window(did) - elif view_id == FAVORITEN_VIEW or view_id == FAVORITEN_LOKAL_VIEW: - if control == 255: - geraete_listcontrol = self.getControl(255) + elif view_id == statics.FAVORITEN_VIEW or view_id == statics.FAVORITEN_LOKAL_VIEW: + xbmc.log("PMM--- GuiController: onClick: FAVORITEN_VIEW", level=xbmc.LOGDEBUG) + if control == statics.FOCUS_LIST_FAVLIST_AKTOREN: + geraete_listcontrol = self.getControl(statics.FOCUS_LIST_FAVLIST_AKTOREN) list_item = geraete_listcontrol.getSelectedItem() - did = list_item.getProperty("did") + did = list_item.getProperty(statics.DID) self.__open_device_window(did) - elif control == 264: - scene_list_control = self.getControl(264) + elif control == statics.FOCUS_LIST_FAVLIST_SZENEN: + scene_list_control = self.getControl(statics.FOCUS_LIST_FAVLIST_SZENEN) list_item = scene_list_control.getSelectedItem() position = scene_list_control.getSelectedPosition - sid = list_item.getProperty("sid") - useLocalFavorites = self.settings_dialog_manager.use_local_favorites(__addon__) - self.__open_scene_window(sid, position, useLocalFavorites) - elif control == FOCUS_LIST_CONFIG: #Menüpunkt Einstellungen + sid = list_item.getProperty(statics.SID) + self.__open_scene_window(sid, position, self.uselocalfavorites_bool) + elif control == statics.FOCUS_LIST_CONFIG: # Menüpunkt Einstellungen + xbmc.log("PMM--- GuiController: onClick: FOCUS_LIST_CONFIG", level=xbmc.LOGDEBUG) self._wait_for_visualization = True self.settings_dialog_manager.update_ip_address(__addon__) ip_address = self.settings_dialog_manager.get_ip_address(__addon__) + if self.settings_dialog_manager.use_local_favorites(__addon__) == "true": + self.uselocalfavorites_bool = True + else: + self.uselocalfavorites_bool = False self._wait_for_visualization = False self.client.set_ip_address(ip_address) - elif control == 258:# show szenen detail view - scene_list_control = self.getControl(258) + elif control == statics.FOCUS_LIST_SCENE_LIST: # show szenen detail view + xbmc.log("PMM--- GuiController: onClick: FOCUS_LIST_SCENE_LIST", level=xbmc.LOGDEBUG) + scene_list_control = self.getControl(statics.FOCUS_LIST_SCENE_LIST) list_item = scene_list_control.getSelectedItem() position = scene_list_control.getSelectedPosition() sceneId = list_item.getProperty("sid") - useLocalFavorites = self.settings_dialog_manager.use_local_favorites(__addon__) - self.__open_scene_window(sceneId, position, useLocalFavorites) + self.__open_scene_window(sceneId, position, self.uselocalfavorites_bool) - - def __set_geraetetyp_list_focus (self, previeous_view): + def __set_scenen_list_focus(self, scene_id): + xbmc.log("PMM--- GuiController: __set_scenen_list_focus: scene_id: " + repr(scene_id), level=xbmc.LOGDEBUG) + try: + self.__show_szenentyp_view() + list_control = self.getControl(257) + self.setFocus(list_control) + if scene_id == statics.SZENEN_MANUELL: + list_control.selectItem(0) + elif scene_id == statics.SZENEN_NICHT_MANUELL: + list_control.selectItem(1) + elif scene_id == statics.SZENEN_ALLE: + list_control.selectItem(2) + except ValueError: + xbmc.log("PMM--- GuiController: __set_scenen_list_focus: ValueError!", level=xbmc.LOGERROR) + + def __set_geraetetyp_list_focus(self, previeous_view): + xbmc.log("PMM--- GuiController: __set_geraetetyp_list_focus: previeous_view: " + str(previeous_view), + level=xbmc.LOGDEBUG) list_control = self.getControl(257) + xbmc.log("PMM--- GuiController: __set_geraetetyp_list_focus: list_control: \n" + str(list_control), + level=xbmc.LOGDEBUG) try: - for i in range(0, 6): + for i in range(0, int(list_control.size())): list_item = list_control.getListItem(i) - type = list_item.getProperty("type") + type = list_item.getProperty(statics.TYPE) if previeous_view == type + "_view": list_control.selectItem(i) return - #unfortunately there seem to be no way to get the number of list items in a control - #if a non-existent index is accessed a value error is thrown - except ValueError,e: - pass - - - def _set_szenenlistfocus(self, position): - list_control = self.getControl(258) - self.setFocus(list_control) - list_control.selectItem(position) - + except ValueError: + xbmc.log("PMM--- GuiController: __set_geraetetyp_list_focus: ValueError!", level=xbmc.LOGERROR) - def __set_gruppen_list_focus (self, gruppen_id): - list_control = self.getControl(4) + def __set_gruppen_list_focus(self, gruppen_id): + xbmc.log("PMM--- GuiController: __set_gruppen_list_focus: gruppen_id:" + str(gruppen_id), level=xbmc.LOGDEBUG) + list_control = self.getControl(statics.FOCUS_LIST_DEVICE_GROUP) i = 0 - while True: + run = True + while run: try: item = list_control.getListItem(i) gid = item.getProperty("gid") - xbmc.log("gruppenlist " + str(gid), level=xbmc.LOGWARNING) + xbmc.log("PMM--- GuiController: __set_gruppen_list_focus: i:" + repr(i) + + "\nGID " + str(gid) + + "\nitem" + repr(item), level=xbmc.LOGDEBUG) if gid == str(gruppen_id): list_control.selectItem(i) - return + run = False + i += 1 except RuntimeError: - self.setFocusId(4) - return + xbmc.log("PMM--- GuiController: __set_geraetetyp_list_focus: RuntimeError.", level=xbmc.LOGERROR) + self.setFocusId(statics.FOCUS_LIST_DEVICE_GROUP) + run = False def __show_favoriten_view(self): - self.currentView.remove_everything (self) - useLocalFavorites = self.settings_dialog_manager.use_local_favorites(__addon__) - title = self.__get_favorite_view_title(useLocalFavorites) - menu_control = self.getControl(FOCUS_LIST_FAV) - if useLocalFavorites == "true": - geraete_view = homepilot_views.FavoritenView(self.client, FAVORITEN_LOKAL, menu_control) - else: - geraete_view = homepilot_views.FavoritenView(self.client, FAVORITEN, menu_control) - geraete_view.visualize (self, __addon__, title) - self.currentView = geraete_view - self.status_updater.set_current_view(geraete_view, menu_control) - + xbmc.log("PMM--- GuiController: __show_favoriten_view: useLocalFav: " + str( + self.uselocalfavorites_bool) + " currenView: " + repr(self.currentView), level=xbmc.LOGDEBUG) + self.currentView.remove_everything(self) + title = self.__get_favorite_view_title(self.uselocalfavorites_bool) + menu_control = self.getControl(statics.FOCUS_LIST_FAV) + favoriten_view = FavoritenView(self.client, self.uselocalfavorites_bool, menu_control) + favoriten_view.visualize(self, __addon__, title) + self.currentView = favoriten_view + self.status_updater.set_current_view(favoriten_view, menu_control) def __show_geraetetyp_view(self): - self.currentView.remove_everything (self) - geraetetyp_view = homepilot_views.GeraetetypView(self.client) - menu_control = self.getControl(96) - menu_control.controlRight(self.getControl(257)) - geraetetyp_view.visualize (self, __addon__) + xbmc.log("PMM--- GuiController: __show_geraetetyp_view: ", level=xbmc.LOGDEBUG) + geraetetyp_view = GeraetetypView(self.client) + self.currentView.remove_everything(self) + menu_control = self.getControl(statics.FOCUS_LIST_DEVICES) + menu_control.controlRight(self.getControl(statics.FOCUS_LIST_DEVICE_TYP)) + geraetetyp_view.visualize(self, __addon__) self.currentView = geraetetyp_view self.status_updater.set_current_view(geraetetyp_view, menu_control) - def __show_szenentyp_view(self): - menu_control = self.getControl(94) - self.currentView.remove_everything (self) - status_view = homepilot_views.SzenentypView() + xbmc.log("PMM--- GuiController: __show_szenentyp_view: ", level=xbmc.LOGDEBUG) + status_view = SzenentypView() + menu_control = self.getControl(statics.FOCUS_LIST_SCENES) + self.currentView.remove_everything(self) self.currentView = status_view self.status_updater.set_current_view(status_view, menu_control) - menu_control.controlRight(self.getControl(257)) - self.currentView.visualize (self, __addon__) - + menu_control.controlRight(self.getControl(statics.FOCUS_LIST_DEVICE_TYP)) + self.currentView.visualize(self, __addon__) + + def __show_config_view(self): + xbmc.log("PMM--- GuiController: __show_config_view: ", level=xbmc.LOGDEBUG) + self.currentView.remove_everything(self) + empty_view = EmptyView() + menu_control = self.getControl(statics.FOCUS_LIST_CONFIG) + empty_view.visualize(self, __addon__) + self.currentView = empty_view + self.status_updater.set_current_view(empty_view, menu_control) def __open_device_window(self, did): - useLocalFavorites = self.settings_dialog_manager.use_local_favorites(__addon__) - local_favs = False - if useLocalFavorites == "true": - local_favs = True + xbmc.log("PMM--- GuiController: __open_device_window: use_local_favs: " + str( + self.uselocalfavorites_bool) + " did: " + str(did), level=xbmc.LOGDEBUG) try: device = self.client.get_device_by_id(did) dgroup = device.get_devicegroup() if dgroup == 2 or dgroup == 4 or dgroup == 8: - percent_window = PercentageWindow('device_window.xml', __cwd__, client=self.client, device=device, parent=self, local_favs= local_favs) + percent_window = PercentageWindow('device_window.xml', __cwd__, client=self.client, device=device, + parent=self, local_favs=self.uselocalfavorites_bool) self.status_updater.set_current_window(percent_window) percent_window.doModal() elif dgroup == 1: - switch_window = SwitchWindow('device_window.xml', __cwd__, client=self.client, device=device, parent=self, local_favs= local_favs) - self.status_updater.set_current_window(switch_window) - switch_window.doModal() + percent_window = SwitchWindow('device_window.xml', __cwd__, client=self.client, device=device, + parent=self, local_favs=self.uselocalfavorites_bool) + self.status_updater.set_current_window(percent_window) + percent_window.doModal() elif dgroup == 5: - percent_window = DegreeWindow('device_window.xml', __cwd__, client=self.client, device=device, parent=self, local_favs= local_favs) + percent_window = DegreeWindow('device_window.xml', __cwd__, client=self.client, device=device, + parent=self, local_favs=self.uselocalfavorites_bool) self.status_updater.set_current_window(percent_window) percent_window.doModal() except Exception, e: - xbmc.log("Fehler beim Öffnen einer Detailsicht: " + str(e), level=xbmc.LOGWARNING) - error_window = ErrorWindow('device_window.xml', __cwd__, parent=self) + xbmc.log("PMM--- GuiController: __open_device_window: Fehler beim Öffnen einer Detailsicht: " + str(e.args), + level=xbmc.LOGWARNING) + error_window = ErrorWindow() error_window.doModal() def __open_scene_window(self, sceneId, position, useLocalFavorites): - scene_window = SzenenDetailWindow('scene_window.xml', __cwd__, client=self.client, scene_id=sceneId, - previous_list_position=position, addon=__addon__, parent=self, - use_local_favorites=useLocalFavorites) - self.status_updater.set_current_window(scene_window) - scene_window.doModal() + xbmc.log("PMM--- GuiController: __open_scene_window ", level=xbmc.LOGDEBUG) + scene_window = szene.SzenenDetailWindow('scene_window.xml', __cwd__, client=self.client, scene_id=sceneId, + previous_list_position=position, addon=__addon__, parent=self, + use_local_favorites=useLocalFavorites) + self.status_updater.set_current_window(scene_window) + scene_window.doModal() if __name__ == "__main__": + xbmc.log("PMM--- default: START ", level=xbmc.LOGDEBUG) window = GuiController('homepilot.xml', __cwd__) window.doModal() - diff --git a/script.homepilot/resources/lib/Models/__init__.py b/script.homepilot/resources/lib/Models/__init__.py new file mode 100644 index 0000000..f23368e --- /dev/null +++ b/script.homepilot/resources/lib/Models/__init__.py @@ -0,0 +1 @@ +__author__ = 'dominik' diff --git a/script.homepilot/resources/lib/Models/action.py b/script.homepilot/resources/lib/Models/action.py new file mode 100644 index 0000000..56d513a --- /dev/null +++ b/script.homepilot/resources/lib/Models/action.py @@ -0,0 +1,48 @@ +import xbmc +from .. import statics +from .. import homepilot_utils + + +class Action: + def __init__(self, action): + xbmc.log("Action: __init__: action: " + str(action), level=xbmc.LOGDEBUG) + self._did = action[statics.DID] + self._type = action[statics.TYPE] + self._name = action[statics.NAME] + self._description = action[statics.DESCRIPTION] + self._iconset = action[statics.ICONSET] + self._iconsetInverted = action[statics.ICONSET_INVERTED] + self._cmdId = action[statics.CMID] + if statics.PARAM in action: + self._param = action[statics.PARAM] + else: + self._param = None + + def get_did(self): + return self._did + + def get_name(self): + return self._name + + def get_description(self): + return self._description + + def get_icon(self): + xbmc.log("Action: get_icon: _cmdId" + repr(self._cmdId), level=xbmc.LOGDEBUG) + if self._cmdId == 666: + return homepilot_utils.get_action_sensor_icon() + elif self._param is not None: + return homepilot_utils.get_icon(self._iconset, self._iconsetInverted, self._param, type) + elif self._cmdId == 10 or self._cmdId == 2: + return homepilot_utils.get_icon(self._iconset, self._iconsetInverted, 100, type) + else: + return homepilot_utils.get_icon(self._iconset, self._iconsetInverted, 0, type) + + def get_cmdId(self): + return self._cmdId + + def get_device_group(self): + return self._type + + def get_param(self): + return self._param diff --git a/script.homepilot/resources/lib/Models/automation.py b/script.homepilot/resources/lib/Models/automation.py new file mode 100644 index 0000000..cd46555 --- /dev/null +++ b/script.homepilot/resources/lib/Models/automation.py @@ -0,0 +1,65 @@ +import xbmc +from .. import statics + + +class Automation: + def __init__(self, properties): + xbmc.log("Automation: __init__: properties: " + str(properties), level=xbmc.LOGDEBUG) + self.properties = properties + + def get_dawn(self): + return self.properties[statics.DAWN] + + def get_dusk(self): + return self.properties[statics.DUSK] + + def get_time(self): + return self.properties[statics.TIME] + + def get_wind(self): + return self.properties[statics.WIND] + + def get_temperature(self): + return self.properties[statics.TEMPERATUR] + + def get_generic(self): + return self.properties[statics.GENERIC] + + def get_trigger(self): + return self.properties[statics.TRIGGER] + + def get_closing_contact(self): + return self.properties[statics.CLOSINGCONTACT] + + def get_smoke(self): + return self.properties[statics.SMOKE] + + def get_sun(self): + return self.properties[statics.SUN] + + def get_manual(self): + return self.properties[statics.MANUAL] + + def get_dust(self): + return self.properties[statics.DUST] + + def get_favored(self): + return self.properties[statics.FAVORED] + + def get_smartphone(self): + return self.properties[statics.SMARTPHONE] + + def get_motion(self): + return self.properties[statics.MOTION] + + def get_temperator(self): + return self.properties[statics.TEMPERATOR] + + def get_warning(self): + return self.properties[statics.WARNING] + + def get_rain(self): + return self.properties[statics.RAIN] + + def get_props(self): + return self.properties diff --git a/script.homepilot/resources/lib/Models/device.py b/script.homepilot/resources/lib/Models/device.py new file mode 100644 index 0000000..b34e7b3 --- /dev/null +++ b/script.homepilot/resources/lib/Models/device.py @@ -0,0 +1,50 @@ +import xbmc +from .. import statics +import automation +import home_pilot_base_object + + +class Device(home_pilot_base_object.HomePilotBaseObject): + def __init__(self, device): + home_pilot_base_object.HomePilotBaseObject.__init__(self, device) + self.device = device + self._available = device[statics.AVAIL] + self._hasErrors = device[statics.HAS_ERRORS] != 0 + self._groups = device[statics.GROUPS] + self._favoredId = device[statics.FAVORED_ID] + self._automated = device[statics.AUTOMATED] != 0 + self._properties = device[statics.PROPERTIES] + + def has_errors(self): + """ + returns if the device has errors + """ + return self._hasErrors + + def is_available(self): + """ + returns if the device is available + """ + return self._available + + def get_favoredId (self): + return self._favoredId + + def get_icon(self): + icon = home_pilot_base_object.HomePilotBaseObject.get_icon(self) + # xbmc.log("device: get_automation: get_icon" + repr(icon) + + # "\nis_available:" + repr(self.is_available()) + + # "\nhas_errors" + repr(self.has_errors()), level=xbmc.LOGDEBUG) + if self.is_available() is False or self.has_errors(): + icon = "warnung_72.png" + return icon + + def is_automated(self): + return self._automated + + def get_automationen(self): + xbmc.log("device: get_automation: properties" + str(self._properties), level=xbmc.LOGDEBUG) + return automation.Automation(self._properties) + + def is_favored(self): + return self._favoredId != -1 diff --git a/script.homepilot/resources/lib/Models/group.py b/script.homepilot/resources/lib/Models/group.py new file mode 100644 index 0000000..3855220 --- /dev/null +++ b/script.homepilot/resources/lib/Models/group.py @@ -0,0 +1,21 @@ +import xbmc +from .. import statics + + +class Group: + def __init__(self, group): + self.group = group + self._name = group[statics.NAME] + self._description = group[statics.DESCRIPTION] + self._gid = group[statics.GID] + xbmc.log("Group: __init__: group: name: " + repr(self._name) + + "\ngid: " + repr(self._gid), level=xbmc.LOGDEBUG) + + def get_group_id(self): + return self._gid + + def get_name(self): + return self._name + + def get_description(self): + return self._description diff --git a/script.homepilot/resources/lib/Models/home_pilot_base_object.py b/script.homepilot/resources/lib/Models/home_pilot_base_object.py new file mode 100644 index 0000000..5f8c48c --- /dev/null +++ b/script.homepilot/resources/lib/Models/home_pilot_base_object.py @@ -0,0 +1,76 @@ +import xbmc +from .. import statics +from .. import homepilot_utils + + +class HomePilotBaseObject: + """ + class which represents a single device + """ + + def __init__(self, device): + """ + constructor of the class + Arguments: + device -- dictionary with the device attributes + """ + self.device = device + self.name = device[statics.NAME] + self.descriprion = device[statics.DESCRIPTION] + self.did = device[statics.DID] + self.position = device[statics.POSITION] + self.deviceGroup = device[statics.DEVICE_GROUP] + self.status = device[statics.POSITION] + self.sync = device[statics.SYNC] + self.icon_set = device[statics.ICONSETKEY] + self.icon_set_inverted = device.get(statics.ICON_SET_INVERTED) + + def get_name(self): + """ + returns the device name + """ + return self.name + + def get_device_id(self): + """ + return the device id + """ + return self.did + + def get_position(self): + """ + gets the current position of the device on a scale from 0 to 100 + """ + return self.position + + def get_devicegroup(self): + """ + returns the devicegroup the device belongs to + Schalter:1, Sensoren:3, Rollos:2, Thermostate:5, Dimmer:4, Tore:8 + """ + return self.deviceGroup + + def get_status(self): + """ + returns the current status + """ + return self.status + + def get_description(self): + return self.descriprion + + def get_sync(self): + return self.sync + + def get_iconset_inverted(self): + return homepilot_utils.get_iconset_inverted(self.icon_set_inverted) + + def get_icon(self): + icon = homepilot_utils.get_icon(self.icon_set, self.icon_set_inverted, self.position, self.deviceGroup) + xbmc.log("HomePilotBaseObject: get_icon: icon: " + repr(icon), level=xbmc.LOGDEBUG) + return icon + + def get_display_value(self): + position = self.get_position() + group = self.get_devicegroup() + return homepilot_utils.get_display_value(position, group) diff --git a/script.homepilot/resources/lib/Models/meter.py b/script.homepilot/resources/lib/Models/meter.py new file mode 100644 index 0000000..6c45724 --- /dev/null +++ b/script.homepilot/resources/lib/Models/meter.py @@ -0,0 +1,19 @@ +import home_pilot_base_object +import xbmc + + +class Meter(home_pilot_base_object.HomePilotBaseObject): + def __init__(self, device, data): + """ + constructor of the class + + Arguments: + + meter -- dictionary with the sensor attributes + """ + home_pilot_base_object.HomePilotBaseObject.__init__(self, device) + xbmc.log("Meter: __init__: device: " + str(device), level=xbmc.LOGDEBUG) + self._data = data + + def get_data(self): + return self._data diff --git a/script.homepilot/resources/lib/Models/scene.py b/script.homepilot/resources/lib/Models/scene.py new file mode 100644 index 0000000..da1b1e7 --- /dev/null +++ b/script.homepilot/resources/lib/Models/scene.py @@ -0,0 +1,63 @@ +import xbmc +from .. import statics +import automation +import action + + +class Scene: + def __init__(self, scene): + self._sid = scene[statics.SID] + self._name = scene[statics.NAME] + self._description = scene[statics.DESCRIPTION] + self._is_executable = scene[statics.IS_EXECUTABLE] + self._sync = scene[statics.SYNC] + self._groups = scene[statics.GROUPS] + if 'actions' in scene: + self._actions = scene[statics.ACTIONS] + self._properties = scene[statics.PROPERTIES] + self._is_active = scene[statics.IS_ACTIVE] + self._favored = scene[statics.FAVORED_ID] + + def get_id(self): + return self._sid + + def get_name(self): + return self._name + + def get_actions_as_list(self): + xbmc.log("Scene: get_actions_as_list: ", level=xbmc.LOGDEBUG) + return map(lambda x: action.Action(x), self._actions) + + def get_automationen(self): + return automation.Automation(self._properties) + + def is_executable(self): + return self._is_executable == 1 + + def is_active(self): + return self._is_active == 1 + + def is_favored(self): + return self._favored > 0 + + def get_sync(self): + return self._sync + + def get_description(self): + return self._description + + def set_favored(self): + xbmc.log("Scene: set_favored: ", level=xbmc.LOGDEBUG) + self._favored = 1 + + def set_unfavored(self): + xbmc.log("Scene: set_unfavored: ", level=xbmc.LOGDEBUG) + self._favored = 0 + + def set_activ(self): + xbmc.log("Scene: set_activ: ", level=xbmc.LOGDEBUG) + self._is_active = 1 + + def set_inactive(self): + xbmc.log("Scene: set_inactive: ", level=xbmc.LOGDEBUG) + self._is_active = 0 diff --git a/script.homepilot/resources/lib/Views/__init__.py b/script.homepilot/resources/lib/Views/__init__.py new file mode 100644 index 0000000..f23368e --- /dev/null +++ b/script.homepilot/resources/lib/Views/__init__.py @@ -0,0 +1 @@ +__author__ = 'dominik' diff --git a/script.homepilot/resources/lib/Views/base_view.py b/script.homepilot/resources/lib/Views/base_view.py new file mode 100644 index 0000000..8222a8e --- /dev/null +++ b/script.homepilot/resources/lib/Views/base_view.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import xbmc +import os +import xbmcaddon + +__addon__ = xbmcaddon.Addon(id='script.homepilot') +__addon_path__ = __addon__.getAddonInfo('path').decode("utf-8") +images_device = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media', 'devices') +_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media') + +schalter_img = os.path.join(images_device, 'steckdose_72_0.png') +rollo_img = os.path.join(images_device, 'rollladen2_72_50.png') +dimmer_img = os.path.join(images_device, 'birne1_72_100.png') +thermostat_img = os.path.join(images_device, 'thermostat_72_100.png') +tore_img = os.path.join(images_device, 'garage_72_50.png') +logo_img = os.path.join(_images, 'logo-homepilot-klein.png') +szene_img = os.path.join(_images, 'szene_32.png') +szene_img_deact = os.path.join(_images, 'szene_32_deactivated.png') +scene_manual = os.path.join(_images, 'scene_manual2.png') +scene_non_manual = os.path.join(_images, 'scene_no_manual2.png') + + +class BaseView: + def __init__(self): + xbmc.log("BaseView: __init__", level=xbmc.LOGDEBUG) + + def get_communication_error_label(self): + return __addon__.getLocalizedString(32381) diff --git a/script.homepilot/resources/lib/Views/empty_view.py b/script.homepilot/resources/lib/Views/empty_view.py new file mode 100644 index 0000000..c175c6b --- /dev/null +++ b/script.homepilot/resources/lib/Views/empty_view.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import xbmc + +import xbmcgui +import base_view +from .. import homepilot_utils +from .. import statics + + +class EmptyView(base_view.BaseView): + def __init__(self): + base_view.BaseView.__init__(self) + self.einstellungen_control = None + self.label = None + + def get_id(self): + return statics.empty_view_id + + def remove_everything(self, window): + xbmc.log("EmptyView: remove_everything: ", level=xbmc.LOGDEBUG) + window.removeControls([self.einstellungen_control, self.label]) + + def visualize(self, window, addon): + xbmc.log("EmptyView: visualize: ", level=xbmc.LOGDEBUG) + MESSAGE_SETTINGS_DIALOG = base_view.__addon__.getLocalizedString(32384) + self.einstellungen_control = homepilot_utils.get_title_control(32008, addon) + self.label = xbmcgui.ControlLabel(460, 250, 590, 40, MESSAGE_SETTINGS_DIALOG, alignment=0x00000002) + window.addControls([self.einstellungen_control, self.label]) + return [self.einstellungen_control, self.label] + + def handle_click(self, control): + xbmc.log("EmptyView: handle_click: ", level=xbmc.LOGDEBUG) + pass diff --git a/script.homepilot/resources/lib/Views/favoriten_view.py b/script.homepilot/resources/lib/Views/favoriten_view.py new file mode 100644 index 0000000..65e6d18 --- /dev/null +++ b/script.homepilot/resources/lib/Views/favoriten_view.py @@ -0,0 +1,253 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import xbmcgui +import xbmc +import os +import base_view +from .. import homepilot_utils +from .. import statics +from .. import local_favorites + + +class FavoritenView(base_view.BaseView): + def __init__(self, home_pilot_client, useLocalFavoritesBool, menu_control, group=None): + base_view.BaseView.__init__(self) + self.client = home_pilot_client + self.total = 0 + self.controldict = {} + if useLocalFavoritesBool: + self.type = statics.FAVORITEN_LOKAL + else: + self.type = statics.FAVORITEN + self.useLocalFavoritesBool = useLocalFavoritesBool + self.list_item_dict = {} + self.hp_error = False + self.errorcontrol = None + self.errorcontrol2 = None + self.group = group + self.menu_control = menu_control + self.scene_group = None + self.geraete_group = None + self.szenen_control = None + self.title_control = None + xbmc.log("FavoritenView: __init__: type:" + repr(self.type), level=xbmc.LOGDEBUG) + + def get_id(self): + return str(self.type) + "_view" + + def get_group(self): + return self.group + + def visualize(self, window, addon, title=None): + xbmc.log("FavoritenView: visualize: titel: "+repr(title), level=xbmc.LOGDEBUG) + if title is None: + self.title_control = homepilot_utils.get_title_control(self.type, addon) + else: + self.title_control = homepilot_utils.get_title_control(title, addon) + + label = addon.getLocalizedString(statics.SZENEN) + self.szenen_control = xbmcgui.ControlLabel(400, 380, 600, 75, label, font="font16") + window.addControls([self.title_control, self.szenen_control]) + homepilot_is_reachable = self.client.ping + xbmc.log("reachable " + str(homepilot_is_reachable), level=xbmc.LOGNOTICE) + self.scene_group = window.getControl(262) + self.geraete_group = window.getControl(254) + if not homepilot_is_reachable: + xbmc.log("not reachable " + str(homepilot_is_reachable), level=xbmc.LOGNOTICE) + self.hp_error = True + errorlabel = self.get_communication_error_label() + self.errorcontrol = xbmcgui.ControlLabel(400, 250, 700, 100, errorlabel, font="font12") + window.addControl(self.errorcontrol) + self.errorcontrol2 = xbmcgui.ControlLabel(400, 450, 700, 100, errorlabel, font="font12") + window.addControl(self.errorcontrol2) + else: + self.hp_error = False + self.__visualize_devices(window, addon) + + def __visualize_devices(self, window, addon): + xbmc.log("FavoritenView: __visualize_devices: DEVICES", level=xbmc.LOGDEBUG) + try: + devices = self.__get_devices() + if len(devices) > 0: + self.geraete_list = window.getControl(255) + self.geraete_list.reset() + self.__add_listitems(devices) + self.geraete_group.setVisible(True) + xbmc.log("FavoritenView: __visualize_devices: SCENES", level=xbmc.LOGDEBUG) + scenes = self.__get_scenes() + if len(scenes) > 0: + self.scene_list = window.getControl(264) + self.scene_list.reset() + self.__add_scene_item(scenes) + self.scene_group.setVisible(True) + + if len(devices) > 0: + self.menu_control.controlRight(self.geraete_list) + elif len(scenes) > 0: + self.menu_control.controlRight(self.scene_list) + + except Exception as inst: + self.hp_error = True + errorlabel = self.get_communication_error_label() + self.errorcontrol = xbmcgui.ControlLabel(400, 250, 600, 75, errorlabel) + window.addControl(self.errorcontrol) + xbmc.log("FavoritenView: __visualize_devices: Exception: " + str(inst.message), level=xbmc.LOGWARNING) + + def __add_listitems(self, devs): + xbmc.log("FavoritenView: __add_listitems: ", level=xbmc.LOGDEBUG) + devices = self.sort_set(devs) + try: + for device in devices: + item = xbmcgui.ListItem(label=device.get_name(), label2=device.get_display_value()) + icon_name = device.get_icon() + xbmc.log("FavoritenView: __add_listitems: device: " + repr(device.get_favoredId()) + + "\ndevicename: " + repr(device.get_name()) + + "\nicon_name: " + repr(icon_name), level=xbmc.LOGDEBUG) + item.setIconImage(os.path.join(base_view.images_device, icon_name)) + item.setProperty(statics.DESCRIPTION, device.get_description()) + item.setProperty(statics.DID, str(device.get_device_id())) + item.setProperty(statics.SYNC, str(device.get_sync())) + self.list_item_dict[device.get_device_id()] = item + self.geraete_list.addItem(item) + except Exception, e: + xbmc.log("FavoritenView: __add_listitems: Exception: " + str(e.args), level=xbmc.LOGWARNING) + + def __add_scene_item(self, scens): + xbmc.log("FavoritenView: __add_scene_item: ", level=xbmc.LOGDEBUG) + scenes = self.sort_set(scens) + for scene in scenes: + xbmc.log("FavoritenView: __add_scene_item: scenes: " + repr(scene.get_id()) + + "\nscene name: " + repr(scene.get_name()), level=xbmc.LOGDEBUG) + scene_item = xbmcgui.ListItem(label=scene.get_name()) + scene_item.setIconImage(base_view.szene_img) + scene_item.setProperty(statics.SID, str(scene.get_id())) + scene_item.setProperty(statics.DESCRIPTION, scene.get_description()) + self.scene_list.addItem(scene_item) + + def sort_set(self, set_to_sort): + return sorted(set_to_sort, key=lambda obt: obt.get_name()) + + def __get_devices(self): + xbmc.log("FavoritenView: __get_devices: suseLocalFavoritesBool:" + repr(self.useLocalFavoritesBool), level=xbmc.LOGDEBUG) + if self.useLocalFavoritesBool: + devices = self.__get_local_favorit_devices() + else: + devices = self.client.get_favorite_devices() + return devices + + def __get_scenes(self): + xbmc.log("FavoritenView: __get_scenes: useLocalFavoritesBool: " + repr(self.useLocalFavoritesBool), level=xbmc.LOGDEBUG) + if self.useLocalFavoritesBool: + scenes = self.__get_local_favorit_scenes() + else: + scenes = self.client.get_favorite_scenes() + return scenes + + def __get_local_favorit_devices(self): + local_favorites_device_ids = local_favorites.get_devices_as_set() + all_devices = self.client.get_devices() + favorite_devices = [] + xbmc.log("FavoritenView: __get_local_favorit_devices: local_favorites_device_ids: " + + repr(local_favorites_device_ids), level=xbmc.LOGDEBUG) + + if local_favorites_device_ids is not None: + for device in all_devices: + if device.get_device_id() in local_favorites_device_ids: + xbmc.log("FavoritenView: __get_local_favorit_devices: device id: " + repr(device.get_device_id()), level=xbmc.LOGDEBUG) + favorite_devices.append(device) + return set(favorite_devices) + + def __get_local_favorit_scenes(self): + local_favorites_scene_ids = local_favorites.get_scenes_as_set() + all_scenes = self.client.get_scenes() + favorite_scenes = [] + xbmc.log("FavoritenView: __get_local_favorit_scenes: local_favorites_scene_ids: " + + repr(local_favorites_scene_ids), level=xbmc.LOGDEBUG) + + if local_favorites_scene_ids is not None: + for scene in all_scenes: + if scene.get_id() in local_favorites_scene_ids: + xbmc.log("FavoritenView: __get_local_favorit_scenes: scene id: " + repr(scene.get_id()), level=xbmc.LOGDEBUG) + favorite_scenes.append(scene) + return set(favorite_scenes) + + def remove_everything(self, window): + xbmc.log("FavoritenView: remove_everything: errorcontrol: " + repr(self.errorcontrol) + + "\nerrorcontrol2: " + repr(self.errorcontrol2) + + "\nhp_error: " + repr(self.hp_error) + + "\ntitle_control: " +repr(self.title_control) + + "\nszenen_control: " +repr(self.szenen_control) + + "\nscene_group: " +repr(self.scene_group) + + "\ngeraete_group: " +repr(self.geraete_group), level=xbmc.LOGDEBUG) + if not self.hp_error: + if self.errorcontrol is not None: + window.removeControl(self.errorcontrol) + if self.errorcontrol2 is not None: + window.removeControl(self.errorcontrol2) + if self.title_control is not None: + xbmc.log("FavoritenView: remove_everything: title_control: "+repr(self.title_control.getId()), level=xbmc.LOGDEBUG) + window.removeControl(self.title_control) + if self.szenen_control is not None: + xbmc.log("FavoritenView: remove_everything: title_control: "+repr(self.szenen_control.getId()), level=xbmc.LOGDEBUG) + window.removeControl(self.szenen_control) + if self.scene_group is not None: + xbmc.log("FavoritenView: remove_everything: title_control: "+repr(self.scene_group.getId()), level=xbmc.LOGDEBUG) + self.scene_group.setVisible(False) + if self.geraete_group is not None: + xbmc.log("FavoritenView: remove_everything: title_control: "+repr(self.geraete_group.getId()), level=xbmc.LOGDEBUG) + self.geraete_group.setVisible(False) + + def update(self, window, addon, menuControl): + xbmc.log("FavoritenView: update: hp_error: " + repr(self.hp_error), level=xbmc.LOGDEBUG) + try: + if self.hp_error: + self.remove_everything(window) + self.visualize(window, addon) + else: + new_devices = self.__get_devices() + list_item_ids = self.list_item_dict.keys() + xbmc.log("FavoritenView: update:\n new_devices: " + repr(new_devices) + + "\nlist_item_ids: " + repr(list_item_ids) + + "\nlist_item_dict: " + repr(self.list_item_dict), level=xbmc.LOGDEBUG) + for new_device in new_devices: + new_sync_value = str(new_device.get_sync()) + device_listitem = self.list_item_dict.get(new_device.get_device_id()) + xbmc.log("FavoritenView: update: device_listitem: " + repr(device_listitem), level=xbmc.LOGDEBUG) + if device_listitem is not None: + list_item_ids.remove(new_device.get_device_id()) + old_sync_value = device_listitem.getProperty(statics.SYNC) + old_status = device_listitem.getLabel2() + new_status = new_device.get_display_value() + if new_sync_value != old_sync_value or old_status != new_status: + new_icon = new_device.get_icon() + if old_status != new_status: + device_listitem.setLabel2(new_status) + device_listitem.setIconImage(os.path.join(base_view.images_device, new_icon)) + else: + device_listitem.setIconImage(os.path.join(base_view.images_device, new_icon)) + old_label = device_listitem.getLabel() + new_label = new_device.get_name() + if old_label != new_label.encode('utf8'): + device_listitem.setLabel(new_label) + old_label2 = device_listitem.getProperty(statics.DESCRIPTION) + new_label2 = new_device.get_description() + if old_label2 != new_label2.encode('utf8'): + device_listitem.setProperty(statics.DESCRIPTION, new_label2) + else: + # add new listitem + xbmc.log("FavoritenView: update: device_listitem is None.", level=xbmc.LOGDEBUG) + self.__add_listitems([new_device]) + # remove items from list when devices are no longer present + # workaround implementation as the ControlList.removeItem didn't work + if len(list_item_ids) > 0: + self.list_item_dict = {} + self.geraete_list.reset() + self.__add_listitems(new_devices) + self.hp_error = False + except Exception, e: + if not self.hp_error: + xbmc.log("FavoritenView: update: Exception: " + repr(self.type) + " " + repr(e.message), level=xbmc.LOGERROR) + self.remove_everything(window) + self.visualize(window, addon) + self.hp_error = True diff --git a/script.homepilot/resources/lib/Views/geraetetyp_view.py b/script.homepilot/resources/lib/Views/geraetetyp_view.py new file mode 100644 index 0000000..01d4fee --- /dev/null +++ b/script.homepilot/resources/lib/Views/geraetetyp_view.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os +import xbmcaddon +import xbmcgui +import xbmc +from .. import homepilot_utils +from .. import statics +import base_view + +__addon__ = xbmcaddon.Addon(id='script.homepilot') +__addon_path__ = __addon__.getAddonInfo('path').decode("utf-8") +_images_device = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media', 'devices') +_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media') + + +class GeraetetypView(base_view.BaseView): + def __init__(self, home_pilot_client): + base_view.BaseView.__init__(self) + self.client = home_pilot_client + self.geraetetypen_list = None + self.rolladen_item = None + self.schalter_item = None + self.dimmer_item = None + self.thermostat_item = None + self.tore_item = None + self.alle_item = None + self.gruppen_control = None + self.errorcontrol = None + self.geraetelabel_control = None + self.gruppen_group_control = None + + def get_id(self): + return statics.geraetetyp_view_id + + def remove_everything(self, window): + xbmc.log("GeraetetypView: remove_everything: window: " + str(window), level=xbmc.LOGDEBUG) + window.removeControls([self.geraetelabel_control, self.gruppen_control]) + self.geraetetypen_list.setVisible(False) + self.gruppen_group_control.setVisible(False) + if self.errorcontrol is not None: + window.removeControl(self.errorcontrol) + + def visualize(self, window, addon): + xbmc.log("GeraetetypView: visualize: window: " + str(window), level=xbmc.LOGDEBUG) + self.geraetelabel_control = homepilot_utils.get_title_control(32009, addon) + + self.geraetetypen_list = window.getControl(257) + self.geraetetypen_list.reset() + + self.__build_device_groups(self.__get_device_groups(), addon) + + self.alle_item = xbmcgui.ListItem(label=addon.getLocalizedString(statics.ALLE)) + self.alle_item.setIconImage(base_view.logo_img) + self.alle_item.setProperty(statics.TYPE, str(statics.ALLE)) + self.geraetetypen_list.addItem(self.alle_item) + + self.geraetetypen_list.setVisible(True) + + label = addon.getLocalizedString(32015) + self.gruppen_control = xbmcgui.ControlLabel(400, 380, 600, 75, label, font="font16") + window.addControls([self.geraetelabel_control, self.gruppen_control]) + + gruppen_list = window.getControl(4) + gruppen_list.reset() + self.gruppen_group_control = window.getControl(251) + try: + groups = self.client.get_groups() + if len(groups) > 0: + for group in groups: + xbmc.log("GeraetetypView: visualize: group: " + repr(group.get_name()), level=xbmc.LOGDEBUG) + group_item = xbmcgui.ListItem(label=group.get_name()) + group_item.setProperty("gid", str(group.get_group_id())) + gruppen_list.addItem(group_item) + + self.gruppen_group_control.setPosition(350, 420) + self.gruppen_group_control.setVisible(True) + self.errorcontrol = None + else: + errorlabel = addon.getLocalizedString(32380) + self.errorcontrol = xbmcgui.ControlLabel(450, 450, 600, 75, errorlabel) + window.addControl(self.errorcontrol) + except Exception, e: + xbmc.log("GeraetetypView: visualize: " + str(e), level=xbmc.LOGERROR) + errorlabel = self.get_communication_error_label() + self.errorcontrol = xbmcgui.ControlLabel(450, 450, 600, 75, errorlabel) + window.addControl(self.errorcontrol) + + def __get_device_groups(self): + xbmc.log("GeraetetypView: __get_device_groups:", level=xbmc.LOGDEBUG) + devices = self.client.get_devices() + device_groups = [] + for device in devices: + device_groups.append(device.get_devicegroup()) + return set(device_groups) + + def __build_device_groups(self, device_groups, addon): + if 2 in device_groups: + self.rolladen_item = xbmcgui.ListItem(label=addon.getLocalizedString(statics.ROLLADEN)) + self.rolladen_item.setIconImage(base_view.rollo_img) + self.rolladen_item.setProperty(statics.TYPE, str(statics.ROLLADEN)) + self.geraetetypen_list.addItem(self.rolladen_item) + + if 1 in device_groups: + self.schalter_item = xbmcgui.ListItem(label=addon.getLocalizedString(statics.SCHALTER)) + self.schalter_item.setIconImage(base_view.schalter_img) + self.schalter_item.setProperty(statics.TYPE, str(statics.SCHALTER)) + self.geraetetypen_list.addItem(self.schalter_item) + + if 4 in device_groups: + self.dimmer_item = xbmcgui.ListItem(label=addon.getLocalizedString(statics.DIMMER)) + self.dimmer_item.setIconImage(base_view.dimmer_img) + self.dimmer_item.setProperty(statics.TYPE, str(statics.DIMMER)) + self.geraetetypen_list.addItem(self.dimmer_item) + + if 5 in device_groups: + self.thermostat_item = xbmcgui.ListItem(label=addon.getLocalizedString(statics.THERMOSTATE)) + self.thermostat_item.setIconImage(base_view.thermostat_img) + self.thermostat_item.setProperty(statics.TYPE, str(statics.THERMOSTATE)) + self.geraetetypen_list.addItem(self.thermostat_item) + + if 8 in device_groups: + self.tore_item = xbmcgui.ListItem(label=addon.getLocalizedString(statics.TORE)) + self.tore_item.setIconImage(base_view.tore_img) + self.tore_item.setProperty(statics.TYPE, str(statics.TORE)) + self.geraetetypen_list.addItem(self.tore_item) + + def handle_click(self, position): + xbmc.log("GeraetetypView: visualize: handle_click: " + str(position) + + "\nposition.getProperty(statics.TYPE):" + repr(position.getProperty(statics.TYPE)), level=xbmc.LOGDEBUG) + if position.getProperty(statics.TYPE) == str(statics.ALLE): + return statics.ALLE + elif position.getProperty(statics.TYPE) == str(statics.ROLLADEN): + return statics.ROLLADEN + elif position.getProperty(statics.TYPE) == str(statics.SCHALTER): + return statics.SCHALTER + elif position.getProperty(statics.TYPE) == str(statics.DIMMER): + return statics.DIMMER + elif position.getProperty(statics.TYPE) == str(statics.THERMOSTATE): + return statics.THERMOSTATE + elif position.getProperty(statics.TYPE) == str(statics.TORE): + return statics.TORE + pass diff --git a/script.homepilot/resources/lib/Views/parametrized_geraete_view.py b/script.homepilot/resources/lib/Views/parametrized_geraete_view.py new file mode 100644 index 0000000..37d856d --- /dev/null +++ b/script.homepilot/resources/lib/Views/parametrized_geraete_view.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os +import xbmcgui +import xbmc +import base_view +from .. import homepilot_utils +from .. import statics + +device_types = {statics.SCHALTER: 1, statics.ROLLADEN: 2, statics.SENSOREN: 3, statics.DIMMER: 4, + statics.THERMOSTATE: 5, statics.TORE: 8} + + +class ParametrizedGeraeteView(base_view.BaseView): + def __init__(self, home_pilot_client, device_type, group=None): + base_view.BaseView.__init__(self) + self.client = home_pilot_client + self.total = 0 + self.controldict = {} + self.type = device_type + self.list_item_dict = {} + self.hp_error = False + self.errorcontrol = None + self.group = group + self.title_control = None + self.gerate_group_control = None + + def get_id(self): + return str(self.type) + "_view" + + def get_group(self): + return self.group + + def visualize(self, window, addon, title=None): + xbmc.log("ParametrizedGeraeteView: visualize: window: " + str(window), level=xbmc.LOGDEBUG) + if title is None: + self.title_control = homepilot_utils.get_title_control(self.type, addon) + else: + self.title_control = homepilot_utils.get_title_control(title, addon) + window.addControl(self.title_control) + if not hasattr(self, "gerate_group_control"): + self.gerate_group_control = window.getControl(252) + window.setProperty('GeraeteScrollHeight', '480') + elif self.gerate_group_control is None: + xbmc.log( + "ParametrizedGeraeteView: visualize: gerate_group_control will be None. ", level=xbmc.LOGWARNING) + self.gerate_group_control = window.getControl(252) + window.setProperty('GeraeteScrollHeight', '480') + homepilot_is_reachable = self.client.ping + if not homepilot_is_reachable: + self.hp_error = True + errorlabel = self.get_communication_error_label() + self.errorcontrol = xbmcgui.ControlLabel(400, 250, 700, 100, errorlabel) + window.addControl(self.errorcontrol) + else: + self.hp_error = False + self.__visualize_devices(window, addon) + + def __visualize_devices(self, window, addon): + xbmc.log("ParametrizedGeraeteView: __visualize_devices: window: " + str(window), level=xbmc.LOGDEBUG) + try: + devices = self.__get_devices() + if len(devices) > 0: + self.geraete_list = window.getControl(5) + if self.type == statics.SENSOREN: + self.geraete_list.controlLeft(self.__get_menu_control(window)) + else: + xbmc.log( + "ParametrizedGeraeteView: __visualize_devices: set a fake control to prevent xbmc from setting it back to the main menu. ", + level=xbmc.LOGDEBUG) + control = window.getControl(111) + self.geraete_list.controlLeft(control) + self.geraete_list.reset() + self.__add_listitems(devices) + xbmc.log("ParametrizedGeraeteView: __visualize_devices: listItems geladen. ", level=xbmc.LOGDEBUG) + if self.gerate_group_control is not None: + self.gerate_group_control.setPosition(350, 100) + self.gerate_group_control.setVisible(True) + else: + xbmc.log("ParametrizedGeraeteView: __visualize_devices: gerate_group_control is None. ", + level=xbmc.LOGWARNING) + if self.type != statics.FAVORITEN and self.type != statics.FAVORITEN_LOKAL and self.type != statics.SENSOREN: + window.setFocus(self.geraete_list) + except Exception as inst: + self.hp_error = True + errorlabel = self.get_communication_error_label() + self.errorcontrol = xbmcgui.ControlLabel(400, 250, 600, 75, errorlabel, font="font13") + window.addControl(self.errorcontrol) + xbmc.log("ParametrizedGeraeteView: __visualize_devices: Exception: " + str(inst), level=xbmc.LOGWARNING) + + def __get_menu_control(self, window): + xbmc.log("ParametrizedGeraeteView: __get_menu_control: window: " + str(window), level=xbmc.LOGDEBUG) + if self.type == statics.SENSOREN: + return window.getControl(97) + else: + return window.getControl(96) + + def __add_listitems(self, devices): + xbmc.log("ParametrizedGeraeteView: __add_listitems: devices: " + repr(devices), level=xbmc.LOGDEBUG) + try: + for device in devices: + devicename = device.get_name() + device_display_value = device.get_display_value() + if self.type == statics.SENSOREN: + item = xbmcgui.ListItem(label=devicename) + else: + item = xbmcgui.ListItem(label=devicename, label2=device_display_value) + icon_name = device.get_icon() + item.setIconImage(os.path.join(base_view.images_device, icon_name)) + item.setProperty("description", device.get_description()) + item.setProperty("did", str(device.get_device_id())) + item.setProperty("sync", str(device.get_sync())) + self.list_item_dict[device.get_device_id()] = item + self.geraete_list.addItem(item) + except Exception, e: + xbmc.log("ParametrizedGeraeteView: __add_listitems: Exception: " + str(e.args), level=xbmc.LOGWARNING) + + def __get_devices(self): + xbmc.log("ParametrizedGeraeteView: __get_devices: ", level=xbmc.LOGDEBUG) + if self.type == statics.ALLE: + devices = self.client.get_devices() + elif self.type == statics.SENSOREN: + devices = self.client.get_meters() + elif self.type == statics.GRUPPEN: + devices = self.client.get_devices_by_group(self.group) + else: + devices = self.client.get_devices_by_device_group(device_types[self.type]) + return devices + + def remove_everything(self, window): + xbmc.log("ParametrizedGeraeteView: remove_everything: window: " + str(window), level=xbmc.LOGDEBUG) + if self.hp_error and self.errorcontrol is not None: + window.removeControls([self.errorcontrol, self.title_control]) + self.errorcontrol = None + try: + window.removeControls([self.title_control]) + except RuntimeError, e: + xbmc.log("Control does not exist in window: " + str(e), level=xbmc.LOGWARNING) + if self.gerate_group_control is not None: + self.gerate_group_control.setVisible(False) + + def update(self, window, addon, menuControl): + xbmc.log("ParametrizedGeraeteView: update: window: " + str(window) + + "\nhp_error: " + repr(self.hp_error), level=xbmc.LOGDEBUG) + try: + if self.hp_error: + self.remove_everything(window) + self.visualize(window, addon) + else: + new_devices = self.__get_devices() + list_item_ids = self.list_item_dict.keys() + xbmc.log("ParametrizedGeraeteView: update:\n new_devices: " + repr(new_devices) + + "\nlist_item_ids: " + repr(list_item_ids) + + "\nlist_item_dict: " + repr(self.list_item_dict), level=xbmc.LOGDEBUG) + for new_device in new_devices: + new_sync_value = str(new_device.get_sync()) + device_listitem = self.list_item_dict.get(new_device.get_device_id()) + if device_listitem is not None: + list_item_ids.remove(new_device.get_device_id()) + old_sync_value = device_listitem.getProperty("sync") + old_status = device_listitem.getLabel2() + new_status = new_device.get_display_value() + if new_sync_value != old_sync_value or old_status != new_status: + new_icon = new_device.get_icon() + if old_status != new_status: + device_listitem.setLabel2(new_status) + device_listitem.setIconImage(os.path.join(base_view.images_device, new_icon)) + else: + device_listitem.setIconImage(os.path.join(base_view.images_device, new_icon)) + old_label = device_listitem.getLabel() + new_label = new_device.get_name() + if old_label != new_label.encode('utf8'): + device_listitem.setLabel(new_label) + old_label2 = device_listitem.getProperty("description") + new_label2 = new_device.get_description() + if old_label2 != new_label2.encode('utf8'): + device_listitem.setProperty("description", new_label2) + else: + xbmc.log("ParametrizedGeraeteView: update: device_listitem is None: " + repr(device_listitem), level=xbmc.LOGDEBUG) + self.__add_listitems([new_device]) + # remove items from list when devices are no longer present + # workaround implementation as the ControlList.removeItem didn't work + if len(list_item_ids) > 0: + self.list_item_dict = {} + self.geraete_list.reset() + self.__add_listitems(new_devices) + self.hp_error = False + except Exception, e: + xbmc.log("Problem beim Updaten des views: " + str(self.type) + " " + str(e), level=xbmc.LOGERROR) + self.remove_everything(window) + self.visualize(window, addon) + self.hp_error = True + + def _get_list_item_position(self, item): + xbmc.log("ParametrizedGeraeteView: _get_list_item_position: item: " + str(item), level=xbmc.LOGDEBUG) + for i in range(0, self.geraete_list.size()): + if self.geraete_list.getListItem(i) == item: + return i + return -1 + + def handle_click(self, position): + pass diff --git a/script.homepilot/resources/lib/Views/szenen_list_view.py b/script.homepilot/resources/lib/Views/szenen_list_view.py new file mode 100644 index 0000000..deae83f --- /dev/null +++ b/script.homepilot/resources/lib/Views/szenen_list_view.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import xbmc + +import xbmcgui +from .. import statics +from .. import homepilot_utils +import base_view + + +class SzenenListView(base_view.BaseView): + def __init__(self, client, stype): + base_view.BaseView.__init__(self) + self.stype = stype + self.client = client + self.title_control = None + self.errorcontrol = None + + def get_id(self): + return str(self.stype) + "_view" + + def remove_everything(self, window): + xbmc.log("SzenenListView: remove_everything: window: " + str(window), level=xbmc.LOGDEBUG) + window.removeControls([self.title_control]) + scenes_group = window.getControl(260) + if scenes_group is not None: + scenes_group.setVisible(False) + if self.errorcontrol is not None: + window.removeControl(self.errorcontrol) + + def visualize(self, window, addon): + xbmc.log("SzenenListView: visualize: window: " + str(window), level=xbmc.LOGDEBUG) + self.title_control = homepilot_utils.get_title_control(self.stype, addon) + window.addControl(self.title_control) + scenes_list = window.getControl(258) + scenes_list.reset() + + scenes = self.__get_scenes() + if scenes is not None and len(scenes) > 0: + scenes_group = window.getControl(260) + scenes_group.setPosition(350, 100) + scenes_group.setVisible(True) + for scene in scenes: + scene_item = xbmcgui.ListItem(label=scene.get_name()) + if scene.is_active(): + scene_item.setIconImage(base_view.szene_img) + else: + scene_item.setIconImage(base_view.szene_img_deact) + scene_item.setProperty("sid", str(scene.get_id())) + scene_item.setProperty("description", scene.get_description()) + scenes_list.addItem(scene_item) + self.errorcontrol = None + window.setFocusId(258) + else: + errorlabel = addon.getLocalizedString(32380) + self.errorcontrol = xbmcgui.ControlLabel(450, 150, 600, 75, errorlabel) + window.addControl(self.errorcontrol) + # window.setFocusId(94) + scenes_list.setVisible(True) + return [self.title_control] + + def handle_click(self, control): + pass + + def __get_scenes(self): + xbmc.log("SzenenListView: __get_scenes: ", level=xbmc.LOGDEBUG) + if self.stype == statics.SZENEN_ALLE: + return self.client.get_scenes() + elif self.stype == statics.SZENEN_MANUELL: + return self.client.get_manual_scenes() + elif self.stype == statics.SZENEN_NICHT_MANUELL: + return self.client.get_non_manual_scenes() + + def update(self, window, addon, menuControl): + xbmc.log("SzenenListView: update", level=xbmc.LOGDEBUG) + try: + self.remove_everything(window) + self.visualize(window, addon) + + except Exception, e: + xbmc.log("SzenenListView: update: Exception" + str(e.message), level=xbmc.LOGERROR) diff --git a/script.homepilot/resources/lib/Views/szenentyp_view.py b/script.homepilot/resources/lib/Views/szenentyp_view.py new file mode 100644 index 0000000..6555775 --- /dev/null +++ b/script.homepilot/resources/lib/Views/szenentyp_view.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import xbmcgui +import xbmc +import base_view +from .. import statics +from .. import homepilot_utils + + +class SzenentypView(base_view.BaseView): + def __init__(self): + base_view.BaseView.__init__(self) + self.scenes_list = None + self.manuell_item = None + self.nicht_manuell_item = None + self.title_control = None + self.alle_item = None + + def get_id(self): + return str(statics.SZENENTYPEN) + "_view" + + def remove_everything(self, window): + xbmc.log("SzenentypView: remove_everything: window: " + str(window), level=xbmc.LOGDEBUG) + if self.scenes_list is not None: + self.scenes_list.setVisible(False) + try: + window.removeControls([self.title_control]) + except RuntimeError, e: + xbmc.log("SzenentypView: Control does not exist in window " + str(e.message), level=xbmc.LOGERROR) + + def visualize(self, window, addon): + self.title_control = homepilot_utils.get_title_control(32016, addon) + window.addControl(self.title_control) + self.scenes_list = window.getControl(257) + self.scenes_list.reset() + + self.manuell_item = xbmcgui.ListItem(addon.getLocalizedString(32017)) + self.manuell_item.setIconImage(base_view.scene_manual) + self.manuell_item.setProperty("pid", "0") + self.scenes_list.addItem(self.manuell_item) + + self.nicht_manuell_item = xbmcgui.ListItem(addon.getLocalizedString(32018)) + self.nicht_manuell_item.setIconImage(base_view.scene_non_manual) + self.nicht_manuell_item.setProperty("pid", "1") + self.scenes_list.addItem(self.nicht_manuell_item) + + self.alle_item = xbmcgui.ListItem(addon.getLocalizedString(32020)) + self.alle_item.setProperty("pid", "2") + self.scenes_list.addItem(self.alle_item) + + self.scenes_list.setVisible(True) + + return [self.title_control] + + def handle_click(self, item): + position = item.getProperty("pid") + xbmc.log("SzenentypView: handle_click: position: " + str(position), level=xbmc.LOGDEBUG) + if position == "0": + return statics.SZENEN_MANUELL + elif position == "1": + return statics.SZENEN_NICHT_MANUELL + elif position == "2": + return statics.SZENEN_ALLE + return None + + def focus_list_item(self, view_id): + xbmc.log("SzenentypView: focus_list_item: view_id: " + str(view_id), level=xbmc.LOGDEBUG) + if view_id == str(statics.SZENEN_MANUELL) + "_view": + self.scenes_list.selectItem(0) + elif view_id == str(statics.SZENEN_NICHT_MANUELL) + "_view": + self.scenes_list.selectItem(1) + elif view_id == str(statics.SZENEN_ALLE) + "_view": + self.scenes_list.selectItem(2) diff --git a/script.homepilot/resources/lib/Windows/__init__.py b/script.homepilot/resources/lib/Windows/__init__.py new file mode 100644 index 0000000..f23368e --- /dev/null +++ b/script.homepilot/resources/lib/Windows/__init__.py @@ -0,0 +1 @@ +__author__ = 'dominik' diff --git a/script.homepilot/resources/lib/Windows/base_window.py b/script.homepilot/resources/lib/Windows/base_window.py new file mode 100644 index 0000000..add983c --- /dev/null +++ b/script.homepilot/resources/lib/Windows/base_window.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os + +import xbmc +import xbmcaddon +import xbmcgui +from .. import statics + +__addon__ = xbmcaddon.Addon(id='script.homepilot') +__addon_path__ = __addon__.getAddonInfo('path').decode("utf-8") +_control_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media') +images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media', 'devices') + +sliderbarImg = os.path.join(_control_images, 'slider.png') +sliderNibImg = os.path.join(_control_images, 'osd_slider_nib.png') +sliderNibImgNF = os.path.join(_control_images, 'osd_slider_nibNF.png') + + +class BaseWindow(xbmcgui.WindowXMLDialog): + def __init__(self, xmlFilename, scriptPath, defaultSkin='Default', defaultRes='720p'): + super(BaseWindow, self).__init__(xmlFilename, scriptPath, defaultSkin='Default', defaultRes='720p') + self.parent_window = None + self.errorcontrol = None + self._is_closed = True + + def is_closed(self): + xbmc.log("BaseWindow: is_closed: is_closed: "+repr(self._is_closed), level=xbmc.LOGDEBUG) + return self._is_closed + + def onAction(self, action): + xbmc.log("BaseWindow: onAction: action: "+repr(action), level=xbmc.LOGDEBUG) + if action == statics.ACTION_NAV_BACK or action == statics.ACTION_LAST_PAGE or action == statics.ACTION_STEP_BACK: + self.close() + self._is_closed = True + if action == statics.ACTION_PREVIOUS_MENU: + self.parent_window.shutdown() + self.close() + + def add_error_control(self): + label = __addon__.getLocalizedString(32381) + self.errorcontrol = xbmcgui.ControlLabel(280, 250, 350, 75, label, alignment=0x00000002) + self.addControl(self.errorcontrol) diff --git a/script.homepilot/resources/lib/Windows/degree_window.py b/script.homepilot/resources/lib/Windows/degree_window.py new file mode 100644 index 0000000..0871a97 --- /dev/null +++ b/script.homepilot/resources/lib/Windows/degree_window.py @@ -0,0 +1,189 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os + +import xbmc +import xbmcgui +from .. import statics +from .. import homepilot_utils +import device_window +import slider_updater +import base_window + + +class DegreeWindow(device_window.DeviceWindow): + def __init__(self, *args, **kwargs): + super(DegreeWindow, self).__init__(*args, **kwargs) + self.client = kwargs[statics.CLIENT] + self.device = kwargs[statics.DEVICE] + self.parent_window = kwargs[statics.PARENT] + self.use_local_favorites = kwargs[statics.LOCAL_FAVS] + self.updater = slider_updater.SliderUpdater(self.client, self.device, statics.DEGREE_TYPE) + self.updater.start() + self.errorcontrol = None + self.has_error = False + self.controls = None + + def onInit(self): + xbmc.log("DegreeWindow: onInit: ", level=xbmc.LOGDEBUG) + base_device_controls = self.get_base_device_controls(self.device) + degree_controls = self.__get_degree_controls() + self.controls = base_device_controls + self.controls.update(degree_controls) + button_group = self.getControl(114) + button_group.setPosition(330, 200) + self.addControls( + [self.controls[statics.SLIDER], + self.controls[statics.STATUS], + self.controls[statics.TITLE], + self.controls[statics.ICON]]) + slider = self.controls[statics.SLIDER] + slider_position = self.__get_slider_percent_from_position(self.device) + slider.setPercent(slider_position) + self.__set_focus_and_navigation_handling() + self.visualize_automations(self.device) + + def __get_degree_controls(self): + xbmc.log("DegreeWindow: __get_degree_controls: ", level=xbmc.LOGDEBUG) + controls = {} + # x = self.x + # y = self.y + status = self.device.get_display_value() + status_control = xbmcgui.ControlLabel(self.x + 180, self.y + 60, 600, 75, status, font="font16", + textColor="white") + controls[statics.STATUS] = status_control + controls[statics.SLIDER] = self.get_slider() + controls[statics.DOWN] = self.getControl(112) + controls[statics.UP] = self.getControl(113) + return controls + + def __get_slider_percent_from_position(self, device): + xbmc.log("DegreeWindow: __get_slider_percent_from_position: ", level=xbmc.LOGDEBUG) + position = device.get_position() + return (float(position) / 10 - 3) * 4 + + def __set_focus_and_navigation_handling(self): + xbmc.log("DegreeWindow: __set_focus_and_navigation_handling: ", level=xbmc.LOGDEBUG) + statusSlider = self.controls[statics.SLIDER] + downButton = self.controls[statics.DOWN] + upButton = self.controls[statics.UP] + self.setFocus(statusSlider) + statusSlider.controlDown(downButton) + downButton.controlDown(upButton) + downButton.controlRight(upButton) + downButton.controlUp(statusSlider) + downButton.controlLeft(statusSlider) + upButton.controlUp(downButton) + upButton.controlLeft(downButton) + self.set_navigation_handling_for_automatik_and_favorit(upButton) + + def update(self): + xbmc.log("DegreeWindow: update: ", level=xbmc.LOGDEBUG) + if self.getFocusId() == 0: + self.setFocus(self.controls[statics.SLIDER]) + try: + if self.updater.get_status() != "UPDATE": + new_device = self.client.get_device_by_id(self.device.get_device_id()) + if new_device.get_sync() != self.device.get_sync(): + self.__update_position(new_device) + self.__update_name(new_device) + self.device = new_device + else: + new_device = self.client.get_device_by_id(self.device.get_device_id()) + if new_device.get_sync() != self.device.get_sync(): + self.__update_name(new_device) + self.__update_icon(new_device) + if self.has_error and self.errorcontrol is not None: + self.removeControl(self.errorcontrol) + self.errorcontrol = None + self.has_error = False + except Exception, e: + xbmc.log(str(e), level=xbmc.LOGERROR) + self.has_error = True + + if self.has_error and self.errorcontrol is None: + self.add_error_control() + + def __update_icon(self, new_device): + xbmc.log("DegreeWindow: __update_icon: ", level=xbmc.LOGDEBUG) + icon = self.controls[statics.ICON] + image = new_device.get_icon() + icon_img = os.path.join(base_window.images, image) + icon.setImage(icon_img) + + def __update_position(self, new_device): + xbmc.log("DegreeWindow: __update_position: ", level=xbmc.LOGDEBUG) + if new_device.get_position() != self.device.get_position(): + statusSlider = self.controls[statics.SLIDER] + new_position = self.__get_slider_percent_from_position(new_device) + statusSlider.setPercent(new_position) + self.device = new_device + statusLabel = self.controls[statics.STATUS] + statusLabel.setLabel(new_device.get_display_value()) + self.__update_icon(new_device) + + def __update_name(self, new_device): + xbmc.log("DegreeWindow: __update_name: ", level=xbmc.LOGDEBUG) + if new_device.get_name() != self.device.get_name(): + title_label = self.controls[statics.TITLE] + title_label.setLabel(new_device.get_name()) + + def onClick(self, controlId): + xbmc.log("DegreeWindow: onClick: ", level=xbmc.LOGDEBUG) + xbmc.log("window click " + str(controlId), level=xbmc.LOGNOTICE) + statusSlider = self.controls[statics.SLIDER] + downButton = self.controls[statics.DOWN] + upButton = self.controls[statics.UP] + autoButton = self.controls[statics.AUTO] + favoriten_radio_control = self.controls["favoriten"] + current_device_position = self.device.get_position() + current_device_position_in_percent = self.__get_slider_percent_from_position(self.device) + current_slider_position = statusSlider.getPercent() + if controlId == downButton.getId(): + if current_slider_position >= 5: + self.client.move_to_degree(self.device.get_device_id(), current_device_position - 5) + elif controlId == upButton.getId(): + if current_slider_position <= 95: + self.client.move_to_degree(self.device.get_device_id(), current_device_position + 5) + elif controlId == statusSlider.getId(): + if current_slider_position != current_device_position_in_percent: + statusLabel = self.controls[statics.STATUS] + device_group = self.device.get_devicegroup() + diff = current_slider_position - current_device_position_in_percent + # thermostats can only be shifted in 0.5 degree steps over a range from 3°-28° + # this results in 50 possible value. As the slider has 100 possible values + # this requires some mappings + if current_slider_position < 3: + current_slider_position = 3 + if diff == 1: + new_position = (float(current_slider_position + 1) * 5 + 60) / 2 + if new_position % 5 == 0: + self.updater.update_slider(int(new_position)) + elif diff == -1: + new_position = (float(current_slider_position - 1) * 5 + 60) / 2 + if new_position % 5 == 0: + self.updater.update_slider(int(new_position)) + else: + new_position = (float(current_slider_position) * 5 + 60) / 2 + if new_position % 5 == 0: + self.updater.update_slider(int(new_position)) + + if new_position % 5 == 0: + display_value = homepilot_utils.get_display_value(int(new_position), device_group) + statusLabel.setLabel(display_value) + if controlId == autoButton.getId(): + self.handle_automation(self.device.get_device_id(), autoButton.isSelected(), self.device.is_automated()) + + if controlId == favoriten_radio_control.getId(): + self.handle_favorit(self.device.get_device_id(), favoriten_radio_control.isSelected(), + self.device.is_favored(), self.use_local_favorites) + + def onAction(self, action): + xbmc.log("DegreeWindow: onAction: ", level=xbmc.LOGDEBUG) + if action == 92 or action == 10: + self.updater.set_is_running = False + base_window.BaseWindow.onAction(self, action) + + def is_closed(self): + return base_window.BaseWindow.is_closed() \ No newline at end of file diff --git a/script.homepilot/resources/lib/Windows/device_window.py b/script.homepilot/resources/lib/Windows/device_window.py new file mode 100644 index 0000000..0a3bf4d --- /dev/null +++ b/script.homepilot/resources/lib/Windows/device_window.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import xbmc +import xbmcgui +import base_window +from .. import homepilot_utils +from .. import statics +from .. import local_favorites + + +class DeviceWindow(base_window.BaseWindow): + """ + Parent class for all types of devices (Thermostat, Schalter, Dimmer, Tor, ...) + """ + + def __init__(self, *args, **kwargs): + xbmc.log("DeviceWindow: __init__ ", level=xbmc.LOGDEBUG) + xbmcgui.WindowXMLDialog.__init__(self) + self.x = 250 + self.y = 40 + self.device = None + self.client = None + self.use_local_favorites = kwargs[statics.LOCAL_FAVS] + xbmc.log("DeviceWindow: __init__ ", level=xbmc.LOGDEBUG) + + def get_base_device_controls(self, device): + self.device = device + xbmc.log("DeviceWindow: get_base_device_controls: ", level=xbmc.LOGDEBUG) + control_dict = {} + title = self.device.get_name() + title_control = xbmcgui.ControlLabel(325, 55, 600, 75, title, font="font16", textColor="white") + control_dict[statics.TITLE] = title_control + icon = self.device.get_icon() + icon_img = os.path.join(base_window.images, icon) + image_control = xbmcgui.ControlImage(self.x + 80, self.y + 60, 50, 50, icon_img) + control_dict[statics.ICON] = image_control + auto_control = self.getControl(132) + auto_control.setSelected(device.is_automated()) + control_dict[statics.AUTO] = auto_control + fav_control = self.getControl(136) + + if self.use_local_favorites: + favored_devices = local_favorites.get_devices_as_set() + xbmc.log("DeviceWindow: get_base_device_controls: Local favored_devices: " + repr(favored_devices), + level=xbmc.LOGDEBUG) + if favored_devices is not None: + if device.get_device_id() in favored_devices: + fav_control.setSelected(True) + else: + fav_control.setSelected(False) + else: + xbmc.log("DeviceWindow: get_base_device_controls: Keine lokalen Favoriten. ", level=xbmc.LOGDEBUG) + fav_control.setSelected(device.is_favored()) + control_dict[statics.FAVORITEN] = fav_control + return control_dict + + def get_slider(self): + xbmc.log("DeviceWindow: get_slider: ", level=xbmc.LOGDEBUG) + if xbmc.skinHasImage('settings/slider_back.png'): + status_slider = xbmcgui.ControlSlider(self.x + 30, self.y + 130, 310, 15, + textureback='settings/slider_back.png', + texture='settings/orb_nofo.png', texturefocus='settings/orb_fo.png') + elif xbmc.skinHasImage('slider.png'): + status_slider = xbmcgui.ControlSlider(self.x + 80, self.y + 130, 240, 20, textureback='slider.png', + texture='osd_slider_nibNF.png', texturefocus='osd_slider_nib.png') + else: + status_slider = xbmcgui.ControlSlider(self.x + 80, self.y + 130, 240, 20, + textureback=base_window.sliderbarImg, + texture=base_window.sliderNibImgNF, + texturefocus=base_window.sliderNibImg) + return status_slider + + def handle_automation(self, deviceId, is_selected, is_automated): + xbmc.log("DeviceWindow: handle_automation: ", level=xbmc.LOGDEBUG) + if is_selected and not is_automated: + self.client.set_device_automation_on(deviceId) + elif not is_selected and is_automated: + self.client.set_device_automation_off(deviceId) + + def handle_favorit(self, deviceId, is_selected, is_favorited, use_local_favorites): + xbmc.log("DeviceWindow: handle_favorit: ", level=xbmc.LOGDEBUG) + favored_devices = local_favorites.get_devices_as_set() + if use_local_favorites: + if favored_devices is None: + if is_selected: + local_favorites.add_device(deviceId) + elif not is_selected: + local_favorites.remove_device(deviceId) + elif favored_devices is not None: + if is_selected: + if deviceId not in favored_devices: + local_favorites.add_device(deviceId) + elif not is_selected and deviceId in favored_devices: + local_favorites.remove_device(deviceId) + elif not is_selected and deviceId in favored_devices: + local_favorites.remove_device(deviceId) + else: + if is_selected and not is_favorited: + self.client.favorize_device(deviceId) + elif not is_selected and is_favorited: + self.client.unfavorize_device(deviceId) + + def set_navigation_handling_for_automatik_and_favorit(self, previous_control): + xbmc.log("DeviceWindow: set_navigation_handling_for_automatik_and_favorit: ", level=xbmc.LOGDEBUG) + autoButton = self.getControl(132) + favorit_button = self.getControl(136) + autoScrollbar = self.getControl(142) + previous_control.controlRight(autoButton) + previous_control.controlDown(autoButton) + autoButton.controlLeft(previous_control) + autoButton.controlUp(previous_control) + autoButton.controlRight(favorit_button) + autoButton.controlDown(favorit_button) + favorit_button.controlLeft(autoButton) + favorit_button.controlUp(autoButton) + favorit_button.controlDown(autoScrollbar) + favorit_button.controlRight(autoScrollbar) + autoScrollbar.controlLeft(favorit_button) + autoScrollbar.controlUp(favorit_button) + + def visualize_automations(self, device): + xbmc.log("DeviceWindow: visualize_automations: ", level=xbmc.LOGDEBUG) + automation_list = self.getControl(142) + automation_list.reset() + automations = device.get_automationen() + homepilot_utils.add_device_to_automation_list(automation_list, automations, base_window.__addon__) diff --git a/script.homepilot/resources/lib/Windows/error_window.py b/script.homepilot/resources/lib/Windows/error_window.py new file mode 100644 index 0000000..aa6dfe6 --- /dev/null +++ b/script.homepilot/resources/lib/Windows/error_window.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import base_window +from .. import statics +import xbmc + + +class ErrorWindow(base_window.BaseWindow): + def __init__(self, xmlFilename, scriptPath, *args, **kwargs): + super(ErrorWindow, self).__init__(xmlFilename, scriptPath) + self.parent_window = kwargs[statics.PARENT] + + def onInit(self): + self.add_error_control() + + def onAction(self, action): + xbmc.log("ErrorWindow: onAction: ", level=xbmc.LOGDEBUG) + base_window.BaseWindow.onAction(self, action) + + def is_closed(self): + return base_window.BaseWindow.is_closed() diff --git a/script.homepilot/resources/lib/Windows/meter_window.py b/script.homepilot/resources/lib/Windows/meter_window.py new file mode 100644 index 0000000..e4f9213 --- /dev/null +++ b/script.homepilot/resources/lib/Windows/meter_window.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import xbmc +import xbmcgui +import os +from .. import statics +import base_window + + +class MeterWindow(base_window.BaseWindow): + def __init__(self, *args, **kwargs): + xbmcgui.WindowXMLDialog.__init__(self) + self.client = kwargs[statics.CLIENT] + self.did = kwargs[statics.CLIENT] + self.parent_window = kwargs[statics.PARENT] + self.meter = None + self.icon_control = None + self.data_controls = None + + def onInit(self): + xbmc.log("MeterWindow: onInit: ", level=xbmc.LOGDEBUG) + self.__disable_favorite_and_automatik_control() + self.__resize_window() + try: + self.meter = self.client.get_meter_by_id(self.did) + self.__add__controls() + self.errorcontrol = None + except Exception, e: + xbmc.log(str(e), level=xbmc.LOGWARNING) + self.add_error_control() + + def __add__controls(self): + xbmc.log("MeterWindow: __add__controls: ", level=xbmc.LOGDEBUG) + controls = [] + self.icon_control = self.__get_icon_control() + controls.append(self.icon_control) + title = self.meter.get_name() + self.title_control = xbmcgui.ControlLabel(310, 55, 600, 75, title, font="font16", textColor="white") + controls.append(self.title_control) + label = base_window.__addon__.getLocalizedString(32389) + aktuell_control = xbmcgui.ControlLabel(300, 110, 600, 75, label, font="font12", textColor="white") + controls.append(aktuell_control) + self.data_controls = self.__get_data_controls() + controls.extend(self.data_controls) + self.addControls(controls) + + def __get_icon_control(self): + xbmc.log("MeterWindow: __get_icon_control: ", level=xbmc.LOGDEBUG) + icon = self.meter.get_icon() + icon_img = os.path.join(base_window.images, icon) + image_control = xbmcgui.ControlImage(260, 55, 40, 40, icon_img) + return image_control + + def __get_data_controls(self): + xbmc.log("MeterWindow: __get_data_controls: ", level=xbmc.LOGDEBUG) + data = self.meter.get_data() + y = 150 + data_controls = [] + for data_dict in data: + for d in data_dict: + label = d + ": " + data_dict[d] + data_control = xbmcgui.ControlLabel(300, y, 600, 75, label, font="font12", textColor="white") + y += 35 + data_controls.append(data_control) + return data_controls + + def update(self): + xbmc.log("MeterWindow: update: ", level=xbmc.LOGDEBUG) + try: + new_meter = self.client.get_meter_by_id(self.did) + if new_meter.get_sync() != self.meter.get_sync(): + if new_meter.get_name() != self.meter.get_name(): + xbmc.log("-- name has changed ", level=xbmc.LOGNOTICE) + self.title_control.setLabel(new_meter.get_name()) + if new_meter.get_icon() != self.meter.get_icon(): + self.removeControl(self.icon_control) + self.icon_control = self.__get_icon_control() + self.addControl(self.icon_control) + self.removeControls(self.data_controls) + self.data_controls = self.__get_data_controls() + self.addControls(self.data_controls) + self.meter = new_meter + except Exception, e: + xbmc.log(str(e), level=xbmc.LOGWARNING) + + def __disable_favorite_and_automatik_control(self): + xbmc.log("MeterWindow: __disable_favorite_and_automatik_control: ", level=xbmc.LOGDEBUG) + automation_control = self.getControl(138) + automation_control.setVisible(False) + favorit_control = self.getControl(134) + favorit_control.setVisible(False) + automatik_control = self.getControl(130) + automatik_control.setVisible(False) + + def __resize_window(self): + xbmc.log("MeterWindow: __resize_window: ", level=xbmc.LOGDEBUG) + background = self.getControl(1002) + background.setWidth(600) + separator = self.getControl(1004) + if xbmc.getSkinDir() == "skin.confluence": + separator.setWidth(620) + close_icon = self.getControl(1003) + close_icon.setPosition(780, close_icon.getY()) + else: + separator.setWidth(540) + + def onAction(self, action): + xbmc.log("MeterWindow: onAction: ", level=xbmc.LOGDEBUG) + base_window.BaseWindow.onAction(self, action) + + def is_closed(self): + return base_window.BaseWindow.is_closed() \ No newline at end of file diff --git a/script.homepilot/resources/lib/Windows/percentage_window.py b/script.homepilot/resources/lib/Windows/percentage_window.py new file mode 100644 index 0000000..4d440a4 --- /dev/null +++ b/script.homepilot/resources/lib/Windows/percentage_window.py @@ -0,0 +1,214 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +from .. import statics +from .. import homepilot_utils +import xbmc +import xbmcgui +import device_window +import slider_updater +import base_window + + +class PercentageWindow(device_window.DeviceWindow): + def __init__(self, *args, **kwargs): + xbmc.log("PercentageWindow: __init__: ", level=xbmc.LOGDEBUG) + super(PercentageWindow, self).__init__(*args, **kwargs) + self.client = kwargs[statics.CLIENT] + self.device = kwargs[statics.DEVICE] + self.parent_window = kwargs[statics.PARENT] + self.use_local_favorites = kwargs[statics.LOCAL_FAVS] + self.updater = slider_updater.SliderUpdater(self.client, self.device, statics.PERCENT_TYPE) + self.updater.start() + self.has_error = False + self.controls = {} + self.errorcontrol = None + + def onInit(self): + xbmc.log("PercentageWindow: onInit: ", level=xbmc.LOGDEBUG) + base_device_controls = self.get_base_device_controls(self.device) + percent_controls = self.__get_percent_controls() + self.controls = base_device_controls + self.controls.update(percent_controls) + if self.device.get_devicegroup() == 2: + button_group = self.getControl(1141) + else: + button_group = self.getControl(114) + button_group.setPosition(330, 200) + self.addControls([self.controls[statics.SLIDER], + self.controls[statics.STATUS], + self.controls[statics.TITLE], + self.controls[statics.ICON]]) + slider = self.controls[statics.SLIDER] + slider.setPercent(self.device.get_position()) + xbmc.log("PercentageWindow: onInit: slider" + repr(slider), level=xbmc.LOGDEBUG) + self.__set_focus_and_navigation_handling() + self.visualize_automations(self.device) + + def __get_percent_controls(self): + xbmc.log("PercentageWindow: __get_percent_controls: ", level=xbmc.LOGDEBUG) + controls = {} + # x = self.x + # y = self.y + status = self.device.get_display_value() + status_control = xbmcgui.ControlLabel(self.x + 180, self.y + 65, 600, 75, status, font="font16", + textColor="white") + controls[statics.STATUS] = status_control + slider = self.get_slider() + controls[statics.SLIDER] = slider + slider.setPercent(self.device.get_position()) + if self.device.get_devicegroup() == 2: + down_button = self.getControl(1121) + up_button = self.getControl(1131) + else: + down_button = self.getControl(112) + up_button = self.getControl(113) + controls[statics.DOWN] = down_button + controls[statics.UP] = up_button + return controls + + def update(self): + xbmc.log("PercentageWindow: update: ", level=xbmc.LOGDEBUG) + if self.getFocusId() == 0: + if self.controls.get(statics.SLIDER) is not None: + self.setFocus(self.controls.get(statics.SLIDER)) + if self.updater.get_status() != statics.UPDATE: + xbmc.log("PercentageWindow: update: no status update awaiting", xbmc.LOGNOTICE) + try: + new_device = self.client.get_device_by_id(self.device.get_device_id()) + if new_device.get_sync() != self.device.get_sync(): # device has changed + self.__update_position(new_device) + self.__update_name(new_device) + self.device = new_device + if self.has_error and self.errorcontrol is not None: + self.removeControl(self.errorcontrol) + self.errorcontrol = None + self.has_error = False + except Exception, e: + xbmc.log("PercentageWindow: update:" + repr(e.message), level=xbmc.LOGWARNING) + self.has_error = True + else: + xbmc.log("PercentageWindow: update: Status update awaiting", xbmc.LOGNOTICE) + try: + new_device = self.client.get_device_by_id(self.device.get_device_id()) + if new_device.get_sync() != self.device.get_sync(): # device has changed + self.__update_icon(new_device) + self.__update_name(new_device) + if self.has_error: + if self.errorcontrol is not None: + self.removeControl(self.errorcontrol) + self.errorcontrol = None + self.has_error = False + except Exception, e: + xbmc.log("PercentageWindow: update:" + repr(e.message), level=xbmc.LOGWARNING) + self.has_error = True + + if self.has_error and self.errorcontrol is None: + self.add_error_control() + + def __update_icon(self, new_device): + xbmc.log("PercentageWindow: __update_icon: ", level=xbmc.LOGDEBUG) + icon = self.controls[statics.ICON] + image = new_device.get_icon() + icon_img = os.path.join(base_window.images, image) + icon.setImage(icon_img) + + def __update_position(self, new_device): + xbmc.log("PercentageWindow: __update_position: ", level=xbmc.LOGDEBUG) + self.__update_icon(new_device) + if new_device.get_position() != self.device.get_position(): + statusSlider = self.controls[statics.SLIDER] + statusSlider.setPercent(new_device.get_position()) + self.device = new_device + statusLabel = self.controls[statics.STATUS] + statusLabel.setLabel(new_device.get_display_value()) + + def __update_name(self, new_device): + xbmc.log("PercentageWindow: __update_name: ", level=xbmc.LOGDEBUG) + if new_device.get_name() != self.device.get_name(): + title_label = self.controls[statics.TITLE] + title_label.setLabel(new_device.get_name()) + + def __set_focus_and_navigation_handling(self): + xbmc.log("PercentageWindow: __set_focus_and_navigation_handling: ", level=xbmc.LOGDEBUG) + statusSlider = self.controls[statics.SLIDER] + downButton = self.controls[statics.DOWN] + upButton = self.controls[statics.UP] + + self.setFocus(statusSlider) + if self.device.get_devicegroup() == 2: + statusSlider.controlDown(upButton) + upButton.controlDown(downButton) + upButton.controlRight(downButton) + upButton.controlUp(statusSlider) + upButton.controlLeft(statusSlider) + downButton.controlUp(upButton) + downButton.controlLeft(upButton) + self.set_navigation_handling_for_automatik_and_favorit(downButton) + else: + statusSlider.controlDown(downButton) + downButton.controlDown(upButton) + downButton.controlRight(upButton) + downButton.controlUp(statusSlider) + downButton.controlLeft(statusSlider) + upButton.controlUp(downButton) + upButton.controlLeft(downButton) + self.set_navigation_handling_for_automatik_and_favorit(upButton) + + def onClick(self, controlId): + xbmc.log("PercentageWindow: onClick: controlId: " + repr(controlId), level=xbmc.LOGDEBUG) + status_slider = self.controls[statics.SLIDER] + down_button = self.controls[statics.DOWN] + up_button = self.controls[statics.UP] + auto_button = self.controls[statics.AUTO] + favoriten_radio_control = self.controls[statics.FAVORITEN] + status = self.device.get_status() + # handle up-down-buttons + device_group = self.device.get_devicegroup() + try: + if device_group == 2 or device_group == 4 or device_group == 8: # rollo,dimmer,tore + if controlId == down_button.getId(): + self.client.move_down(self.device.get_device_id()) + elif controlId == up_button.getId(): + self.client.move_up(self.device.get_device_id()) + else: + if controlId == down_button.getId(): + if status <= 95: + self.client.move_to_position(self.device.get_device_id(), status + 5) + elif controlId == up_button.getId(): + if status >= 5: + self.client.move_to_position(self.device.get_device_id(), status - 5) + except Exception, e: + xbmc.log("PercentageWindow: onClick" + str(e), level=xbmc.LOGWARNING) + self.has_error = True + + # handle slider + if controlId == status_slider.getId(): + current_slider_value = status_slider.getPercent() + statusLabel = self.controls[statics.STATUS] + device_group = self.device.get_devicegroup() + display_value = homepilot_utils.get_display_value(int(current_slider_value), device_group) + statusLabel.setLabel(display_value) + if current_slider_value > status: + new_position = current_slider_value + self.updater.update_slider(new_position) + elif current_slider_value < status: + new_position = current_slider_value + self.updater.update_slider(new_position) + + if controlId == auto_button.getId(): + self.handle_automation(self.device.get_device_id(), auto_button.isSelected(), self.device.is_automated()) + + if controlId == favoriten_radio_control.getId(): + self.handle_favorit(self.device.get_device_id(), favoriten_radio_control.isSelected(), + self.device.is_favored(), self.use_local_favorites) + + def onAction(self, action): + xbmc.log("PercentageWindow: onAction: ", level=xbmc.LOGDEBUG) + if action == 92 or action == 10: + self.updater.set_is_running(False) + base_window.BaseWindow.onAction(self, action) + + def is_closed(self): + return base_window.BaseWindow.is_closed(self) diff --git a/script.homepilot/resources/lib/scene_window.py b/script.homepilot/resources/lib/Windows/scene_window.py similarity index 57% rename from script.homepilot/resources/lib/scene_window.py rename to script.homepilot/resources/lib/Windows/scene_window.py index cade63e..ce15710 100644 --- a/script.homepilot/resources/lib/scene_window.py +++ b/script.homepilot/resources/lib/Windows/scene_window.py @@ -1,43 +1,48 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - -import xbmcgui -import xbmc import os +from .. import statics +from .. import homepilot_utils +from .. import local_favorites +import xbmc import xbmcaddon +import xbmcgui + __addon__ = xbmcaddon.Addon(id='script.homepilot') __addon_path__ = __addon__.getAddonInfo('path').decode("utf-8") _images_device = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media', 'devices') _images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media') -import homepilot_utils -import local_favorites - szene_img = os.path.join(_images, 'szene_32.png') szene_img_deact = os.path.join(_images, 'szene_32_deactivated.png') -class SzenenDetailWindow(xbmcgui.WindowXMLDialog): - def __init__( self, *args, **kwargs ): - xbmcgui.WindowXMLDialog.__init__( self ) +class SzenenDetailWindow(xbmcgui.WindowXMLDialog): + def __init__(self, *args, **kwargs): + xbmcgui.WindowXMLDialog.__init__(self) self.x = 250 self.y = 40 - self.client = kwargs["client"] - scene_id = kwargs["scene_id"] + self.client = kwargs[statics.CLIENT] + scene_id = kwargs[statics.SCENE_ID] self.scene = self.client.get_scene_by_id(scene_id) - self.previous_list_position = kwargs["previous_list_position"] - self.addon = kwargs["addon"] - self.parent_window = kwargs["parent"] - local_favs = kwargs["use_local_favorites"] - self.use_local_favorites = False - if local_favs == "true": - self.use_local_favorites = True + self.previous_list_position = kwargs[statics.PREVIOUS_LIST_POSITION] + self.addon = kwargs[statics.ADDON] + self.parent_window = kwargs[statics.PARENT] + self.use_local_favorites = kwargs[statics.USE_LOCAL_FAVORITES] + self.title_control = None + self.radiobutton_control = None + self.execcontrol = None + self.gerate_group_control = None + self.imagecontrol = None + self._is_closed = True def get_previous_list_position(self): return self.previous_list_position def onInit(self): - self.title_control = xbmcgui.ControlLabel(400, 55, 600, 75, self.scene.get_name(), font="font16", textColor="white") + xbmc.log("SzenenDetailWindow: onInit: ", level=xbmc.LOGDEBUG) + self.title_control = xbmcgui.ControlLabel(400, 55, 600, 75, self.scene.get_name(), font="font16", + textColor="white") self.radiobutton_control = self.getControl(134) self.addControl(self.title_control) self.__set_state() @@ -57,19 +62,22 @@ def onInit(self): self.__handle_navigation(self.scene.is_executable()) def __generate_geraetelist(self): + xbmc.log("SzenenDetailWindow: __generate_geraetelist: ", level=xbmc.LOGDEBUG) self.geraete_list = self.getControl(148) - actions = self.scene.get_actions() + actions = self.scene.get_actions_as_list() self.geraete_list.reset() # show scrollbar only when there are more than two devices - if len(actions) == 1 or len(actions) == 2 or len(actions) == 0: + if len(actions) <= 2: + xbmc.log("SzenenDetailWindow: __generate_geraetelist: No scrollbar, less than two devices.", level=xbmc.LOGDEBUG) xbmc.executebuiltin("SetProperty(show_bar,0,Home)") else: + xbmc.log("SzenenDetailWindow: __generate_geraetelist: Scrollbar, more than two devices.", level=xbmc.LOGDEBUG) xbmc.executebuiltin("SetProperty(show_bar,1,Home)") self.__add_geraetelistitems(actions, __addon__) - def __generate_automationlist(self): + xbmc.log("SzenenDetailWindow: __generate_automationlist: ", level=xbmc.LOGDEBUG) self.automation_group_control = self.getControl(138) self.automation_group_control.setHeight(100) self.automation_list = self.getControl(142) @@ -77,12 +85,13 @@ def __generate_automationlist(self): automations = self.scene.get_automationen() homepilot_utils.add_scene_to_automation_list(self.automation_list, automations, __addon__) - def __set_state(self): + xbmc.log("SzenenDetailWindow: __set_state: ", level=xbmc.LOGDEBUG) aktiv_button = self.getControl(160) is_active = self.scene.is_active() aktiv_button.setSelected(is_active) - if hasattr(self, "imagecontrol"): + + if hasattr(self, "imagecontrol") and self.imagecontrol is not None: self.removeControl(self.imagecontrol) if is_active: @@ -91,26 +100,28 @@ def __set_state(self): self.imagecontrol = xbmcgui.ControlImage(400, 100, 64, 64, szene_img_deact) fav_button = self.getControl(136) - if self.use_local_favorites: - favored_scenes = local_favorites.get_devices_as_set() - if self.scene.get_id() in favored_scenes: + favored_scenes = local_favorites.get_scenes_as_set() + + if self.use_local_favorites and favored_scenes is not None: + xbmc.log("SzenenDetailWindow: __set_state: use_local_favorites: " + repr(self.use_local_favorites), level=xbmc.LOGDEBUG) + if self.scene.get_id() in favored_scenes or self.scene.is_favored(): fav_button.setSelected(True) else: fav_button.setSelected(False) else: fav_button.setSelected(self.scene.is_favored()) - xbmc.log("---scene_window.py-- update scene" + str(self.getFocusId()), level=xbmc.LOGNOTICE) - - if self.scene.is_executable() and hasattr(self, 'execcontrol'): - self.execcontrol.setVisible(True) - elif hasattr(self, 'execcontrol'): - self.execcontrol.setVisible(False) + if self.execcontrol is not None: + if self.scene.is_executable() and hasattr(self, 'execcontrol'): + self.execcontrol.setVisible(True) + elif hasattr(self, 'execcontrol'): + self.execcontrol.setVisible(False) + else: + xbmc.log("SzenenDetailWindow: __set_state: execcontrol: " + repr(self.execcontrol.__class__), level=xbmc.LOGDEBUG) self.addControl(self.imagecontrol) - def __handle_navigation(self, exec_button_visible): - xbmc.log("---scene_window.py-- navigation" + str(self.execcontrol), level=xbmc.LOGNOTICE) + xbmc.log("SzenenDetailWindow: __handle_navigation: ", level=xbmc.LOGDEBUG) aktiv_button = self.getControl(160) fav_button = self.getControl(136) if exec_button_visible: @@ -127,10 +138,11 @@ def __handle_navigation(self, exec_button_visible): fav_button.controlDown(self.automation_list) self.automation_list.controlUp(fav_button) - def __add_geraetelistitems(self, actions, addon): + xbmc.log("SzenenDetailWindow: __add_geraetelistitems: action: " + repr(actions), level=xbmc.LOGDEBUG) for action in actions: - item = xbmcgui.ListItem(label=action.get_name()) + xbmc.log("SzenenDetailWindow: __add_geraetelistitems: action Name: " + repr(action.get_name()), level=xbmc.LOGDEBUG) + item = xbmcgui.ListItem(label=str(action.get_name())) icon_name = action.get_icon() item.setLabel2(self.get_cmd_txt(action.get_cmdId(), action.get_param(), action.get_device_group(), addon)) item.setIconImage(os.path.join(_images_device, icon_name)) @@ -138,6 +150,7 @@ def __add_geraetelistitems(self, actions, addon): self.geraete_list.addItem(item) def get_cmd_txt(self, cmd_id, param, device_group, addon): + xbmc.log("SzenenDetailWindow: get_cmd_txt: ", level=xbmc.LOGDEBUG) EIN = 10 AUS = 11 AUF = 1 @@ -208,60 +221,84 @@ def get_cmd_txt(self, cmd_id, param, device_group, addon): return "-" return "" - def onClick(self, controlId): + xbmc.log("SzenenDetailWindow: onClick: ", level=xbmc.LOGDEBUG) if controlId == 160: - aktiv_button = self.getControl(160) - button_is_akiv = aktiv_button.isSelected() - - if self.scene.is_active() and not button_is_akiv: - self.client.set_scene_inactive(self.scene.get_id()) - self.removeControl(self.imagecontrol) - self.imagecontrol = xbmcgui.ControlImage(400, 100, 64, 64, szene_img_deact) - self.addControl(self.imagecontrol) - elif not self.scene.is_active() and button_is_akiv: - self.client.set_scene_active(self.scene.get_id()) - self.removeControl(self.imagecontrol) - self.imagecontrol = xbmcgui.ControlImage(400, 100, 64, 64, szene_img) - self.addControl(self.imagecontrol) + self.__on_click_active_button() elif controlId == 136: - fav_button = self.getControl(136) - button_is_faved = (fav_button.isSelected() == 1) - if self.use_local_favorites: - favored_scenes = local_favorites.get_devices_as_set() + self.__on_click_fav_button() + elif controlId == self.execcontrol.getId(): + self.client.execute_scene(self.scene.get_id()) + + def __on_click_active_button(self): + xbmc.log("SzenenDetailWindow: __on_click_active_button", level=xbmc.LOGDEBUG) + aktiv_button = self.getControl(160) + button_is_akiv = aktiv_button.isSelected() + xbmc.log("SzenenDetailWindow: __on_click_active_button scene.is_active():" + repr(self.scene.is_active()) + + "\nbutton_is_akiv: " + repr(button_is_akiv), level=xbmc.LOGDEBUG) + if self.scene.is_active() and not button_is_akiv: + self.client.set_scene_inactive(self.scene.get_id()) + self.scene.set_inactive() + self.removeControl(self.imagecontrol) + self.imagecontrol = xbmcgui.ControlImage(400, 100, 64, 64, szene_img_deact) + self.addControl(self.imagecontrol) + elif not self.scene.is_active() and button_is_akiv: + self.client.set_scene_active(self.scene.get_id()) + self.scene.set_activ() + self.removeControl(self.imagecontrol) + self.imagecontrol = xbmcgui.ControlImage(400, 100, 64, 64, szene_img) + self.addControl(self.imagecontrol) + + def __on_click_fav_button(self): + xbmc.log("SzenenDetailWindow: __on_click_fav_button", level=xbmc.LOGDEBUG) + fav_button = self.getControl(136) + button_is_faved = (fav_button.isSelected() == 1) + if self.use_local_favorites: + favored_scenes = local_favorites.get_scenes_as_set() + xbmc.log("SzenenDetailWindow: __on_click_fav_button: favored_scenes: " + repr(favored_scenes) + + " self.scene.get_id(): " + repr(self.scene.get_id()) + + " scene is_favored: " + repr(self.scene.is_favored()), level=xbmc.LOGDEBUG) + if favored_scenes is not None: if button_is_faved and self.scene.get_id() not in favored_scenes: local_favorites.add_scene(self.scene.get_id()) + self.scene.set_favored() elif not button_is_faved and self.scene.get_id() in favored_scenes: local_favorites.remove_scene(self.scene.get_id()) - + self.scene.set_unfavored() else: - if self.scene.is_favored() and not button_is_faved: - self.client.unfavorize_scene(self.scene.get_id()) - elif not self.scene.is_favored() and button_is_faved: - self.client.favorize_scene(self.scene.get_id()) - - - elif controlId == self.execcontrol.getId(): - self.client.execute_scene(self.scene.get_id()) - + #Wenn die Favoriten None sind, sind sie leer. Also befüllen wie sie. + local_favorites.add_scene(self.scene.get_id()) + self.scene.set_favored() + else: + if self.scene.is_favored() and not button_is_faved: + self.client.unfavorize_scene(self.scene.get_id()) + self.scene.set_unfavored() + elif not self.scene.is_favored() and button_is_faved: + self.client.favorize_scene(self.scene.get_id()) + self.scene.set_favored() + xbmc.log("SzenenDetailWindow: __on_click_fav_button: is_favored: " + repr(self.scene.is_favored()), level=xbmc.LOGDEBUG) def onAction(self, action): - if action == 92 or action == 160 or action == 21: + xbmc.log("SzenenDetailWindow: onAction: action: " + repr(action), level=xbmc.LOGDEBUG) + if action == statics.AID_BACK or action == statics.ACTION_LAST_PAGE or action == statics.ACTION_STEP_BACK: self.close() - self.is_closed = True - if action == 10: + self._is_closed = True + if action == statics.ACTION_PREVIOUS_MENU: self.parent_window.shutdown() self.close() - self.is_closed = True - + self._is_closed = True + def is_closed(self): - return self.is_closed + return self._is_closed def update(self): - xbmc.log("---scene_window.py-- update scene" + str(self.getFocusId()), level=xbmc.LOGNOTICE) - if self.getFocusId() == 0 and self.scene.is_executable() and hasattr(self, 'execcontrol'): + xbmc.log("SzenenDetailWindow: update: is_favored: " + repr(self.scene.is_favored()) + + "\nexeccontrol: " + repr(self.execcontrol) + + "\nradiobutton_control: " + repr(self.radiobutton_control) + + "\nuse_local_favorites: " + repr(self.use_local_favorites), level=xbmc.LOGDEBUG) + if self.getFocusId() == 0 and self.scene.is_executable() and hasattr(self, 'execcontrol') and self.execcontrol is not None: self.setFocus(self.execcontrol) - elif self.getFocusId() == 0 and hasattr(self, 'radiobutton_control'): + elif self.getFocusId() == 0 and hasattr(self, 'radiobutton_control') and self.radiobutton_control is not None: self.setFocus(self.radiobutton_control) try: new_scene = self.client.get_scene_by_id(self.scene.get_id()) @@ -271,6 +308,5 @@ def update(self): self.__generate_geraetelist() self.__generate_automationlist() self.__handle_navigation(self.scene.is_executable()) - except Exception, e: xbmc.log(str(e), level=xbmc.LOGWARNING) diff --git a/script.homepilot/resources/lib/Windows/slider_updater.py b/script.homepilot/resources/lib/Windows/slider_updater.py new file mode 100644 index 0000000..bf4869b --- /dev/null +++ b/script.homepilot/resources/lib/Windows/slider_updater.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import time +import threading +from .. import statics +import xbmc + + +class SliderUpdater(threading.Thread): + def __init__(self, client, device, type): + threading.Thread.__init__(self) + self.position = -1 + self.update_time = 0 + self.client = client + self.device = device + self.status = statics.NOTHING + self.type = type + self.is_running = None + + def update_slider(self, new_value): + xbmc.log("SliderUpdater: update_slider: ", level=xbmc.LOGDEBUG) + if self.position != new_value: + # xbmc.log(str(self.position), xbmc.LOGNOTICE) + # xbmc.log(str(new_value), xbmc.LOGNOTICE) + self.update_time = time.time() + self.position = new_value + self.status = statics.UPDATE + + def set_is_running(self, is_running): + xbmc.log("SliderUpdater: set_is_running: ", level=xbmc.LOGDEBUG) + self.is_running = is_running + + def get_status(self): + xbmc.log("SliderUpdater: get_status: ", level=xbmc.LOGDEBUG) + return self.status + + def run(self): + xbmc.log("SliderUpdater: run: ", level=xbmc.LOGDEBUG) + self.is_running = True + count = 0 + while self.is_running: + if self.update_time > 0 and time.time() - self.update_time > 0.4: + if self.status == statics.UPDATE: + if self.type == statics.PERCENT_TYPE and count < 3: + success = self.client.move_to_position(self.device.get_device_id(), self.position) + if success: + self.status = statics.UPDATE_SENT + count = 0 + else: + count += 1 + elif count < 3: + success = self.client.move_to_degree(self.device.get_device_id(), self.position) + if success: + self.status = statics.UPDATE_SENT + count = 0 + else: + count += 1 + time.sleep(0.3) diff --git a/script.homepilot/resources/lib/Windows/switch_window.py b/script.homepilot/resources/lib/Windows/switch_window.py new file mode 100644 index 0000000..04a39ba --- /dev/null +++ b/script.homepilot/resources/lib/Windows/switch_window.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import device_window +import xbmc +from .. import statics +import slider_updater +import base_window + + +class SwitchWindow(device_window.DeviceWindow): + def __init__(self, *args, **kwargs): + super(SwitchWindow, self).__init__(*args, **kwargs) + self.client = kwargs[statics.CLIENT] + self.device = kwargs[statics.DEVICE] + self.parent_window = kwargs[statics.PARENT] + self.use_local_favorites = kwargs[statics.LOCAL_FAVS] + self.wait_for_response = False + self.updater = slider_updater.SliderUpdater(self.client, self.device, statics.DEGREE_TYPE) + self.errorcontrol = None + self.has_error = False + self.controls = None + + def onInit(self): + xbmc.log("SwitchWindow: onInit: ", level=xbmc.LOGDEBUG) + base_device_controls = self.get_base_device_controls(self.device) + switch_controls = self.__get_switch_controls() + + self.controls = base_device_controls + self.controls.update(switch_controls) + self.addControls([self.controls[statics.TITLE], self.controls[statics.ICON]]) + self.__set_focus_and_navigation_handling() + self.visualize_automations(self.device) + + def __get_switch_controls(self): + xbmc.log("SwitchWindow: __get_switch_controls: ", level=xbmc.LOGDEBUG) + controls = {} + group_control = self.getControl(118) + group_control.setPosition(350, 100) + + radio = self.getControl(116) + on = self.getControl(115) + off = self.getControl(117) + if self.device.get_position() > 0: + radio.setSelected(True) + on.setEnabled(True) + off.setEnabled(False) + else: + radio.setSelected(False) + on.setEnabled(False) + off.setEnabled(True) + controls[statics.GROUP] = group_control + controls[statics.RADIO] = radio + controls[statics.ON] = on + controls[statics.OFF] = off + return controls + + def update(self): + xbmc.log("SwitchWindow: update: ", level=xbmc.LOGDEBUG) + if self.getFocusId() == 0: + self.setFocusId(116) + try: + new_device = self.client.get_device_by_id(self.device.get_device_id()) + if new_device.get_sync() != self.device.get_sync(): + if new_device.get_position() != self.device.get_position(): + self.__set_state(new_device) + if new_device.get_name() != self.device.get_name(): + title_label = self.controls[statics.TITLE] + title_label.setLabel(new_device.get_name()) + self.device = new_device + if self.has_error: + self.has_error = False + if self.errorcontrol is not None: + self.removeControl(self.errorcontrol) + self.errorcontrol = None + except Exception, e: + xbmc.log(str(e), level=xbmc.LOGWARNING) + self.has_error = True + + if self.has_error and self.errorcontrol is None: + self.add_error_control() + + def __set_state(self, new_device): + xbmc.log("SwitchWindow: __set_state: ", level=xbmc.LOGDEBUG) + radio = self.getControl(116) + on = self.getControl(115) + off = self.getControl(117) + icon = self.controls[statics.ICON] + if new_device.get_position() > 0: + radio.setSelected(True) + on.setEnabled(True) + off.setEnabled(False) + else: + radio.setSelected(False) + on.setEnabled(False) + off.setEnabled(True) + image = new_device.get_icon() + icon_img = os.path.join(base_window.images, image) + icon.setImage(icon_img) + + def __set_focus_and_navigation_handling(self): + xbmc.log("SwitchWindow: __set_focus_and_navigation_handling: ", level=xbmc.LOGDEBUG) + button = self.controls[statics.RADIO] + self.set_navigation_handling_for_automatik_and_favorit(button) + self.setFocus(button) + + def onClick(self, controlId): + xbmc.log("SwitchWindow: onClick: controlls: " + repr(self.controls), level=xbmc.LOGDEBUG) + button = self.controls[statics.RADIO] + autoButton = self.controls[statics.AUTO] + if statics.FAVORITEN not in self.controls: + self.controls.update(self.get_base_device_controls(self.device)) + favoriten_radio_control = self.controls[statics.FAVORITEN] + on = self.getControl(115) + off = self.getControl(117) + if controlId == button.getId(): + if button.isSelected(): + on.setEnabled(True) + off.setEnabled(False) + self.client.switch_on(self.device.get_device_id()) + else: + on.setEnabled(False) + off.setEnabled(True) + self.client.switch_off(self.device.get_device_id()) + if controlId == autoButton.getId(): + self.handle_automation(self.device.get_device_id(), autoButton.isSelected(), self.device.is_automated()) + + if controlId == favoriten_radio_control.getId(): + self.handle_favorit(self.device.get_device_id(), favoriten_radio_control.isSelected(), + self.device.is_favored(), self.use_local_favorites) + + def onAction(self, action): + xbmc.log("SwitchWindow: onAction: ", level=xbmc.LOGDEBUG) + base_window.BaseWindow.onAction(self, action) + + def is_closed(self): + return base_window.BaseWindow.is_closed() diff --git a/script.homepilot/resources/lib/__init__.py b/script.homepilot/resources/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/script.homepilot/resources/lib/device_windows.py b/script.homepilot/resources/lib/device_windows.py deleted file mode 100644 index f9840e7..0000000 --- a/script.homepilot/resources/lib/device_windows.py +++ /dev/null @@ -1,750 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import sys -import time -import math -import xbmc -import xbmcgui -import xbmcaddon -import threading -import os -import xbmcaddon -import homepilot_utils -import local_favorites -__addon__ = xbmcaddon.Addon(id='script.homepilot') -__addon_path__ = __addon__.getAddonInfo('path').decode("utf-8") -_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media', 'devices') -_control_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media') - -class BaseWindow(xbmcgui.WindowXMLDialog): - - def is_closed(self): - return self.is_closed - - def onAction(self, action): - if action == 92 or action == 160 or action == 21: - self.close() - self.is_closed = True - if action == 10: - self.parent_window.shutdown() - self.close() - self.is_closed = True - - def add_error_control(self): - label = __addon__.getLocalizedString(32381) - self.errorcontrol = xbmcgui.ControlLabel(280, 250, 350, 75, label, alignment=0x00000002) - self.addControl(self.errorcontrol) - - -class ErrorWindow(BaseWindow): - - def __init__( self, *args, **kwargs ): - self.parent_window = kwargs["parent"] - - def onInit(self): - self.add_error_control() - - def onAction(self, action): - BaseWindow.onAction(self, action) - - -class MeterWindow(BaseWindow): - - def __init__( self, *args, **kwargs ): - xbmcgui.WindowXMLDialog.__init__( self ) - self.client = kwargs["client"] - self.did = kwargs["did"] - self.parent_window = kwargs["parent"] - - def onInit(self): - - self.__disable_favorite_and_automatik_control() - self.__resize_window() - try: - self.meter = self.client.get_meter_by_id(self.did) - self.__add__controls() - self.errorcontrol = None - except Exception, e: - xbmc.log(str(e), level=xbmc.LOGWARNING) - self.add_error_control() - - - def __add__controls(self): - controls = [] - self.icon_control = self.__get_icon_control() - controls.append(self.icon_control) - title = self.meter.get_name() - self.title_control = xbmcgui.ControlLabel(310, 55, 600, 75, title, font="font16", textColor="white") - controls.append(self.title_control) - label = __addon__.getLocalizedString(32389) - aktuell_control = xbmcgui.ControlLabel(300, 110, 600, 75, label, font="font12", textColor="white") - controls.append(aktuell_control) - self.data_controls = self.__get_data_controls() - controls.extend(self.data_controls) - self.addControls(controls) - - def __get_icon_control(self): - icon = self.meter.get_icon() - icon_img = os.path.join(_images, icon) - image_control = xbmcgui.ControlImage(260, 55, 40,40, icon_img) - return image_control - - def __get_data_controls(self): - data = self.meter.get_data() - y = 150 - data_controls = [] - for data_dict in data: - for d in data_dict: - label = d + ": " + data_dict[d] - data_control = xbmcgui.ControlLabel(300, y, 600, 75, label, font="font12", textColor="white") - y += 35 - data_controls.append(data_control) - return data_controls - - def update(self): - try: - new_meter = self.client.get_meter_by_id(self.did) - if new_meter.get_sync() != self.meter.get_sync(): - if new_meter.get_name() != self.meter.get_name(): - xbmc.log("-- name has changed ", level=xbmc.LOGNOTICE) - self.title_control.setLabel(new_meter.get_name()) - if new_meter.get_icon() != self.meter.get_icon(): - self.removeControl(self.icon_control) - self.icon_control = self.__get_icon_control() - self.addControl(self.icon_control) - self.removeControls(self.data_controls) - self.data_controls = self.__get_data_controls() - self.addControls(self.data_controls) - self.meter = new_meter - except Exception, e: - xbmc.log(str(e), level=xbmc.LOGWARNING) - - def __disable_favorite_and_automatik_control(self): - automation_control = self.getControl(138) - automation_control.setVisible(False) - favorit_control = self.getControl(134) - favorit_control.setVisible(False) - automatik_control = self.getControl(130) - automatik_control.setVisible(False) - - def __resize_window(self): - background = self.getControl(1002) - background.setWidth(600) - separator = self.getControl(1004) - if xbmc.getSkinDir() == "skin.confluence": - separator.setWidth(620) - close_icon = self.getControl(1003) - close_icon.setPosition(780, close_icon.getY()) - else: - separator.setWidth(540) - - - def onAction(self, action): - BaseWindow.onAction(self, action) - - - -sliderbarImg = os.path.join(_control_images, 'slider.png') -sliderNibImg = os.path.join(_control_images, 'osd_slider_nib.png') -sliderNibImgNF = os.path.join(_control_images, 'osd_slider_nibNF.png') -PERCENT_TYPE = "PERCENT" -DEGREE_TYPE = "DEGREE" - - -class SliderUpdater (threading.Thread): - - def __init__(self, client, device, type): - threading.Thread.__init__(self) - self.position = -1 - self.update_time = 0 - self.client = client - self.device = device - self.status = "NOTHING" - self.type = type - - def update_slider (self, new_value): - if self.position != new_value: - #xbmc.log(str(self.position), xbmc.LOGNOTICE) - #xbmc.log(str(new_value), xbmc.LOGNOTICE) - self.update_time = time.time() - self.position = new_value - self.status = "UPDATE" - - def set_is_running (self, is_running): - self.is_running = is_running - - def get_status(self): - return self.status - - def run(self): - self.is_running = 'True' - count = 0 - while self.is_running: - if self.update_time > 0 and time.time() - self.update_time > 0.4: - if self.status == "UPDATE": - #xbmc.log("-- send move --" + str(self.position), xbmc.LOGNOTICE) - if self.type == PERCENT_TYPE and count < 3: - success = self.client.move_to_position(self.device.get_device_id(), self.position) - if success: - self.status = "UPDATE_SENT" - count = 0 - else: - count += 1 - elif count < 3: - success = self.client.move_to_degree(self.device.get_device_id(), self.position) - if success: - self.status = "UPDATE_SENT" - count = 0 - else: - count += 1 - time.sleep(0.3) - -class DeviceWindow(BaseWindow): - ''' - Parent class for all types of devices (Thermostat, Schalter, Dimmer, Tor, ...) - ''' - - def __init__( self, *args, **kwargs ): - xbmcgui.WindowXMLDialog.__init__( self ) - self.x = 250 - self.y = 40 - - def get_base_device_controls(self, device): - control_dict = {} - title = self.device.get_name() - title_control = xbmcgui.ControlLabel(325, 55, 600, 75, title, font="font16", textColor="white") - control_dict["title"] = title_control - icon = self.device.get_icon() - icon_img = os.path.join(_images, icon) - image_control = xbmcgui.ControlImage ( self.x + 80, self.y + 60, 50, 50, icon_img) - control_dict["icon"] = image_control - auto_control = self.getControl(132) - auto_control.setSelected(device.is_automated()) - control_dict["auto"] = auto_control - fav_control = self.getControl(136) - if self.use_local_favorites: - favored_devices = local_favorites.get_devices_as_set() - if device.get_device_id() in favored_devices: - fav_control.setSelected(True) - else: - fav_control.setSelected(False) - else: - fav_control.setSelected(device.is_favored()) - control_dict["favoriten"] = fav_control - return control_dict - - def get_slider (self): - if xbmc.skinHasImage ('settings/slider_back.png'): - statusSlider = xbmcgui.ControlSlider(self.x + 30, self.y + 130, 310, 15, textureback = 'settings/slider_back.png', texture = 'settings/orb_nofo.png', texturefocus = 'settings/orb_fo.png') - return statusSlider - elif xbmc.skinHasImage ('slider.png'): - statusSlider = xbmcgui.ControlSlider(self.x + 80, self.y + 130, 240, 20, textureback = 'slider.png', texture = 'osd_slider_nibNF.png', texturefocus = 'osd_slider_nib.png') - return statusSlider - else: - statusSlider = xbmcgui.ControlSlider(self.x + 80, self.y + 130, 240, 20, textureback = sliderbarImg, texture = sliderNibImgNF, texturefocus = sliderNibImg) - return statusSlider - - def handle_automation(self, deviceId, is_selected, is_automated): - if is_selected and not is_automated: - self.client.set_device_automation_on(deviceId) - elif not is_selected and is_automated: - self.client.set_device_automation_off(deviceId) - - def handle_favorit(self, deviceId, is_selected, is_favorited, use_local_favorites): - favored_devices = local_favorites.get_devices_as_set() - if use_local_favorites: - if is_selected and not deviceId in favored_devices: - local_favorites.add_device(deviceId) - elif not is_selected and deviceId in favored_devices: - local_favorites.remove_device(deviceId) - else: - if is_selected and not is_favorited: - self.client.favorize_device(deviceId) - elif not is_selected and is_favorited: - self.client.unfavorize_device(deviceId) - - def set_navigation_handling_for_automatik_and_favorit(self, previous_control): - autoButton = self.getControl(132) - favorit_button = self.getControl(136) - autoScrollbar = self.getControl(142) - previous_control.controlRight(autoButton) - previous_control.controlDown(autoButton) - autoButton.controlLeft(previous_control) - autoButton.controlUp(previous_control) - autoButton.controlRight(favorit_button) - autoButton.controlDown(favorit_button) - favorit_button.controlLeft(autoButton) - favorit_button.controlUp(autoButton) - favorit_button.controlDown(autoScrollbar) - favorit_button.controlRight(autoScrollbar) - autoScrollbar.controlLeft(favorit_button) - autoScrollbar.controlUp(favorit_button) - - def visualize_automations(self, device): - automation_list = self.getControl(142) - automation_list.reset() - automations = device.get_automationen() - homepilot_utils.add_device_to_automation_list(automation_list, automations, __addon__) - -class PercentageWindow(DeviceWindow): - - def __init__( self, *args, **kwargs ): - DeviceWindow.__init__( self ) - self.client = kwargs["client"] - self.device = kwargs["device"] - self.parent_window = kwargs["parent"] - self.use_local_favorites = kwargs["local_favs"] - self.updater = SliderUpdater(self.client, self.device, PERCENT_TYPE) - self.updater.start() - self.has_error = False - self.controls = {} - self.errorcontrol = None - - def onInit(self): - base_device_controls = self.get_base_device_controls(self.device) - percent_controls = self.__get_percent_controls() - self.controls = base_device_controls - self.controls.update(percent_controls) - if self.device.get_devicegroup() == 2: - button_group = self.getControl(1141) - else: - button_group = self.getControl(114) - button_group.setPosition(330,200) - self.addControls([self.controls["slider"], self.controls["status"], self.controls["title"], self.controls["icon"]]) - slider = self.controls["slider"] - slider.setPercent(self.device.get_position()) - self.__set_focus_and_navigation_handling() - self.visualize_automations(self.device) - - def __get_percent_controls (self): - controls = {} - x = self.x - y = self.y - status = self.device.get_display_value() - status_control = xbmcgui.ControlLabel(self.x+ 180, self.y + 65, 600, 75, status, font="font16", textColor="white") - controls["status"] = status_control - slider = self.get_slider() - controls["slider"] = slider - slider.setPercent(self.device.get_position()) - if self.device.get_devicegroup() == 2: - down_button = self.getControl(1121) - up_button = self.getControl(1131) - else: - down_button = self.getControl(112) - up_button = self.getControl(113) - controls["down"] = down_button - controls["up"] = up_button - return controls - - def update(self): - if self.getFocusId() == 0: - if self.controls.get("slider") is not None: - self.setFocus(self.controls.get("slider")) - if self.updater.get_status() != "UPDATE": - #xbmc.log("-- update -- no status update awaiting", xbmc.LOGNOTICE) - try: - new_device = self.client.get_device_by_id(self.device.get_device_id()) - if new_device.get_sync() != self.device.get_sync():#device has changed - self.__update_position(new_device) - self.__update_name(new_device) - self.device = new_device - if self.has_error and self.errorcontrol is not None: - self.removeControl(self.errorcontrol) - self.errorcontrol = None - self.has_error = False - except Exception, e: - xbmc.log(str(e), level=xbmc.LOGWARNING) - self.has_error = True - else: - try: - new_device = self.client.get_device_by_id(self.device.get_device_id()) - if new_device.get_sync() != self.device.get_sync():#device has changed - self.__update_icon(new_device) - self.__update_name(new_device) - if self.has_error: - if self.errorcontrol is not None: - self.removeControl(self.errorcontrol) - self.errorcontrol = None - self.has_error = False - except Exception, e: - xbmc.log(str(e), level=xbmc.LOGWARNING) - self.has_error = True - - if self.has_error and self.errorcontrol is None: - self.add_error_control() - - - def __update_icon(self, new_device): - icon = self.controls["icon"] - image = new_device.get_icon() - icon_img = os.path.join(_images, image) - icon.setImage(icon_img) - - def __update_position (self, new_device): - self.__update_icon(new_device) - if new_device.get_position() != self.device.get_position(): - statusSlider = self.controls["slider"] - #xbmc.log("set slider to position: " + str(new_device.get_position()), xbmc.LOGNOTICE) - statusSlider.setPercent(new_device.get_position()) - self.device = new_device - statusLabel = self.controls["status"] - statusLabel.setLabel(new_device.get_display_value()) - - - def __update_name(self, new_device): - if new_device.get_name() != self.device.get_name(): - title_label = self.controls["title"] - title_label.setLabel(new_device.get_name()) - - - def __set_focus_and_navigation_handling(self): - statusSlider = self.controls["slider"] - downButton = self.controls["down"] - upButton = self.controls["up"] - - self.setFocus(statusSlider) - if self.device.get_devicegroup() == 2: - statusSlider.controlDown(upButton) - upButton.controlDown(downButton) - upButton.controlRight(downButton) - upButton.controlUp(statusSlider) - upButton.controlLeft(statusSlider) - downButton.controlUp(upButton) - downButton.controlLeft(upButton) - self.set_navigation_handling_for_automatik_and_favorit(downButton) - else: - statusSlider.controlDown(downButton) - downButton.controlDown(upButton) - downButton.controlRight(upButton) - downButton.controlUp(statusSlider) - downButton.controlLeft(statusSlider) - upButton.controlUp(downButton) - upButton.controlLeft(downButton) - self.set_navigation_handling_for_automatik_and_favorit(upButton) - - - def onClick (self, controlId): - statusSlider = self.controls["slider"] - down_button = self.controls["down"] - up_button = self.controls["up"] - auto_button = self.controls["auto"] - favoriten_radio_control = self.controls["favoriten"] - status = self.device.get_status() - #handle up-down-buttons - device_group = self.device.get_devicegroup() - try: - if device_group == 2 or device_group == 4 or device_group == 8:#rollo,dimmer,tore - if controlId == down_button.getId(): - self.client.move_down(self.device.get_device_id()) - elif controlId == up_button.getId(): - self.client.move_up(self.device.get_device_id()) - else: - if controlId == down_button.getId(): - if status <= 95: - self.client.move_to_position(self.device.get_device_id(), status + 5) - elif controlId == up_button.getId(): - if status >= 5: - self.client.move_to_position(self.device.get_device_id(), status - 5) - except Exception, e: - xbmc.log(str(e), level=xbmc.LOGWARNING) - self.has_error = True - - #handle slider - if controlId == statusSlider.getId(): - current_slider_value = statusSlider.getPercent() - statusLabel = self.controls["status"] - device_group = self.device.get_devicegroup() - display_value = homepilot_utils.get_display_value(int(current_slider_value), device_group) - statusLabel.setLabel(display_value) - if current_slider_value > status: - new_position = current_slider_value - self.updater.update_slider(new_position) - elif current_slider_value < status: - new_position = current_slider_value - self.updater.update_slider(new_position) - - if controlId == auto_button.getId(): - self.handle_automation(self.device.get_device_id(), auto_button.isSelected(), self.device.is_automated()) - - if controlId == favoriten_radio_control.getId(): - self.handle_favorit(self.device.get_device_id(), favoriten_radio_control.isSelected(), self.device.is_favored(), self.use_local_favorites) - - - def onAction(self, action): - if action == 92 or action == 10: - self.updater.set_is_running(False) - BaseWindow.onAction(self, action) - -class SwitchWindow(DeviceWindow): - - def __init__( self, *args, **kwargs ): - DeviceWindow.__init__( self ) - self.client = kwargs["client"] - self.device = kwargs["device"] - self.parent_window = kwargs["parent"] - self.use_local_favorites = kwargs["local_favs"] - self.wait_for_response = False - self.updater = SliderUpdater(self.client, self.device, DEGREE_TYPE) - self.errorcontrol = None - self.has_error = False - - def onInit(self): - base_device_controls = self.get_base_device_controls(self.device) - switch_controls = self.__get_switch_controls() - - self.controls = base_device_controls - self.controls.update(switch_controls) - self.addControls([self.controls["title"], self.controls["icon"]]) - self.__set_focus_and_navigation_handling() - self.visualize_automations(self.device) - - def __get_switch_controls(self): - controls = {} - group_control = self.getControl(118) - group_control.setPosition(350, 100) - - radio = self.getControl(116) - on = self.getControl(115) - off = self.getControl(117) - if self.device.get_position() > 0: - radio.setSelected(True) - on.setEnabled(True) - off.setEnabled(False) - else: - radio.setSelected(False) - on.setEnabled(False) - off.setEnabled(True) - controls["group"] = group_control - controls["radio"] = radio - controls["on"] = on - controls["off"] = off - return controls - - def update (self): - if self.getFocusId() == 0: - self.setFocusId(116) - try: - new_device = self.client.get_device_by_id(self.device.get_device_id()) - if new_device.get_sync() != self.device.get_sync(): - if new_device.get_position() != self.device.get_position(): - self.__set_state(new_device) - if new_device.get_name() != self.device.get_name(): - title_label = self.controls["title"] - title_label.setLabel(new_device.get_name()) - self.device = new_device - if self.has_error: - self.has_error = False - if self.errorcontrol is not None: - self.removeControl(self.errorcontrol) - self.errorcontrol = None - except Exception, e: - xbmc.log(str(e), level=xbmc.LOGWARNING) - self.has_error = True - - if self.has_error and self.errorcontrol is None: - self.add_error_control() - - def __set_state(self, new_device): - radio = self.getControl(116) - on = self.getControl(115) - off = self.getControl(117) - icon = self.controls["icon"] - if new_device.get_position() > 0: - radio.setSelected(True) - on.setEnabled(True) - off.setEnabled(False) - else: - radio.setSelected(False) - on.setEnabled(False) - off.setEnabled(True) - image = new_device.get_icon() - icon_img = os.path.join(_images, image) - icon.setImage(icon_img) - - def __set_focus_and_navigation_handling(self): - button = self.controls["radio"] - self.set_navigation_handling_for_automatik_and_favorit(button) - self.setFocus(button) - - def onClick (self, controlId): - button = self.controls["radio"] - autoButton = self.controls["auto"] - favoriten_radio_control = self.controls["favoriten"] - on = self.getControl(115) - off = self.getControl(117) - if controlId == button.getId(): - if button.isSelected(): - on.setEnabled(True) - off.setEnabled(False) - self.client.switch_on(self.device.get_device_id()) - else: - on.setEnabled(False) - off.setEnabled(True) - self.client.switch_off(self.device.get_device_id()) - if controlId == autoButton.getId(): - self.handle_automation(self.device.get_device_id(), autoButton.isSelected(), self.device.is_automated()) - - if controlId == favoriten_radio_control.getId(): - self.handle_favorit(self.device.get_device_id(), favoriten_radio_control.isSelected(), self.device.is_favored(), self.use_local_favorites) - - def onAction(self, action): - BaseWindow.onAction(self, action) - -class DegreeWindow(DeviceWindow): - - def __init__( self, *args, **kwargs ): - DeviceWindow.__init__( self ) - self.client = kwargs["client"] - self.device = kwargs["device"] - self.parent_window = kwargs["parent"] - self.use_local_favorites = kwargs["local_favs"] - self.updater = SliderUpdater(self.client, self.device, DEGREE_TYPE) - self.updater.start() - self.errorcontrol = None - self.has_error = False - - def onInit(self): - base_device_controls = self.get_base_device_controls(self.device) - degree_controls = self.__get_degree_controls() - self.controls = base_device_controls - self.controls.update(degree_controls) - button_group = self.getControl(114) - button_group.setPosition(330,200) - self.addControls([self.controls["slider"], self.controls["status"], self.controls["title"], self.controls["icon"]]) - slider = self.controls["slider"] - slider_position = self.__get_slider_percent_from_position(self.device) - slider.setPercent(slider_position) - self.__set_focus_and_navigation_handling() - self.visualize_automations(self.device) - - def __get_degree_controls (self): - controls = {} - x = self.x - y = self.y - status = self.device.get_display_value() - status_control = xbmcgui.ControlLabel(self.x+ 180, self.y + 60, 600, 75, status, font="font16", textColor="white") - controls["status"] = status_control - controls["slider"] = self.get_slider() - controls["down"] = self.getControl(112) - controls["up"] = self.getControl(113) - return controls - - def __get_slider_percent_from_position (self, device): - position = device.get_position() - return (float(position)/10 - 3) * 4 - - - def __set_focus_and_navigation_handling(self): - statusSlider = self.controls["slider"] - downButton = self.controls["down"] - upButton = self.controls["up"] - self.setFocus(statusSlider) - statusSlider.controlDown(downButton) - downButton.controlDown(upButton) - downButton.controlRight(upButton) - downButton.controlUp(statusSlider) - downButton.controlLeft(statusSlider) - upButton.controlUp(downButton) - upButton.controlLeft(downButton) - self.set_navigation_handling_for_automatik_and_favorit(upButton) - - def update(self): - if self.getFocusId() == 0: - self.setFocus(self.controls["slider"]) - try: - if self.updater.get_status() != "UPDATE": - new_device = self.client.get_device_by_id(self.device.get_device_id()) - if new_device.get_sync() != self.device.get_sync(): - self.__update_position(new_device) - self.__update_name(new_device) - self.device = new_device - else: - new_device = self.client.get_device_by_id(self.device.get_device_id()) - if new_device.get_sync() != self.device.get_sync(): - self.__update_name(new_device) - self.__update_icon(new_device) - if self.has_error and self.errorcontrol is not None: - self.removeControl(self.errorcontrol) - self.errorcontrol = None - self.has_error = False - except Exception, e: - xbmc.log(str(e), level=xbmc.LOGWARNING) - self.has_error = True - - if self.has_error and self.errorcontrol is None: - self.add_error_control() - - def __update_icon(self, new_device): - icon = self.controls["icon"] - image = new_device.get_icon() - icon_img = os.path.join(_images, image) - icon.setImage(icon_img) - - def __update_position(self, new_device): - if new_device.get_position() != self.device.get_position(): - statusSlider = self.controls["slider"] - new_position = self.__get_slider_percent_from_position(new_device) - statusSlider.setPercent(new_position) - self.device = new_device - statusLabel = self.controls["status"] - statusLabel.setLabel(new_device.get_display_value()) - self.__update_icon(new_device) - - def __update_name (self, new_device): - if new_device.get_name() != self.device.get_name(): - title_label = self.controls["title"] - title_label.setLabel(new_device.get_name()) - - def onClick (self, controlId): - xbmc.log("window click " + str(controlId), level=xbmc.LOGNOTICE) - statusSlider = self.controls["slider"] - downButton = self.controls["down"] - upButton = self.controls["up"] - autoButton = self.controls["auto"] - favoriten_radio_control = self.controls["favoriten"] - current_device_position = self.device.get_position() - current_device_position_in_percent = self.__get_slider_percent_from_position(self.device) - current_slider_position = statusSlider.getPercent() - if controlId == downButton.getId(): - if current_slider_position >= 5: - self.client.move_to_degree(self.device.get_device_id(), current_device_position - 5) - elif controlId == upButton.getId(): - if current_slider_position <= 95: - self.client.move_to_degree(self.device.get_device_id(), current_device_position + 5) - elif controlId == statusSlider.getId(): - if current_slider_position != current_device_position_in_percent: - statusLabel = self.controls["status"] - device_group = self.device.get_devicegroup() - diff = current_slider_position - current_device_position_in_percent - # thermostats can only be shifted in 0.5 degree steps over a range from 3°-28° - # this results in 50 possible value. As the slider has 100 possible values - # this requires some mappings - if current_slider_position < 3: - current_slider_position = 3 - if diff == 1: - new_position = (float(current_slider_position + 1) * 5 + 60) / 2 - if new_position % 5 == 0: - self.updater.update_slider(int(new_position)) - elif diff == -1: - new_position = (float(current_slider_position - 1) * 5 + 60) / 2 - if new_position % 5 == 0: - self.updater.update_slider(int(new_position)) - else: - new_position = (float(current_slider_position) * 5 + 60) / 2 - if new_position % 5 == 0: - self.updater.update_slider(int(new_position)) - - if new_position % 5 == 0: - display_value = homepilot_utils.get_display_value(int(new_position), device_group) - statusLabel.setLabel(display_value) - if controlId == autoButton.getId(): - self.handle_automation(self.device.get_device_id(), autoButton.isSelected(), self.device.is_automated()) - - if controlId == favoriten_radio_control.getId(): - self.handle_favorit(self.device.get_device_id(), favoriten_radio_control.isSelected(), self.device.is_favored(), self.use_local_favorites) - - def onAction(self, action): - if action == 92 or action == 10: - self.updater.set_is_running = False - BaseWindow.onAction(self, action) diff --git a/script.homepilot/resources/lib/homepilot_client.py b/script.homepilot/resources/lib/homepilot_client.py index 71dd912..f32b202 100644 --- a/script.homepilot/resources/lib/homepilot_client.py +++ b/script.homepilot/resources/lib/homepilot_client.py @@ -4,13 +4,14 @@ import requests import json import xbmc -from models import Device, Meter, Group, HomePilotBaseObject, Scene + +from Models import device as import_device, home_pilot_base_object, group, scene as import_scene, meter TIMEOUT = 3 SHORT_TIMEOUT = 2 -class HomepilotClient: +class HomepilotClient: """ Implementation of a client for the HomePilot REST API """ @@ -24,159 +25,172 @@ def __init__(self, homepilot_host): homepilot_host -- the ip address of the homepilot """ self.set_ip_address(homepilot_host) + # self._base_url = None def set_ip_address(self, homepilot_host): - self._base_url = 'http://' + homepilot_host + '/rest2/Index?' - + xbmc.log("HomepilotClient: set_ip_address: " + repr(homepilot_host), level=xbmc.LOGDEBUG) + self._base_url = 'http://' + str(homepilot_host) + '/rest2/Index?' def __map_response_to_devices(self, response): + xbmc.log("HomepilotClient: __map_response_to_devices: ", level=xbmc.LOGDEBUG) data = json.loads(response.content) device_list = data['devices'] - device_objects = map(lambda x: Device(x), device_list) + device_objects = map(lambda x: import_device.Device(x), device_list) return device_objects def __map_response_to_meters(self, response): + xbmc.log("HomepilotClient: __map_response_to_meters: ", level=xbmc.LOGDEBUG) data = json.loads(response.content) device_list = data['meters'] - device_objects = map(lambda x: HomePilotBaseObject(x), device_list) + device_objects = map(lambda x: home_pilot_base_object.HomePilotBaseObject(x), device_list) return device_objects def __map_response_to_groups(self, response): + xbmc.log("HomepilotClient: __map_response_to_groups: ", level=xbmc.LOGDEBUG) data = json.loads(response.content) group_list = data['groups'] - device_objects = map(lambda x: Group(x), group_list) + device_objects = map(lambda x: group.Group(x), group_list) return device_objects def __map_response_to_scenes(self, scene_list): - scene_objects = map(lambda x: Scene(x), scene_list) + xbmc.log("HomepilotClient: __map_response_to_scenes: ", level=xbmc.LOGDEBUG) + scene_objects = map(lambda x: import_scene.Scene(x), scene_list) return scene_objects - def get_devices(self): """ request a list of all devices from the homepilot """ + xbmc.log("HomepilotClient: get_devices: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/devices', timeout=TIMEOUT) return self.__map_response_to_devices(response) - def get_meters(self): """ request a list of all meters from the homepilot """ + xbmc.log("HomepilotClient: get_meters: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/meters', timeout=TIMEOUT) return self.__map_response_to_meters(response) - def get_scenes(self): + xbmc.log("HomepilotClient: get_scenes: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/scenes', timeout=TIMEOUT) data = json.loads(response.content) return self.__map_response_to_scenes(data[u'scenes']) - def get_manual_scenes(self): + xbmc.log("HomepilotClient: get_manual_scenes: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/scenes', timeout=TIMEOUT) data = json.loads(response.content) scene_list = [i for i in data[u'scenes'] if i[u'isExecutable'] == 1] return self.__map_response_to_scenes(scene_list) - def get_non_manual_scenes(self): + xbmc.log("HomepilotClient: get_non_manual_scenes: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/scenes', timeout=TIMEOUT) data = json.loads(response.content) scene_list = [i for i in data[u'scenes'] if i[u'isExecutable'] == 0] return self.__map_response_to_scenes(scene_list) - def get_scene_by_id(self, scene_id): + xbmc.log("HomepilotClient: get_scene_by_id: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/scenes/' + str(scene_id), timeout=TIMEOUT) data = json.loads(response.content) scene = data['scene'] - return Scene(scene) + return import_scene.Scene(scene) def favorize_scene(self, scene_id): - xbmc.log("---home_client.py-- favorisiere Szene " + str(scene_id), level=xbmc.LOGNOTICE) + xbmc.log("HomepilotClient: favorize_scene: ", level=xbmc.LOGDEBUG) + xbmc.log("---home_client.py-- favorisiere Szene " + str(scene_id), level=xbmc.LOGNOTICE) url = self._base_url + 'do=/scenes/' + str(scene_id) + '?do=setFavored' return self._call_url(url) def unfavorize_scene(self, scene_id): - xbmc.log("---home_client.py-- unfavorisiere Szene " + str(scene_id), level=xbmc.LOGNOTICE) + xbmc.log("HomepilotClient: unfavorize_scene: ", level=xbmc.LOGDEBUG) + xbmc.log("---home_client.py-- unfavorisiere Szene " + str(scene_id), level=xbmc.LOGNOTICE) url = self._base_url + 'do=/scenes/' + str(scene_id) + '?do=setUnfavored' return self._call_url(url) def get_favorite_scenes(self): + xbmc.log("HomepilotClient: get_favorite_scenes: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/scenes/favorites/', timeout=TIMEOUT) data = json.loads(response.content) return self.__map_response_to_scenes(data[u'scenes']) def execute_scene(self, scene_id): - xbmc.log("execute scene: " + str(scene_id), level=xbmc.LOGNOTICE) + xbmc.log("HomepilotClient: execute_scene: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/scenes/' + str(scene_id) + '?do=use' return self._call_url(url) def set_scene_active(self, scene_id): - xbmc.log("set scene active: " + str(scene_id), level=xbmc.LOGNOTICE) + xbmc.log("HomepilotClient: set_scene_active: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/scenes/' + str(scene_id) + '?do=setActive&state=1' return self._call_url(url) def set_scene_inactive(self, scene_id): - xbmc.log("set scene inactive: " + str(scene_id), level=xbmc.LOGNOTICE) + xbmc.log("HomepilotClient: set_scene_inactive: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/scenes/' + str(scene_id) + '?do=setActive&state=0' return self._call_url(url) def unfavorize_device(self, device_id): + xbmc.log("HomepilotClient: unfavorize_device: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/devices/' + str(device_id) + '?do=setUnfavored' return self._call_url(url) - def get_devices_by_device_group(self, group_id): """ request a list of all devices for a specific devicegroup + :param group_id: """ + xbmc.log("HomepilotClient: get_devices_by_device_group: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/devices/devicegroup/' + str(group_id), timeout=TIMEOUT) return self.__map_response_to_devices(response) - def get_devices_by_group(self, group_id): """ request a list of all devices for a specific devicegroup + :param group_id: """ + xbmc.log("HomepilotClient: get_devices_by_group: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/groups/' + str(group_id), timeout=TIMEOUT) return self.__map_response_to_devices(response) - def get_favorite_devices(self): """ request favorite devices """ + xbmc.log("HomepilotClient: get_favorite_devices: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/devices/favorites/', timeout=TIMEOUT) return self.__map_response_to_devices(response) - def get_groups(self): + xbmc.log("HomepilotClient: get_groups: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/groups', timeout=TIMEOUT) return self.__map_response_to_groups(response) - def get_device_by_id(self, device_id): """ request device by id + :param device_id: """ + xbmc.log("HomepilotClient: get_device_by_id: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/devices/' + str(device_id), timeout=SHORT_TIMEOUT) data = json.loads(response.content) device = data['device'] - return Device(device) - + return import_device.Device(device) def get_meter_by_id(self, device_id): """ request device by id + :param device_id: """ + xbmc.log("HomepilotClient: get_meter_by_id: ", level=xbmc.LOGDEBUG) response = requests.get(self._base_url + 'do=/meters/' + str(device_id), timeout=SHORT_TIMEOUT) data = json.loads(response.content) device = data['meter'] data = data['data'] - return Meter(device, data) + return meter.Meter(device, data) def switch_on(self, device_id): """ @@ -185,22 +199,24 @@ def switch_on(self, device_id): Arguments: device_id -- the id of the device that should be switched on + :param device_id: """ + xbmc.log("HomepilotClient: switch_on: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/devices/' + str(device_id) + '?do=use&cmd=10' return self._call_url(url) - def set_device_automation_on(self, device_id): + xbmc.log("HomepilotClient: set_device_automation_on: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/devices/' + str(device_id) + '?do=setAutomation&state=1' return self._call_url(url) - def set_device_automation_off(self, device_id): + xbmc.log("HomepilotClient: set_device_automation_off: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/devices/' + str(device_id) + '?do=setAutomation&state=0' return self._call_url(url) - def switch_off(self, device_id): + xbmc.log("HomepilotClient: switch_off: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/devices/' + str(device_id) + '?do=use&cmd=11' return self._call_url(url) @@ -213,13 +229,17 @@ def move_to_position(self, device_id, position): device_id -- the id of the device that should be moved position -- the position to which the device should be moved + :param position: + :param device_id: """ - assert position >= 0 and position <= 100 + xbmc.log("HomepilotClient: move_to_position: ", level=xbmc.LOGDEBUG) + assert 0 <= position <= 100 url = self._base_url + 'do=/devices/' + str(device_id) + '?do=use&cmd=9&pos=' + str(int(position)) return self._call_url(url) def move_to_degree(self, device_id, position): - assert position >= 30 and position <= 280 + xbmc.log("HomepilotClient: move_to_degree: ", level=xbmc.LOGDEBUG) + assert 30 <= position <= 280 url = self._base_url + 'do=/devices/' + str(device_id) + '?do=use&cmd=9&pos=' + str(int(position)) return self._call_url(url) @@ -230,30 +250,35 @@ def ping(self, device_id): Arguments: device_id -- the id of the device that should be pinged + :param device_id: """ + xbmc.log("HomepilotClient: ping: device_id: " + str(device_id), level=xbmc.LOGDEBUG) url = self._base_url + 'do=/devices/' + str(device_id) + '?do=use&cmd=12' return self._call_url(url) + @property def ping(self): - """ - Pings the homepilot - """ + xbmc.log("HomepilotClient: ping: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/ping?var=1359030565' return self._call_url(url) def favorize_device(self, device_id): + xbmc.log("HomepilotClient: favorize_device: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/devices/' + str(device_id) + '?do=setFavored' return self._call_url(url) def move_up(self, device_id): + xbmc.log("HomepilotClient: move_up: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/devices/' + str(device_id) + '?do=use&cmd=1' return self._call_url(url) def move_down(self, device_id): + xbmc.log("HomepilotClient: move_down: ", level=xbmc.LOGDEBUG) url = self._base_url + 'do=/devices/' + str(device_id) + '?do=use&cmd=3' return self._call_url(url) def _call_url(self, url): + xbmc.log("HomepilotClient: _call_url: ", level=xbmc.LOGDEBUG) try: response = requests.get(url, timeout=TIMEOUT) data = json.loads(response.content) diff --git a/script.homepilot/resources/lib/homepilot_utils.py b/script.homepilot/resources/lib/homepilot_utils.py index 30622a8..08c011d 100644 --- a/script.homepilot/resources/lib/homepilot_utils.py +++ b/script.homepilot/resources/lib/homepilot_utils.py @@ -5,69 +5,22 @@ import xbmcgui import xbmc import xbmcaddon +import statics + +__addon__ = xbmcaddon.Addon(id='script.homepilot') +__addon_path__ = __addon__.getAddonInfo('path').decode("utf-8") +_automation_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media', 'automations') +_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media') +icons_automation = {"generic": "global_sensor_12_", "wind": "wind_12_", "trigger": "trigger_12_", + "closingContact": "schliesskontakt_12_", "dusk": "mond_12_", "dawn": "morgendaemmerung_12_", + "time": "uhr_12_", "smoke": "rauchmelder_12_", "sun": "sonne_12_", "temperature": "temperatur_12_", + "manual": "global_sensor_12_", "dust": "global_sensor_12_", "favored": "favorite_status_12_", + "smartphone": "global_sensor_12_", "motion": "bewegungsmelder_12_", + "temperator": "global_sensor_12_", "warning": "warning_12_", "rain": "regen_12_"} -SENSOREN = 32007 -SZENEN = 32005 -SZENENTYPEN = 32016 -GRUPPEN = 32015 -#GERAETE = 32021 - -ROLLADEN = 32010 -SCHALTER = 32011 -DIMMER = 32012 -THERMOSTATE = 32013 -TORE = 32014 -ALLE = 32020 - -SZENEN_MANUELL = 32017 -SZENEN_NICHT_MANUELL = 32018 -SZENEN_ALLE = 32019 - -SZENEN_DETAILS = 100 -FAVORITEN = 101 -FAVORITEN_LOKAL = 102 - - -icons = {} -icons["iconset1"] = "aquarium_72_" -icons["iconset2"] = "bargraph_vertikal_72_" -icons["iconset4"] = "deckenlampe_72_" -icons["iconset5"] = "ein_aus_schalter1_72_" -icons["iconset6"] = "jalousie_72_" -icons["iconset7"] = "markise_72_" -icons["iconset8"] = "rollladen1_72_" -icons["iconset9"] = "schiebetuer_72_" -icons["iconset10"] = "steckdose_72_" -icons["iconset11"] = "tischlampe_72_" -icons["iconset12"] = "tuer_72_" -icons["iconset13"] = "stehlampe_72_" -icons["iconset14"] = "schiebeladen_72_" -icons["iconset15"] = "rollladen2_72_" -icons["iconset16"] = "pumpe_72_" -icons["iconset17"] = "kaffeemaschine_72_" -icons["iconset18"] = "gartensprenkler_72_" -#icons["iconset19"] -> Standard -icons["iconset20"] = "sunscreen_72_" -icons["iconset21"] = "birne1_72_" -icons["iconset22"] = "bargraph_horizontal_72_" -icons["iconset23"] = "bewegungsmelder_72_" -icons["iconset24"] = "fenster_72_" -icons["iconset25"] = "genericsensor_72_" -icons["iconset26"] = "rauchmelder_72_" -icons["iconset27"] = "schliesskontakt_72_" -icons["iconset28"] = "thermostat_72_" -icons["iconset30"] = "garage_72_" -icons["iconset31"] = "sektionaltor_72_" -icons["iconset32"] = "lichterkette_72_" -icons["iconset33"] = "weihnachtsbaum_72_" -icons["iconset34"] = "dachfenster_72_" -icons["iconset35"] = "handsender_72_" -icons["iconset36"] = "leinwand_72_" -icons["iconset37"] = "radio_72_" -icons["iconset38"] = "smartphone_72_" -icons["iconset39"] = "ventilator_72_" def get_display_value(position, group): + xbmc.log("homepilot_utils: get_display_value: ", level=xbmc.LOGDEBUG) if group == 1: if position < 50: return "Aus" @@ -78,25 +31,27 @@ def get_display_value(position, group): elif group == 4 or group == 8 or group == 2: return str(position) + " %" elif group == 5: - return str(float(position)/10) + " °C" + return str(float(position) / 10) + " °C" else: return str(position) + def get_iconset_inverted(_icon_set_inverted): + xbmc.log("homepilot_utils: get_iconset_inverted: ", level=xbmc.LOGDEBUG) return _icon_set_inverted is not None and _icon_set_inverted != 0 def get_icon(_icon_set, _icon_set_inverted, _position, _deviceGroup): - if _icon_set in icons: - base_icon = icons[_icon_set] - #An-/Aus-Icons + xbmc.log("homepilot_utils: get_icon: ", level=xbmc.LOGDEBUG) + if _icon_set in statics.icons: + base_icon = statics.icons[_icon_set] + # An-/Aus-Icons position = _position if _deviceGroup == 5: - position = (float(position)/10 - 3) * 4 - an_aus = set( - ["iconset1", "iconset23", "iconset5", "iconset24", "iconset18", "iconset17", "iconset16", "iconset26", - "iconset27", "iconset25", "iconset10", "iconset12", "iconset32", "iconset33", "iconset34", - "iconset37", "iconset38", "iconset39"]) + position = (float(position) / 10 - 3) * 4 + an_aus = {"iconset1", "iconset23", "iconset5", "iconset24", "iconset18", "iconset17", "iconset16", "iconset26", + "iconset27", "iconset25", "iconset10", "iconset12", "iconset32", "iconset33", "iconset34", + "iconset37", "iconset38", "iconset39"} if _icon_set in an_aus: if get_iconset_inverted(_icon_set_inverted): return __get_icon_switch_inverted(position, base_icon) @@ -115,6 +70,7 @@ def get_icon(_icon_set, _icon_set_inverted, _position, _deviceGroup): def __get_icon_switch(position, base_icon): + xbmc.log("homepilot_utils: __get_icon_switch: ", level=xbmc.LOGDEBUG) if position == 0: return base_icon + "0.png" else: @@ -122,6 +78,7 @@ def __get_icon_switch(position, base_icon): def __get_icon_switch_inverted(position, base_icon): + xbmc.log("homepilot_utils: __get_icon_switch_inverted: ", level=xbmc.LOGDEBUG) if position == 0: return base_icon + "1.png" else: @@ -129,6 +86,7 @@ def __get_icon_switch_inverted(position, base_icon): def __get_icon_percent(position, base_icon): + xbmc.log("homepilot_utils: __get_icon_percent: ", level=xbmc.LOGDEBUG) if position < 12: return base_icon + "0.png" elif position < 37: @@ -142,6 +100,7 @@ def __get_icon_percent(position, base_icon): def __get_icon_percent_inverted(position, base_icon): + xbmc.log("homepilot_utils: __get_icon_percent_inverted: ", level=xbmc.LOGDEBUG) if position < 12: return base_icon + "100.png" elif position < 37: @@ -153,95 +112,22 @@ def __get_icon_percent_inverted(position, base_icon): else: return base_icon + "0.png" -__addon__ = xbmcaddon.Addon(id='script.homepilot') -__addon_path__ = __addon__.getAddonInfo('path').decode("utf-8") -_automation_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media', 'automations') -_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media') -icons_automation = {} -icons_automation["generic"] = "global_sensor_12_" -icons_automation["wind"] = "wind_12_" -icons_automation["trigger"] = "trigger_12_" -icons_automation["closingContact"] = "schliesskontakt_12_" -icons_automation["dusk"] = "mond_12_" -icons_automation["dawn"] = "morgendaemmerung_12_" -icons_automation["time"] = "uhr_12_" -icons_automation["smoke"] = "rauchmelder_12_" -icons_automation["sun"] = "sonne_12_" -icons_automation["temperature"] = "temperatur_12_" -# TODO -icons_automation["manual"] = "global_sensor_12_" -# TODO -icons_automation["dust"] = "global_sensor_12_" -icons_automation["favored"] = "favorite_status_12_" -# TODO -icons_automation["smartphone"] = "global_sensor_12_" -icons_automation["motion"] = "bewegungsmelder_12_" -# TODO -icons_automation["temperator"] = "global_sensor_12_" -icons_automation["warning"] = "warning_12_" -icons_automation["rain"] = "regen_12_" def add_scene_to_automation_list(automation_list, automations, addon): - dusk = automations.get_dusk() - _add_scene_item("dusk", dusk, automation_list, addon) - - dawn = automations.get_dawn() - _add_scene_item("dawn", dawn, automation_list, addon) - - time = automations.get_time() - _add_scene_item("time", time, automation_list, addon) - - generic = automations.get_generic() - _add_scene_item("generic", generic, automation_list, addon) - - wind = automations.get_wind() - _add_scene_item("wind", wind, automation_list, addon) - - trigger = automations.get_trigger() - _add_scene_item("trigger", trigger, automation_list, addon) - - closingContact = automations.get_closing_contact() - _add_scene_item("closingContact", closingContact, automation_list, addon) - - dust = automations.get_dust() - _add_scene_item("dust", dust, automation_list, addon) - - smoke = automations.get_smoke() - _add_scene_item("smoke", smoke, automation_list, addon) - - sun = automations.get_sun() - _add_scene_item("sun", sun, automation_list, addon) - - temperature = automations.get_temperature() - _add_scene_item("temperature", temperature, automation_list, addon) - - manual = automations.get_manual() - _add_scene_item("manual", manual, automation_list, addon) - - favored = automations.get_favored() - _add_scene_item("favored", favored, automation_list, addon) - - smartphone = automations.get_smartphone() - _add_scene_item("smartphone", smartphone, automation_list, addon) - - motion = automations.get_motion() - _add_scene_item("motion", motion, automation_list, addon) - - temperator = automations.get_temperator() - _add_scene_item("temperator", temperator, automation_list, addon) - - warning = automations.get_warning() - _add_scene_item("warning", warning, automation_list, addon) - - rain = automations.get_rain() - _add_scene_item("rain", rain, automation_list, addon) - + xbmc.log("homepilot_utils: add_scene_to_automation_list: automation_list: " + repr(automation_list), + level=xbmc.LOGDEBUG) + for prop in automations.get_props(): + _add_scene_item(str(prop), automations.get_props()[prop], automation_list, addon) automation_list.setVisible(True) + def get_action_sensor_icon(): + xbmc.log("homepilot_utils: get_action_sensor_icon: ", level=xbmc.LOGDEBUG) return os.path.join(_images, "action_sensor.png") + def _add_scene_item(automation_type, value, automation_list, addon): + xbmc.log("homepilot_utils: _add_scene_item: ", level=xbmc.LOGDEBUG) if value == 1 or value == 2 or value == 0 or value == 4: label = _get_label_scene(automation_type, value, addon) item = xbmcgui.ListItem(label=label) @@ -251,122 +137,45 @@ def _add_scene_item(automation_type, value, automation_list, addon): else: return None + def _get_label_scene(type, val, addon): + xbmc.log("homepilot_utils: _get_label_scene: ", level=xbmc.LOGDEBUG) if val != 1 and val != 2 and val != 4 and val != 0: return "-" value = str(val) - if type == "dusk": - id = int(str(3222) + value) - return addon.getLocalizedString(id) - elif type == "dawn": - id = int(str(3221) + value) - return addon.getLocalizedString(id) - elif type == "time": - id = int(str(3220) + value) - return addon.getLocalizedString(id) - elif type == "dust": - id = int(str(3223) + value) - return addon.getLocalizedString(id) - elif type == "sun": - id = int(str(3224) + value) - return addon.getLocalizedString(id) - elif type == "favored": - id = int(str(3225) + value) - return addon.getLocalizedString(id) - elif type == "wind": - id = int(str(3227) + value) - return addon.getLocalizedString(id) - elif type == "manual": - id = int(str(3226) + value) - return addon.getLocalizedString(id) - elif type == "rain": - id = int(str(3228) + value) - return addon.getLocalizedString(id) - elif type == "trigger": - id = int(str(3229) + value) - return addon.getLocalizedString(id) - elif type == "generic": - id = int(str(3230) + value) - return addon.getLocalizedString(id) - elif type == "temperator": - id = int(str(3231) + value) - return addon.getLocalizedString(id) - elif type == "temperature": - id = int(str(3232) + value) - return addon.getLocalizedString(id) - elif type == "motion": - id = int(str(3233) + value) - return addon.getLocalizedString(id) - elif type == "smoke": - id = int(str(3234) + value) - return addon.getLocalizedString(id) - elif type == "closingContact": - id = int(str(3235) + value) - return addon.getLocalizedString(id) - elif type == "warning": - id = int(str(3236) + value) - return addon.getLocalizedString(id) + labels = {statics.DUSK: int(str(3222) + value), + statics.DAWN: int(str(3221) + value), + statics.TIME: int(str(3220) + value), + statics.DUST: int(str(3223) + value), + statics.SUN: int(str(3224) + value), + statics.FAVORED: int(str(3225) + value), + statics.WIND: int(str(3227) + value), + statics.MANUAL: int(str(3226) + value), + statics.RAIN: int(str(3228) + value), + statics.TRIGGER: int(str(3229) + value), + statics.GENERIC: int(str(3230) + value), + statics.TEMPERATOR: int(str(3231) + value), + statics.TEMPERATUR: int(str(3232) + value), + statics.MOTION: int(str(3233) + value), + statics.SMOKE: int(str(3234) + value), + statics.CLOSINGCONTACT: int(str(3235) + value), + statics.WARNING: int(str(3236) + value)} + if type in labels: + return addon.getLocalizedString(labels[type]) else: + xbmc.log("homepilot_utils: _get_label_scene: Label nicht gefunden!", level=xbmc.LOGERROR) return "-" -def add_device_to_automation_list(automation_list, automations, addon): - dusk = automations.get_dusk() - _add_device_item("dusk", dusk, automation_list, addon) - - dawn = automations.get_dawn() - _add_device_item("dawn", dawn, automation_list, addon) - - time = automations.get_time() - _add_device_item("time", time, automation_list, addon) - - generic = automations.get_generic() - _add_device_item("generic", generic, automation_list, addon) - - wind = automations.get_wind() - _add_device_item("wind", wind, automation_list, addon) - - trigger = automations.get_trigger() - _add_device_item("trigger", trigger, automation_list, addon) - - closingContact = automations.get_closing_contact() - _add_device_item("closingContact", closingContact, automation_list, addon) - - dust = automations.get_dust() - _add_device_item("dust", dust, automation_list, addon) - - smoke = automations.get_smoke() - _add_device_item("smoke", smoke, automation_list, addon) - - sun = automations.get_sun() - _add_device_item("sun", sun, automation_list, addon) - - temperature = automations.get_temperature() - _add_device_item("temperature", temperature, automation_list, addon) - - manual = automations.get_manual() - _add_device_item("manual", manual, automation_list, addon) - - favored = automations.get_favored() - _add_device_item("favored", favored, automation_list, addon) - - smartphone = automations.get_smartphone() - _add_device_item("smartphone", smartphone, automation_list, addon) - - motion = automations.get_motion() - _add_device_item("motion", motion, automation_list, addon) - - temperator = automations.get_temperator() - _add_device_item("temperator", temperator, automation_list, addon) - - warning = automations.get_warning() - _add_device_item("warning", warning, automation_list, addon) - - rain = automations.get_rain() - _add_device_item("rain", rain, automation_list, addon) +def add_device_to_automation_list(automation_list, automations, addon): + xbmc.log("homepilot_utils: add_device_to_automation_list: ", level=xbmc.LOGDEBUG) + for prop in automations.get_props(): + _add_device_item(str(prop), automations.get_props()[prop], automation_list, addon) automation_list.setVisible(True) + def _add_device_item(automation_type, value, automation_list, addon): + xbmc.log("homepilot_utils: _add_device_item: ", level=xbmc.LOGDEBUG) if value == 1 or value == 2 or value == 0 or value == 4: label = _get_label_device(automation_type, value, addon) item = xbmcgui.ListItem(label=label) @@ -376,74 +185,41 @@ def _add_device_item(automation_type, value, automation_list, addon): else: return None + def _get_label_device(type, val, addon): + xbmc.log("homepilot_utils: _get_label_device: ", level=xbmc.LOGDEBUG) if val != 1 and val != 2 and val != 4 and val != 0: return "-" value = str(val) - if type == "dusk": - id = int(str(3205) + value) - return addon.getLocalizedString(id) - elif type == "dawn": - id = int(str(3204) + value) - return addon.getLocalizedString(id) - elif type == "time": - id = int(str(3203) + value) - return addon.getLocalizedString(id) - elif type == "dust": - id = int(str(3206) + value) - return addon.getLocalizedString(id) - elif type == "sun": - id = int(str(3207) + value) - return addon.getLocalizedString(id) - elif type == "favored": - id = int(str(3208) + value) - return addon.getLocalizedString(id) - elif type == "wind": - id = int(str(3210) + value) - return addon.getLocalizedString(id) - elif type == "manual": - id = int(str(3209) + value) - return addon.getLocalizedString(id) - elif type == "rain": - id = int(str(3211) + value) - return addon.getLocalizedString(id) - elif type == "trigger": - id = int(str(3212) + value) - return addon.getLocalizedString(id) - elif type == "generic": - id = int(str(3213) + value) - return addon.getLocalizedString(id) - elif type == "temperator": - id = int(str(3214) + value) - return addon.getLocalizedString(id) - elif type == "temperature": - id = int(str(3215) + value) - return addon.getLocalizedString(id) - elif type == "motion": - id = int(str(3216) + value) - return addon.getLocalizedString(id) - elif type == "smoke": - id = int(str(3217) + value) - return addon.getLocalizedString(id) - elif type == "closingContact": - id = int(str(3218) + value) - return addon.getLocalizedString(id) - elif type == "warning": - id = int(str(3219) + value) - return addon.getLocalizedString(id) + labels = {statics.DUSK: int(str(3205) + value), + statics.DAWN: int(str(3204) + value), + statics.TIME: int(str(3203) + value), + statics.DUST: int(str(3206) + value), + statics.SUN: int(str(3207) + value), + statics.FAVORED: int(str(3208) + value), + statics.WIND: int(str(3210) + value), + statics.MANUAL: int(str(3209) + value), + statics.RAIN: int(str(3211) + value), + statics.TRIGGER: int(str(3212) + value), + statics.GENERIC: int(str(3213) + value), + statics.TEMPERATOR: int(str(3214) + value), + statics.TEMPERATUR: int(str(3215) + value), + statics.MOTION: int(str(3216) + value), + statics.SMOKE: int(str(3217) + value), + statics.CLOSINGCONTACT: int(str(3218) + value), + statics.WARNING: int(str(3219) + value)} + if type in labels: + return addon.getLocalizedString(labels[type]) else: + xbmc.log("homepilot_utils: _get_label_device: Label nicht gefunden!", level=xbmc.LOGERROR) return "-" -#icons_automation["smartphone"] = "global_sensor_12_" - - - def get_title_control(text_or_id, addon): ''' use this method to make sure view titles are everywhere on the same position ''' - #xbmc.log("label: " + str(text_or_id), level=xbmc.LOGNOTICE) + xbmc.log("homepilot_utils: get_title_control: text_or_id:" + repr(text_or_id), level=xbmc.LOGDEBUG) if isinstance(text_or_id, int): label = addon.getLocalizedString(text_or_id) else: @@ -452,4 +228,4 @@ def get_title_control(text_or_id, addon): control = xbmcgui.ControlLabel(330, 65, 600, 75, label, font="Font_Reg22") else: control = xbmcgui.ControlLabel(400, 50, 600, 75, label, font="font16") - return control \ No newline at end of file + return control diff --git a/script.homepilot/resources/lib/homepilot_views.py b/script.homepilot/resources/lib/homepilot_views.py deleted file mode 100644 index 72d6834..0000000 --- a/script.homepilot/resources/lib/homepilot_views.py +++ /dev/null @@ -1,660 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import xbmcgui -import xbmc -import os -import xbmcaddon -__addon__ = xbmcaddon.Addon(id='script.homepilot') -__addon_path__ = __addon__.getAddonInfo('path').decode("utf-8") -_images_device = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media', 'devices') -_images = os.path.join(__addon_path__, 'resources', 'skins', 'Default', 'media') - -from homepilot_utils import ROLLADEN, SCHALTER, DIMMER, THERMOSTATE, TORE, SZENEN_MANUELL, SZENEN_NICHT_MANUELL, \ - SZENEN_ALLE, SZENENTYPEN, SENSOREN, FAVORITEN, FAVORITEN_LOKAL, ALLE, GRUPPEN, SZENEN_DETAILS, SZENEN -import homepilot_utils -import local_favorites - -device_types = {} -device_types[SCHALTER] = 1 -device_types[ROLLADEN] = 2 -device_types[SENSOREN] = 3 -device_types[DIMMER] = 4 -device_types[THERMOSTATE] = 5 -device_types[TORE] = 8 - - -MESSAGE_SETTINGS_DIALOG = __addon__.getLocalizedString(32384) - - -class BaseView: - - def get_communication_error_label(self): - return __addon__.getLocalizedString(32381) - - -class ParametrizedGeraeteView(BaseView): - - def __init__(self, home_pilot_client, device_type, group=None): - self.client = home_pilot_client - self.total = 0 - self.controldict = {} - self.type = device_type - self.list_item_dict = {} - self.hp_error = False - self.errorcontrol = None - self.group = group - - def get_id(self): - return str(self.type) + "_view" - - def get_group(self): - return self.group - - def visualize(self, window, addon, title=None): - if title is None: - self.title_control = homepilot_utils.get_title_control(self.type, addon) - else: - self.title_control = homepilot_utils.get_title_control(title, addon) - window.addControl(self.title_control) - if not hasattr(self, "gerate_group_control"): - self.gerate_group_control = window.getControl(252) - window.setProperty('GeraeteScrollHeight', '480') - homepilot_is_reachable = self.client.ping() - if not homepilot_is_reachable: - self.hp_error = True - errorlabel = self.get_communication_error_label() - self.errorcontrol = xbmcgui.ControlLabel(400, 250, 700, 100, errorlabel) - window.addControl(self.errorcontrol) - else: - self.hp_error = False - self.__visualize_devices(window, addon) - - - def __visualize_devices(self, window, addon): - try: - devices = self.__get_devices() - if len(devices) > 0: - self.geraete_list = window.getControl(5) - if self.type == SENSOREN: - self.geraete_list.controlLeft(self.__get_menu_control(window)) - else: - #set a fake control to prevent xbmc from setting it back to the main menu - control = window.getControl(111) - self.geraete_list.controlLeft(control) - self.geraete_list.reset() - self.__add_listitems(devices) - self.gerate_group_control.setPosition(350,100) - self.gerate_group_control.setVisible(True) - if self.type != FAVORITEN and self.type != FAVORITEN_LOKAL and self.type != SENSOREN: - window.setFocus(self.geraete_list) - else: - pass - errorlabel = "" - #self.hp_error = True - #if self.type == SENSOREN: - # errorlabel = unicode("", "utf-8") - #elif self.type == FAVORITEN_LOKAL or self.type == FAVORITEN: - # errorlabel = unicode("", "utf-8") - #else: - # errorlabel = unicode("", "utf-8") - #self.errorcontrol = xbmcgui.ControlLabel(400, 250, 600, 75, errorlabel) - #window.addControl(self.errorcontrol) - except Exception as inst: - self.hp_error = True - errorlabel = self.get_communication_error_label() - self.errorcontrol = xbmcgui.ControlLabel(400, 250, 600, 75, errorlabel, font="font13") - window.addControl(self.errorcontrol) - xbmc.log(str(inst), level=xbmc.LOGWARNING) - - def __get_menu_control(self, window): - if self.type == SENSOREN: - return window.getControl(97) - else: - return window.getControl(96) - - def __add_listitems(self, devices): - for device in devices: - if self.type == SENSOREN: - item = xbmcgui.ListItem(label=device.get_name()) - else: - item = xbmcgui.ListItem(label=device.get_name(), label2=device.get_display_value()) - icon_name = device.get_icon() - item.setIconImage(os.path.join(_images_device, icon_name)) - item.setProperty("description", device.get_description()) - item.setProperty("did", str(device.get_device_id())) - item.setProperty("sync", str(device.get_sync())) - self.list_item_dict[device.get_device_id()] = item - self.geraete_list.addItem(item) - - def __get_devices(self): - if self.type == ALLE: - devices = self.client.get_devices() - elif self.type == SENSOREN: - devices = self.client.get_meters() - elif self.type == GRUPPEN: - devices = self.client.get_devices_by_group(self.group) - else: - devices = self.client.get_devices_by_device_group(device_types[self.type]) - return devices - - def remove_everything(self, window): - if self.hp_error and self.errorcontrol is not None: - window.removeControls([self.errorcontrol, self.title_control]) - self.errorcontrol = None - else: - controls_to_remove = [self.title_control] - window.removeControls(controls_to_remove) - self.gerate_group_control.setVisible(False) - - def update(self, window, addon, menuControl): - try: - new_devices = self.__get_devices() - if self.hp_error: - self.remove_everything(window) - self.visualize(window, addon) - else: - list_item_ids = self.list_item_dict.keys() - for new_device in new_devices: - new_sync_value = str(new_device.get_sync()) - device_listitem = self.list_item_dict.get(new_device.get_device_id()) - if device_listitem is not None: - list_item_ids.remove(new_device.get_device_id()) - old_sync_value = device_listitem.getProperty("sync") - old_status = device_listitem.getLabel2() - new_status = new_device.get_display_value() - if new_sync_value != old_sync_value or old_status != new_status: - new_icon = new_device.get_icon() - if old_status != new_status: - device_listitem.setLabel2(new_status) - device_listitem.setIconImage(os.path.join(_images_device, new_icon)) - else: - device_listitem.setIconImage(os.path.join(_images_device, new_icon)) - old_label = device_listitem.getLabel() - new_label = new_device.get_name() - if old_label != new_label.encode('utf8'): - device_listitem.setLabel(new_label) - old_label2 = device_listitem.getProperty("description") - new_label2 = new_device.get_description() - if old_label2 != new_label2.encode('utf8'): - device_listitem.setProperty("description", new_label2) - - else: - #add new listitem - self.__add_listitems([new_device]) - #remove items from list when devices are no longer present - #workaround implementation as the ControlList.removeItem didn't work - if len(list_item_ids) > 0: - self.list_item_dict = {} - self.geraete_list.reset() - self.__add_listitems(new_devices) - self.hp_error = False - except Exception, e: - xbmc.log("Problem beim Updaten des views: " + str(self.type) + " " + str(e), level=xbmc.LOGWARNING) - self.remove_everything(window) - self.visualize(window, addon) - self.hp_error = True - - def _get_list_item_position(self, item): - for i in range(0, self.geraete_list.size()): - if self.geraete_list.getListItem(i) == item: - return i - return -1 - - -class FavoritenView(BaseView): - - def __init__(self, home_pilot_client, device_type, menu_control, group=None): - self.client = home_pilot_client - self.total = 0 - self.controldict = {} - self.type = device_type - self.list_item_dict = {} - self.hp_error = False - self.errorcontrol = None - self.errorcontrol2 = None - self.group = group - self.menu_control = menu_control - - def get_id(self): - return str(self.type) + "_view" - - def get_group(self): - return self.group - - def visualize(self, window, addon, title=None): - self.title_control = homepilot_utils.get_title_control(title, addon) - label = addon.getLocalizedString(SZENEN) - self.szenen_control = xbmcgui.ControlLabel(400, 380, 600, 75, label, font="font16") - window.addControls([self.title_control, self.szenen_control]) - homepilot_is_reachable = self.client.ping() -# xbmc.log("reachable " + str(homepilot_is_reachable), level=xbmc.LOGNOTICE) - self.scene_group = window.getControl(262) - self.geraete_group = window.getControl(254) - if not homepilot_is_reachable: - xbmc.log("not reachable " + str(homepilot_is_reachable), level=xbmc.LOGNOTICE) - self.hp_error = True - errorlabel = self.get_communication_error_label() - self.errorcontrol = xbmcgui.ControlLabel(400, 250, 700, 100, errorlabel, font="font12") - window.addControl(self.errorcontrol) - self.errorcontrol2 = xbmcgui.ControlLabel(400, 450, 700, 100, errorlabel, font="font12") - window.addControl(self.errorcontrol2) - else: - self.hp_error = False - self.__visualize_devices(window, addon) - # xbmc.log("visualize_devices ", level=xbmc.LOGNOTICE) - - - def __visualize_devices(self, window, addon): - try: - devices = self.__get_devices() - if len(devices) > 0: - self.geraete_list = window.getControl(255) - self.geraete_list.reset() - self.__add_listitems(devices) - self.geraete_group.setVisible(True) - - scenes = self.__get_scenes() - if len(scenes) > 0: - self.scene_list = window.getControl(264) - self.scene_list.reset() - self.__add_scene_item(scenes) - self.scene_group.setVisible(True) - - if len(devices) > 0: - self.menu_control.controlRight(self.geraete_list) - elif len(scenes) > 0: - self.menu_control.controlRight(self.scene_list) - - except Exception as inst: - self.hp_error = True - errorlabel = self.get_communication_error_label() - self.errorcontrol = xbmcgui.ControlLabel(400, 250, 600, 75, errorlabel) - window.addControl(self.errorcontrol) - xbmc.log("Exception", level=xbmc.LOGWARNING) - xbmc.log(str(inst), level=xbmc.LOGWARNING) - - def __add_listitems(self, devices): - for device in devices: - item = xbmcgui.ListItem(label=device.get_name(), label2=device.get_display_value()) - icon_name = device.get_icon() - item.setIconImage(os.path.join(_images_device, icon_name)) - item.setProperty("description", device.get_description()) - item.setProperty("did", str(device.get_device_id())) - item.setProperty("sync", str(device.get_sync())) - self.list_item_dict[device.get_device_id()] = item - self.geraete_list.addItem(item) - - def __add_scene_item(self, scenes): - for scene in scenes: - scene_item = xbmcgui.ListItem(label = scene.get_name()) - scene_item.setIconImage(szene_img) - scene_item.setProperty("sid", str(scene.get_id())) - scene_item.setProperty("description", scene.get_description()) - self.scene_list.addItem(scene_item) - - def __get_devices(self): - if self.type == FAVORITEN: - devices = self.client.get_favorite_devices() - else: - devices = self.__get_local_favorit_devices() - return devices - - def __get_scenes(self): - if self.type == FAVORITEN: - scenes = self.client.get_favorite_scenes() - else: - scenes = self.__get_local_favorit_scenes() - return scenes - - def __get_local_favorit_devices(self): - device_ids = local_favorites.get_devices_as_set() - all_devices = self.client.get_devices() - favorite_devices = [] - for device in all_devices: - if device.get_device_id() in device_ids: - favorite_devices.append(device) - return favorite_devices - - def __get_local_favorit_scenes(self): - scene_ids = local_favorites.get_scenes_as_set() - all_scenes = self.client.get_scenes() - favorite_scenes = [] - for scene in all_scenes: - if scene.get_id() in scene_ids: - favorite_scenes.append(scene) - return favorite_scenes - - def remove_everything(self, window): - #FIXME this section is still causing trouble -> clean up displaying of error messages - if self.hp_error and self.errorcontrol is not None and self.errorcontrol2 is not None: - window.removeControls([self.errorcontrol, self.errorcontrol2, self.title_control, self.szenen_control]) - self.errorcontrol = None - self.errorcontrol2 = None - elif self.hp_error and self.errorcontrol is not None: - window.removeControls([self.errorcontrol, self.title_control, self.szenen_control]) - self.errorcontrol = None - elif self.hp_error: - pass - else: - controls_to_remove = [self.title_control, self.szenen_control] - window.removeControls(controls_to_remove) - - self.scene_group.setVisible(False) - self.geraete_group.setVisible(False) - - def update(self, window, addon, menuControl): - try: - new_devices = self.__get_devices() - if self.hp_error: - self.remove_everything(window) - self.visualize(window, addon) - else: - list_item_ids = self.list_item_dict.keys() - for new_device in new_devices: - new_sync_value = str(new_device.get_sync()) - device_listitem = self.list_item_dict.get(new_device.get_device_id()) - if device_listitem is not None: - list_item_ids.remove(new_device.get_device_id()) - old_sync_value = device_listitem.getProperty("sync") - old_status = device_listitem.getLabel2() - new_status = new_device.get_display_value() - if new_sync_value != old_sync_value or old_status != new_status: - new_icon = new_device.get_icon() - if old_status != new_status: - device_listitem.setLabel2(new_status) - device_listitem.setIconImage(os.path.join(_images_device, new_icon)) - else: - device_listitem.setIconImage(os.path.join(_images_device, new_icon)) - old_label = device_listitem.getLabel() - new_label = new_device.get_name() - if old_label != new_label.encode('utf8'): - device_listitem.setLabel(new_label) - old_label2 = device_listitem.getProperty("description") - new_label2 = new_device.get_description() - if old_label2 != new_label2.encode('utf8'): - device_listitem.setProperty("description", new_label2) - - else: - #add new listitem - self.__add_listitems([new_device]) - #remove items from list when devices are no longer present - #workaround implementation as the ControlList.removeItem didn't work - if len(list_item_ids) > 0: - self.list_item_dict = {} - self.geraete_list.reset() - self.__add_listitems(new_devices) - self.hp_error = False - except Exception, e: - if not self.hp_error: - xbmc.log("Problem beim Updaten des views: " + str(self.type) + " " + str(e), level=xbmc.LOGWARNING) - self.remove_everything(window) - self.visualize(window, addon) - self.hp_error = True - - def _get_list_item_position(self, item): - for i in range(0, self.geraete_list.size()): - if self.geraete_list.getListItem(i) == item: - return i - return -1 - - - -schalter_img = os.path.join(_images_device, 'steckdose_72_0.png') -rollo_img = os.path.join(_images_device, 'rollladen2_72_50.png') -dimmer_img = os.path.join(_images_device, 'birne1_72_100.png') -thermostat_img = os.path.join(_images_device, 'thermostat_72_100.png') -tore_img = os.path.join(_images_device, 'garage_72_50.png') -logo_img = os.path.join(_images, 'logo-homepilot-klein.png') - - -class GeraetetypView(BaseView): - - def __init__(self, home_pilot_client): - self.client = home_pilot_client - - def get_id(self): - return "geraetetyp_view" - - def remove_everything(self, window): - window.removeControls([self.geraetelabel_control, self.gruppen_control]) - self.geraetetypen_list.setVisible(False) - self.gruppen_group_control.setVisible(False) - if self.errorcontrol is not None: - window.removeControl(self.errorcontrol) - - def visualize(self, window, addon): - xbmc.log("visualize geraetetypview: ", level=xbmc.LOGNOTICE) - self.geraetelabel_control = homepilot_utils.get_title_control(32009, addon) - - self.geraetetypen_list = window.getControl(257) - self.geraetetypen_list.reset() - - device_groups = self.__get_device_groups() - - if 2 in device_groups: - self.rolladen_item = xbmcgui.ListItem(label=addon.getLocalizedString(ROLLADEN)) - self.rolladen_item.setIconImage(rollo_img) - self.rolladen_item.setProperty("type", str(ROLLADEN)) - self.geraetetypen_list.addItem(self.rolladen_item) - - if 1 in device_groups: - self.schalter_item = xbmcgui.ListItem(label=addon.getLocalizedString(SCHALTER)) - self.schalter_item.setIconImage(schalter_img) - self.schalter_item.setProperty("type", str(SCHALTER)) - self.geraetetypen_list.addItem(self.schalter_item) - - if 4 in device_groups: - self.dimmer_item = xbmcgui.ListItem(label=addon.getLocalizedString(DIMMER)) - self.dimmer_item.setIconImage(dimmer_img) - self.dimmer_item.setProperty("type", str(DIMMER)) - self.geraetetypen_list.addItem(self.dimmer_item) - - if 5 in device_groups: - self.thermostat_item = xbmcgui.ListItem(label=addon.getLocalizedString(THERMOSTATE)) - self.thermostat_item.setIconImage(thermostat_img) - self.thermostat_item.setProperty("type", str(THERMOSTATE)) - self.geraetetypen_list.addItem(self.thermostat_item) - - if 8 in device_groups: - self.tore_item = xbmcgui.ListItem(label=addon.getLocalizedString(TORE)) - self.tore_item.setIconImage(tore_img) - self.tore_item.setProperty("type", str(TORE)) - self.geraetetypen_list.addItem(self.tore_item) - - self.alle_item = xbmcgui.ListItem(label=addon.getLocalizedString(ALLE)) - self.alle_item.setIconImage(logo_img) - self.alle_item.setProperty("type", str(ALLE)) - self.geraetetypen_list.addItem(self.alle_item) - - self.geraetetypen_list.setVisible(True) - - label = addon.getLocalizedString(32015) - self.gruppen_control = xbmcgui.ControlLabel(400, 380, 600, 75, label, font="font16") - window.addControls([self.geraetelabel_control, self.gruppen_control]) - - gruppen_list = window.getControl(4) - gruppen_list.reset() - self.gruppen_group_control = window.getControl(251) - try: - groups = self.client.get_groups() - if len(groups) > 0: - for group in groups: - group_item = xbmcgui.ListItem(label=group.get_name()) - group_item.setProperty("gid", str(group.get_group_id())) - gruppen_list.addItem (group_item) - - self.gruppen_group_control.setPosition(350,420) - self.gruppen_group_control.setVisible(True) - self.errorcontrol = None - else: - errorlabel = addon.getLocalizedString(32380) - self.errorcontrol = xbmcgui.ControlLabel(450, 450, 600, 75, errorlabel) - window.addControl(self.errorcontrol) - except Exception, e: - xbmc.log(str(e), level=xbmc.LOGWARNING) - errorlabel = self.get_communication_error_label() - self.errorcontrol = xbmcgui.ControlLabel(450, 450, 600, 75, errorlabel) - window.addControl(self.errorcontrol) - - def __get_device_groups(self): - devices = self.client.get_devices() - device_groups = map(lambda x: x.get_devicegroup(), devices) - return set(device_groups) - - def handle_click(self, position): - if position.getProperty("type") == str(ALLE): - return ALLE - elif position.getProperty("type") == str(ROLLADEN): - return ROLLADEN - elif position.getProperty("type") == str(SCHALTER): - return SCHALTER - elif position.getProperty("type") == str(DIMMER): - return DIMMER - elif position.getProperty("type") == str(THERMOSTATE): - return THERMOSTATE - elif position.getProperty("type") == str(TORE): - return TORE - pass - - -szene_img = os.path.join(_images, 'szene_32.png') -szene_img_deact = os.path.join(_images, 'szene_32_deactivated.png') -scene_manual = os.path.join(_images, 'scene_manual2.png') -scene_non_manual = os.path.join(_images, 'scene_no_manual2.png') - - -class SzenentypView(BaseView): - - def __init__(self): - pass - - def get_id(self): - return str(SZENENTYPEN) + "_view" - - def remove_everything(self, window): - self.scenes_list.setVisible(False) - window.removeControls([self.title_control]) - - - def visualize(self, window, addon): - self.title_control = homepilot_utils.get_title_control(32016, addon) - window.addControl(self.title_control) - self.scenes_list = window.getControl(257) - self.scenes_list.reset() - - self.manuell_item = xbmcgui.ListItem(addon.getLocalizedString(32017)) - self.manuell_item.setIconImage(scene_manual) - self.manuell_item.setProperty("pid", "0") - self.scenes_list.addItem(self.manuell_item) - - self.nicht_manuell_item = xbmcgui.ListItem(addon.getLocalizedString(32018)) - self.nicht_manuell_item.setIconImage(scene_non_manual) - self.nicht_manuell_item.setProperty("pid", "1") - self.scenes_list.addItem(self.nicht_manuell_item) - - self.alle_item = xbmcgui.ListItem(addon.getLocalizedString(32020)) - self.alle_item.setProperty("pid", "2") - self.scenes_list.addItem(self.alle_item) - - self.scenes_list.setVisible(True) - - return [self.title_control] - - def handle_click (self, item): - position = item.getProperty("pid") - if position == "0": - return SZENEN_MANUELL - elif position == "1": - return SZENEN_NICHT_MANUELL - elif position == "2": - return SZENEN_ALLE - return "" - - def focus_list_item(self, view_id, window): - window.setFocusId(257) - if view_id == str(SZENEN_MANUELL) + "_view": - self.scenes_list.selectItem(0) - elif view_id == str(SZENEN_NICHT_MANUELL) + "_view": - self.scenes_list.selectItem(1) - elif view_id == str(SZENEN_ALLE) + "_view": - self.scenes_list.selectItem(2) - - -class SzenenListView(BaseView): - - def __init__(self, client, type): - self.type = type - self.client = client - - def get_id(self): - return str(self.type) + "_view" - - def remove_everything(self, window): - window.removeControls([self.title_control]) - scenes_group = window.getControl(260) - scenes_group.setVisible(False) - if self.errorcontrol is not None: - window.removeControl(self.errorcontrol) - - def visualize(self, window, addon): - self.title_control = homepilot_utils.get_title_control(self.type, addon) - window.addControl(self.title_control) - scenes_list = window.getControl(258) - scenes_list.reset() - - scenes = self.__get_scenes() - if scenes is not None and len(scenes) > 0: - scenes_group = window.getControl(260) - scenes_group.setPosition(350, 100) - scenes_group.setVisible(True) - for scene in scenes: - scene_item = xbmcgui.ListItem(label = scene.get_name()) - if scene.is_active(): - scene_item.setIconImage(szene_img) - else: - scene_item.setIconImage(szene_img_deact) - scene_item.setProperty("sid", str(scene.get_id())) - scene_item.setProperty("description", scene.get_description()) - scenes_list.addItem(scene_item) - self.errorcontrol = None - window.setFocusId(258) - else: - errorlabel = addon.getLocalizedString(32380) - self.errorcontrol = xbmcgui.ControlLabel(450, 150, 600, 75, errorlabel) - window.addControl(self.errorcontrol) - #window.setFocusId(94) - scenes_list.setVisible(True) - return [self.title_control] - - def handle_click (self, control): - pass - - def __get_scenes(self): - if self.type == SZENEN_ALLE: - return self.client.get_scenes() - elif self.type == SZENEN_MANUELL: - return self.client.get_manual_scenes() - elif self.type == SZENEN_NICHT_MANUELL: - return self.client.get_non_manual_scenes() - - -class EmptyView(BaseView): - - def __init__(self): - pass - - def get_id(self): - return "empty_view" - - def remove_everything(self, window): - window.removeControls([self.einstellungen_control, self.label]) - - def visualize(self, window, addon): - self.einstellungen_control = homepilot_utils.get_title_control(32008, addon) - self.label = xbmcgui.ControlLabel(460,250, 590, 40, MESSAGE_SETTINGS_DIALOG, alignment=0x00000002) - window.addControls([self.einstellungen_control, self.label]) - return [self.einstellungen_control, self.label] - - def handle_click(self, control): - pass diff --git a/script.homepilot/resources/lib/local_favorites.py b/script.homepilot/resources/lib/local_favorites.py index 462b316..13949ea 100644 --- a/script.homepilot/resources/lib/local_favorites.py +++ b/script.homepilot/resources/lib/local_favorites.py @@ -1,58 +1,101 @@ - -import xbmcvfs import xbmc import json import os.path -file_location = xbmc.translatePath('special://userdata') + 'addon_data/script.homepilot/local_favorites.json' +file_location = str(xbmc.translatePath("special://userdata")) + "addon_data/script.homepilot/local_favorites.json" +DEVICES = "devices" +SCENES = "scenes" -def get_file_content(file_path): +def open_file_to_read(): + xbmc.log("local_favorites: open_file_to_read. ", level=xbmc.LOGDEBUG) try: if os.path.isfile(file_location): with open(file_location, 'r') as f: content = f.read() - data = json.loads(content) + if content == '': + data = None + else: + data = json.loads(content) + xbmc.log("local_favorites: open_file_to_write: Content: " + repr(content), level=xbmc.LOGDEBUG) return data except Exception, e: - xbmc.log("Problem beim Lesen der Datei: " + str(file_location) + " " + str(e), level=xbmc.LOGWARNING) + xbmc.log("local_favorites: open_file_to_read: Problem beim Lesen der Datei: " + str(file_location) + " " + str( + e.message), level=xbmc.LOGWARNING) + return None + + +def open_file_to_write(type, id): + xbmc.log("local_favorites: open_file_to_write: ", level=xbmc.LOGDEBUG) + try: + if os.path.isfile(file_location): + with open(file_location, 'r') as f: + content = f.read() + if content == '': + f.close() + with open(file_location, 'w') as f: + if type == DEVICES: + data = {SCENES: [], DEVICES: [id]} + else: + data = {SCENES: [id], DEVICES: []} + json_text = json.dumps(data) + f.write(json_text) + xbmc.log("local_favorites: open_file_to_write: TYPE: " + str(type) + + "\nID: " + repr(id) + + "\nJSON: " + repr(json_text), level=xbmc.LOGDEBUG) + else: + data = json.loads(content) + json_text = __add_id(data, id, type) # "devices" + with open(file_location, 'w') as f: + f.write(json_text) + xbmc.log("local_favorites: open_file_to_write: TYPE: " + str(type) + + "\nID: " + repr(id) + + "\nJSON: " + repr(json_text), level=xbmc.LOGDEBUG) + else: + with open(file_location, 'w') as f: + if id == DEVICES: + data = {SCENES: [], DEVICES: [id]} + else: + data = {SCENES: [id], DEVICES: []} + json_text = json.dumps(data) + f.write(json_text) + xbmc.log("local_favorites: open_file_to_write: TYPE: " + str(type) + + "\nID: " + repr(id) + + "\nJSON: " + repr(json_text), level=xbmc.LOGDEBUG) + except Exception, e: + xbmc.log("local_favorites: open_file_to_write: Problem beim Verarbeiten der Datei: " + str(file_location) + " " + str(e.message), + level=xbmc.LOGWARNING) - return None + +def get_file_content(file_path): + xbmc.log("local_favorites: get_file_content. ", level=xbmc.LOGDEBUG) + return open_file_to_read() def get_devices_as_set(): + xbmc.log("local_favorites: get_devices_as_set: ", level=xbmc.LOGDEBUG) data = get_file_content(file_location) if data is not None: - device_ids = data["devices"] - return set(device_ids) + device_ids = data[DEVICES] + if not device_ids: + xbmc.log("local_favorites: get_devices_as_set: Keine lokalen Geraete Favoriten gefunden. No devices.", + level=xbmc.LOGDEBUG) + return None + else: + xbmc.log("local_favorites: get_devices_as_set: "+repr(len(device_ids))+" lokale Geraete Favoriten gefunden.", level=xbmc.LOGDEBUG) + return set(device_ids) else: - return set() + xbmc.log("local_favorites: get_devices_as_set: Keine lokalen Geraete Favoriten gefunden. No data. ", level=xbmc.LOGDEBUG) + return None def add_device(device_id): - try: - if os.path.isfile(file_location): - content = "{}" - with open(file_location, 'r') as file: - content = file.read() - data = json.loads(content) - json_text = __add_id(data, device_id, "devices") - with open(file_location, 'w') as file: - file.write(json_text) - else: - with open(file_location, 'w') as f: - data = {} - data["scenes"] = [] - data["devices"] = [device_id] - json_text = json.dumps(data) - f.write(json_text) - return True - except Exception, e: - xbmc.log("Problem beim Verarbeiten der Datei: " + str(file_location) + " " + str(e), level=xbmc.LOGWARNING) - return False + xbmc.log("local_favorites: add_device: ", level=xbmc.LOGDEBUG) + open_file_to_write(DEVICES, device_id) def __add_id(data, id, type): + xbmc.log("local_favorites: __add_id: ", level=xbmc.LOGDEBUG) device_ids = set(data[type]) device_ids.add(id) data[type] = list(device_ids) @@ -60,20 +103,21 @@ def __add_id(data, id, type): def remove_device(device_id): + xbmc.log("local_favorites: remove_device: ", level=xbmc.LOGDEBUG) try: if os.path.isfile(file_location): - content = "{}" - with open(file_location, 'r') as file: - content = file.read() - with open(file_location, 'w') as file: + with open(file_location, 'r') as rm_file: + content = rm_file.read() + with open(file_location, 'w') as rm_file: data = json.loads(content) - json_text = __remove_id(data, device_id, "devices") - file.write(json_text) + json_text = __remove_id(data, device_id, DEVICES) + rm_file.write(json_text) except Exception, e: - xbmc.log("Problem beim Verarbeiten der Datei: " + str(file_location) + " " + str(e), level=xbmc.LOGWARNING) + xbmc.log("remove_device: Problem beim Verarbeiten der Datei: " + str(file_location) + " " + str(e), level=xbmc.LOGWARNING) def __remove_id(data, id, type): + xbmc.log("local_favorites: __remove_id: ", level=xbmc.LOGDEBUG) device_ids = set(data[type]) device_ids.remove(id) data[type] = list(device_ids) @@ -81,48 +125,37 @@ def __remove_id(data, id, type): def get_scenes_as_set(): + xbmc.log("local_favorites: get_scenes_as_set: ", level=xbmc.LOGDEBUG) data = get_file_content(file_location) if data is not None: - scene_ids = data["scenes"] - return set(scene_ids) + scene_ids = data[SCENES] + if not scene_ids: + xbmc.log("local_favorites: get_scenes_as_set: Keine lokalen Szene Favoriten gefunden. Keine Szenen. ", + level=xbmc.LOGDEBUG) + return None + else: + xbmc.log("local_favorites: get_scenes_as_set: "+repr(len(scene_ids))+" lokale Szene Favoriten gefunden.", level=xbmc.LOGDEBUG) + return set(scene_ids) else: - return set() + xbmc.log("local_favorites: get_scenes_as_set: Keine Lokalen Szene Favoriten gefunden. Keine Daten. ", level=xbmc.LOGDEBUG) + return None def add_scene(scene_id): - try: - if os.path.isfile(file_location): - content = "{}" - with open(file_location, 'r') as file: - content = file.read() - with open(file_location, 'w') as file: - data = json.loads(content) - json_text = __add_id(data, scene_id, "scenes") - file.write(json_text) - else: - f =xbmcvfs.File(file_location, 'w') - data = {} - data["scenes"] = [scene_id] - data["devices"] = [] - json_text = json.dumps(data) - f.write(json_text) - f.close() - return True - except Exception, e: - xbmc.log("Problem beim Verarbeiten der Datei: " + str(file_location) + " " + str(e), level=xbmc.LOGWARNING) - - return False + xbmc.log("local_favorites: add_scene: scene_id: " + repr(scene_id), level=xbmc.LOGDEBUG) + open_file_to_write(SCENES, scene_id) def remove_scene(scene_id): + xbmc.log("local_favorites: remove_scene: scene_id: " + repr(scene_id), level=xbmc.LOGDEBUG) try: if os.path.isfile(file_location): - content = "{}" - with open(file_location, 'r') as file: - content = file.read() - with open(file_location, 'w') as file: + with open(file_location, 'r') as remove_scene: + content = remove_scene.read() + with open(file_location, 'w') as remove_scene: data = json.loads(content) - json_text = __remove_id(data, scene_id, "scenes") - file.write(json_text) + json_text = __remove_id(data, scene_id, SCENES) + remove_scene.write(json_text) except Exception, e: - xbmc.log("Problem beim Verarbeiten der Datei: " + str(file_location) + " " + str(e), level=xbmc.LOGWARNING) + xbmc.log("remove_scene: Problem beim Verarbeiten der Datei: " + str(file_location) + " " + str(e), level=xbmc.LOGWARNING) + diff --git a/script.homepilot/resources/lib/models.py b/script.homepilot/resources/lib/models.py deleted file mode 100644 index b5144dc..0000000 --- a/script.homepilot/resources/lib/models.py +++ /dev/null @@ -1,302 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import homepilot_utils -import xbmc - - -class HomePilotBaseObject: - """ - class which represents a single device - """ - - def __init__(self, device): - """ - constructor of the class - - Arguments: - - device -- dictionary with the device attributes - """ - self.device = device - self._name = device["name"] - self._descriprion = device["description"] - self._did = device["did"] - self._position = device["position"] - self._deviceGroup = device["deviceGroup"] - self._status = device["position"] - self._sync = device["sync"] - self._icon_set = device["iconsetKey"] - self._icon_set_inverted = device.get("iconSetInverted") - - def get_name(self): - """ - returns the device name - """ - return self._name - - def get_device_id(self): - """ - return the device id - """ - return self._did - - def get_position(self): - """ - gets the current position of the device on a scale from 0 to 100 - """ - return self._position - - def get_devicegroup(self): - """ - returns the devicegroup the device belongs to - - Schalter:1, Sensoren:3, Rollos:2, Thermostate:5, Dimmer:4, Tore:8 - """ - return self._deviceGroup - - def get_status(self): - """ - returns the current status - """ - return self._status - - def get_description(self): - return self._descriprion - - def get_sync(self): - return self._sync - - def get_iconset_inverted(self): - return homepilot_utils.get_iconset_inverted(self._icon_set_inverted) - - def get_icon(self): - - return homepilot_utils.get_icon(self._icon_set, self._icon_set_inverted, self._position, self._deviceGroup) - - def get_display_value(self): - position = self.get_position() - group = self.get_devicegroup() - return homepilot_utils.get_display_value(position, group) - - -class Automation(): - def __init__(self, properties): - self.properties = properties - - def get_dawn(self): - return self.properties["dawn"] - - def get_dusk(self): - return self.properties["dusk"] - - def get_time(self): - return self.properties["time"] - - def get_wind(self): - return self.properties["wind"] - - def get_temperature(self): - return self.properties["temperature"] - - def get_generic(self): - return self.properties["generic"] - - def get_trigger(self): - return self.properties["trigger"] - - def get_closing_contact(self): - return self.properties["closingContact"] - - def get_smoke(self): - return self.properties["smoke"] - - def get_sun(self): - return self.properties["sun"] - - def get_manual(self): - return self.properties["manual"] - - def get_dust(self): - return self.properties["dust"] - - def get_favored(self): - return self.properties["favored"] - - def get_smartphone(self): - return self.properties["smartphone"] - - def get_motion(self): - return self.properties["motion"] - - def get_temperator(self): - return self.properties["temperator"] - - def get_warning(self): - return self.properties["warning"] - - def get_rain(self): - return self.properties["rain"] - - -class Device(HomePilotBaseObject): - - def __init__(self, device): - HomePilotBaseObject.__init__(self, device) - self._available = device["avail"] - self._hasErrors = device["hasErrors"] != 0 - self._groups = device["groups"] - self._favoredId = device["favoredId"] - self._automated = device["automated"] != 0 - self._properties = device["properties"] - - def has_errors(self): - """ - returns if the device has errors - """ - return self._hasErrors - - def is_available(self): - """ - returns if the device is available - """ - return self._available - - def get_favoredId (self): - return self._favoredId - - def get_icon(self): - icon = HomePilotBaseObject.get_icon(self) - if self.is_available() == False or self.has_errors(): - icon = "warnung_72.png" - return icon - - def is_automated(self): - return self._automated - - def get_automationen(self): - return Automation(self._properties) - - def is_favored(self): - return self._favoredId != -1 - -class Meter(HomePilotBaseObject): - - def __init__(self, device, data): - """ - constructor of the class - - Arguments: - - meter -- dictionary with the sensor attributes - """ - HomePilotBaseObject.__init__(self, device) - self._data = data - - def get_data (self): - return self._data - - -class Group: - - def __init__(self, group): - self.group = group - self._name = group["name"] - self._description = group["description"] - self._gid = group["gid"] - - def get_group_id(self): - return self._gid - - def get_name(self): - return self._name - - def get_description(self): - return self._description - - -class Action: - - def __init__(self, action): - self._did = action["did"] - self._type = action["type"] - self._name = action["name"] - self._description = action["description"] - self._iconset = action ["iconset"] - self._iconsetInverted = action["iconsetInverted"] - self._cmdId = action["cmdId"] - if "param" in action: - self._param = action["param"] - else: - self._param = None - - def get_did(self): - return self._did - - def get_name(self): - return self._name - - def get_description(self): - return self._description - - def get_icon(self): - if self._cmdId == 666:#Sensor - return homepilot_utils.get_action_sensor_icon() - elif self._param is not None: - return homepilot_utils.get_icon(self._iconset, self._iconsetInverted, self._param, type) - elif self._cmdId == 10 or self._cmdId == 2: - return homepilot_utils.get_icon(self._iconset, self._iconsetInverted, 100, type) - else: - return homepilot_utils.get_icon(self._iconset, self._iconsetInverted, 0, type) - - def get_cmdId(self): - return self._cmdId - - def get_device_group(self): - return self._type - - def get_param(self): - return self._param - - -class Scene: - - def __init__(self, scene): - self._sid = scene["sid"] - self._name = scene["name"] - self._description = scene["description"] - self._is_executable = scene["isExecutable"] - self._sync = scene["sync"] - self._groups = scene["groups"] - if 'actions' in scene: - self._actions = scene["actions"] - self._properties = scene["properties"] - self._is_active = scene["isActive"] - self._favored = scene["favoredId"] - - def get_id(self): - return self._sid - - def get_name(self): - return self._name - - def get_actions(self): - return map(lambda x: Action(x), self._actions) - - def get_automationen(self): - return Automation(self._properties) - - def is_executable(self): - return self._is_executable == 1 - - def is_active(self): - return self._is_active == 1 - - def is_favored(self): - return self._favored > 0 - - def get_sync(self): - return self._sync - - def get_description(self): - return self._description \ No newline at end of file diff --git a/script.homepilot/resources/lib/settings.py b/script.homepilot/resources/lib/settings.py index e55a873..834a05a 100644 --- a/script.homepilot/resources/lib/settings.py +++ b/script.homepilot/resources/lib/settings.py @@ -1,22 +1,27 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from statics import * +import xbmc -class SettingsDialogManager (object): - def get_ip_address (self, addon): +class SettingsDialogManager(object): + def get_ip_address(self, addon): + xbmc.log("SettingsDialogManager: get_ip_address: ", level=xbmc.LOGDEBUG) ip_address = addon.getSetting("homepilot_ip") ip_set = addon.getSetting("homepilot_ip_set") - if not ip_address or not ip_set: - #addon.openSettings() + if not ip_address or not ip_set: + # addon.openSettings() ip_address = addon.getSetting("homepilot_ip") addon.setSetting("homepilot_ip_set", "true") return ip_address def update_ip_address(self, addon): + xbmc.log("SettingsDialogManager: update_ip_address: ", level=xbmc.LOGDEBUG) addon.openSettings() addon.setSetting("homepilot_ip_set", "true") def use_local_favorites(self, addon): use_local_favorites = addon.getSetting("local_favorites") + xbmc.log("SettingsDialogManager: use_local_favorites: " + repr(use_local_favorites), level=xbmc.LOGDEBUG) return use_local_favorites diff --git a/script.homepilot/resources/lib/statics.py b/script.homepilot/resources/lib/statics.py new file mode 100644 index 0000000..fcfdd14 --- /dev/null +++ b/script.homepilot/resources/lib/statics.py @@ -0,0 +1,497 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +#IDs: +empty_view_id = "empty_view" +geraetetyp_view_id = "geraetetyp_view" + +ADDON = "addon" +PARENT = "parent" +CLIENT = "client" +DID = "did" +GID = "gid" +DEVICE = "device" +LOCAL_FAVS = "local_favs" +SCENE_ID = "scene_id" +PREVIOUS_LIST_POSITION = "previous_list_position" +POSITION = "position" +ICONSETKEY = "iconsetKey" +ICON_SET_INVERTED = "iconSetInverted" +DEVICE_GROUP = "deviceGroup" +USE_LOCAL_FAVORITES = "use_local_favorites" +SLIDER = "slider" +STATUS = "status" +TITLE = "title" +ICON = "icon" +UP = "up" +DOWN = "down" +AUTO = "auto" +GROUP = "group" +RADIO = "radio" +ON = "on" +OFF = "off" +SID = "sid" +NAME = "name" +DESCRIPTION = "description" +IS_EXECUTABLE = "isExecutable" +SYNC = "sync" +GROUPS = "groups" +ACTIONS = "actions" +PROPERTIES = "properties" +IS_ACTIVE = "isActive" +FAVORED_ID = "favoredId" +AVAIL = "avail" +HAS_ERRORS = "hasErrors" +AUTOMATED = "automated" +TYPE = "type" +ICONSET_INVERTED = "iconsetInverted" +CMID = "cmdId" +PARAM = "param" +ICONSET = "iconset" +PERCENT_TYPE = "PERCENT" +DEGREE_TYPE = "DEGREE" +NOTHING = "NOTHING" +UPDATE = "UPDATE" +UPDATE_SENT = "UPDATE_SENT" + +ACTION_ANALOG_FORWARD = 113 +ACTION_ANALOG_MOVE = 49 +ACTION_ANALOG_MOVE_X = 601 +ACTION_ANALOG_MOVE_Y = 602 +ACTION_ANALOG_REWIND = 114 +ACTION_ANALOG_SEEK_BACK = 125 +ACTION_ANALOG_SEEK_FORWARD = 124 +ACTION_ASPECT_RATIO = 19 +ACTION_AUDIO_DELAY = 161 +ACTION_AUDIO_DELAY_MIN = 54 +ACTION_AUDIO_DELAY_PLUS = 55 +ACTION_AUDIO_NEXT_LANGUAGE = 56 +ACTION_BACKSPACE = 110 +ACTION_BIG_STEP_BACK = 23 +ACTION_BIG_STEP_FORWARD = 22 +ACTION_BUILT_IN_FUNCTION = 122 +ACTION_CALIBRATE_RESET = 48 +ACTION_CALIBRATE_SWAP_ARROWS = 47 +ACTION_CHANGE_RESOLUTION = 57 +ACTION_CHANNEL_DOWN = 185 +ACTION_CHANNEL_SWITCH = 183 +ACTION_CHANNEL_UP = 184 +ACTION_CHAPTER_OR_BIG_STEP_BACK = 98 +ACTION_CHAPTER_OR_BIG_STEP_FORWARD = 97 +ACTION_CONTEXT_MENU = 117 +ACTION_COPY_ITEM = 81 +ACTION_CREATE_BOOKMARK = 96 +ACTION_CREATE_EPISODE_BOOKMARK = 95 +ACTION_CURSOR_LEFT = 120 +ACTION_CURSOR_RIGHT = 121 +ACTION_CYCLE_SUBTITLE = 99 +ACTION_DECREASE_PAR = 220 +ACTION_DECREASE_RATING = 137 +ACTION_DELETE_ITEM = 80 +ACTION_ENTER = 135 +ACTION_ERROR = 998 +ACTION_FILTER = 233 +ACTION_FILTER_CLEAR = 150 +ACTION_FILTER_SMS2 = 151 +ACTION_FILTER_SMS3 = 152 +ACTION_FILTER_SMS4 = 153 +ACTION_FILTER_SMS5 = 154 +ACTION_FILTER_SMS6 = 155 +ACTION_FILTER_SMS7 = 156 +ACTION_FILTER_SMS8 = 157 +ACTION_FILTER_SMS9 = 158 +ACTION_FIRST_PAGE = 159 +ACTION_FORWARD = 16 +ACTION_GESTURE_BEGIN = 501 +ACTION_GESTURE_END = 599 +ACTION_GESTURE_NOTIFY = 500 +ACTION_GESTURE_PAN = 504 +ACTION_GESTURE_ROTATE = 503 +ACTION_GESTURE_SWIPE_DOWN = 541 +ACTION_GESTURE_SWIPE_DOWN_TEN = 550 +ACTION_GESTURE_SWIPE_LEFT = 511 +ACTION_GESTURE_SWIPE_LEFT_TEN = 520 +ACTION_GESTURE_SWIPE_RIGHT = 521 +ACTION_GESTURE_SWIPE_RIGHT_TEN = 530 +ACTION_GESTURE_SWIPE_UP = 531 +ACTION_GESTURE_SWIPE_UP_TEN = 540 +ACTION_GESTURE_ZOOM = 502 +ACTION_GUIPROFILE_BEGIN = 204 +ACTION_HIGHLIGHT_ITEM = 8 +ACTION_INCREASE_PAR = 219 +ACTION_INCREASE_RATING = 136 +ACTION_INPUT_TEXT = 244 +ACTION_JUMP_SMS2 = 142 +ACTION_JUMP_SMS3 = 143 +ACTION_JUMP_SMS4 = 144 +ACTION_JUMP_SMS5 = 145 +ACTION_JUMP_SMS6 = 146 +ACTION_JUMP_SMS7 = 147 +ACTION_JUMP_SMS8 = 148 +ACTION_JUMP_SMS9 = 149 +ACTION_LAST_PAGE = 160 +ACTION_MOUSE_DOUBLE_CLICK = 103 +ACTION_MOUSE_DRAG = 106 +ACTION_MOUSE_END = 109 +ACTION_MOUSE_LEFT_CLICK = 100 +ACTION_MOUSE_LONG_CLICK = 108 +ACTION_MOUSE_MIDDLE_CLICK = 102 +ACTION_MOUSE_MOVE = 107 +ACTION_MOUSE_RIGHT_CLICK = 101 +ACTION_MOUSE_START = 100 +ACTION_MOUSE_WHEEL_DOWN = 105 +ACTION_MOUSE_WHEEL_UP = 104 +ACTION_MOVE_DOWN = 4 +ACTION_MOVE_ITEM = 82 +ACTION_MOVE_ITEM_DOWN = 116 +ACTION_MOVE_ITEM_UP = 115 +ACTION_MOVE_LEFT = 1 +ACTION_MOVE_RIGHT = 2 +ACTION_MOVE_UP = 3 +ACTION_MUTE = 91 +ACTION_NAV_BACK = 92 +ACTION_NEXT_CHANNELGROUP = 186 +ACTION_NEXT_CONTROL = 181 +ACTION_NEXT_ITEM = 14 +ACTION_NEXT_LETTER = 140 +ACTION_NEXT_PICTURE = 28 +ACTION_NEXT_SCENE = 138 +ACTION_NEXT_SUBTITLE = 26 +ACTION_NONE = 0 +ACTION_NOOP = 999 +ACTION_OSD_HIDESUBMENU = 84 +ACTION_OSD_SHOW_DOWN = 72 +ACTION_OSD_SHOW_LEFT = 69 +ACTION_OSD_SHOW_RIGHT = 70 +ACTION_OSD_SHOW_SELECT = 73 +ACTION_OSD_SHOW_UP = 71 +ACTION_OSD_SHOW_VALUE_MIN = 75 +ACTION_OSD_SHOW_VALUE_PLUS = 74 +ACTION_PAGE_DOWN = 6 +ACTION_PAGE_UP = 5 +ACTION_PARENT_DIR = 9 +ACTION_PASTE = 180 +ACTION_PAUSE = 12 +ACTION_PLAY = 68 +ACTION_PLAYER_FORWARD = 77 +ACTION_PLAYER_PLAY = 79 +ACTION_PLAYER_PLAYPAUSE = 229 +ACTION_PLAYER_REWIND = 78 +ACTION_PREVIOUS_CHANNELGROUP = 187 +ACTION_PREVIOUS_MENU = 10 +ACTION_PREV_CONTROL = 182 +ACTION_PREV_ITEM = 15 +ACTION_PREV_LETTER = 141 +ACTION_PREV_PICTURE = 29 +ACTION_PREV_SCENE = 139 +ACTION_PVR_PLAY = 188 +ACTION_PVR_PLAY_RADIO = 190 +ACTION_PVR_PLAY_TV = 189 +ACTION_QUEUE_ITEM = 34 +ACTION_RECORD = 170 +ACTION_RELOAD_KEYMAPS = 203 +ACTION_REMOVE_ITEM = 35 +ACTION_RENAME_ITEM = 87 +ACTION_REWIND = 17 +ACTION_ROTATE_PICTURE_CCW = 51 +ACTION_ROTATE_PICTURE_CW = 50 +ACTION_SCAN_ITEM = 201 +ACTION_SCROLL_DOWN = 112 +ACTION_SCROLL_UP = 111 +ACTION_SELECT_ITEM = 7 +ACTION_SETTINGS_LEVEL_CHANGE = 242 +ACTION_SETTINGS_RESET = 241 +ACTION_SHIFT = 118 +ACTION_SHOW_CODEC = 27 +ACTION_SHOW_FULLSCREEN = 36 +ACTION_SHOW_GUI = 18 +ACTION_SHOW_INFO = 11 +ACTION_SHOW_MPLAYER_OSD = 83 +ACTION_SHOW_OSD = 24 +ACTION_SHOW_OSD_TIME = 123 +ACTION_SHOW_PLAYLIST = 33 +ACTION_SHOW_SUBTITLES = 25 +ACTION_SHOW_VIDEOMENU = 134 +ACTION_SMALL_STEP_BACK = 76 +ACTION_STEP_BACK = 21 +ACTION_STEP_FORWARD = 20 +ACTION_STEREOMODE_NEXT = 235 +ACTION_STEREOMODE_PREVIOUS = 236 +ACTION_STEREOMODE_SELECT = 238 +ACTION_STEREOMODE_SET = 240 +ACTION_STEREOMODE_TOGGLE = 237 +ACTION_STEREOMODE_TOMONO = 239 +ACTION_STOP = 13 +ACTION_SUBTITLE_ALIGN = 232 +ACTION_SUBTITLE_DELAY = 162 +ACTION_SUBTITLE_DELAY_MIN = 52 +ACTION_SUBTITLE_DELAY_PLUS = 53 +ACTION_SUBTITLE_VSHIFT_DOWN = 231 +ACTION_SUBTITLE_VSHIFT_UP = 230 +ACTION_SWITCH_PLAYER = 234 +ACTION_SYMBOLS = 119 +ACTION_TAKE_SCREENSHOT = 85 +ACTION_TELETEXT_BLUE = 218 +ACTION_TELETEXT_GREEN = 216 +ACTION_TELETEXT_RED = 215 +ACTION_TELETEXT_YELLOW = 217 +ACTION_TOGGLE_DIGITAL_ANALOG = 202 +ACTION_TOGGLE_FULLSCREEN = 199 +ACTION_TOGGLE_SOURCE_DEST = 32 +ACTION_TOGGLE_WATCHED = 200 +ACTION_TOUCH_LONGPRESS = 411 +ACTION_TOUCH_LONGPRESS_TEN = 420 +ACTION_TOUCH_TAP = 401 +ACTION_TOUCH_TAP_TEN = 410 +ACTION_TRIGGER_OSD = 243 +ACTION_VIS_PRESET_LOCK = 130 +ACTION_VIS_PRESET_NEXT = 128 +ACTION_VIS_PRESET_PREV = 129 +ACTION_VIS_PRESET_RANDOM = 131 +ACTION_VIS_PRESET_SHOW = 126 +ACTION_VIS_RATE_PRESET_MINUS = 133 +ACTION_VIS_RATE_PRESET_PLUS = 132 +ACTION_VOLAMP = 90 +ACTION_VOLAMP_DOWN = 94 +ACTION_VOLAMP_UP = 93 +ACTION_VOLUME_DOWN = 89 +ACTION_VOLUME_SET = 245 +ACTION_VOLUME_UP = 88 +ACTION_VSHIFT_DOWN = 228 +ACTION_VSHIFT_UP = 227 +ACTION_ZOOM_IN = 31 +ACTION_ZOOM_LEVEL_1 = 38 +ACTION_ZOOM_LEVEL_2 = 39 +ACTION_ZOOM_LEVEL_3 = 40 +ACTION_ZOOM_LEVEL_4 = 41 +ACTION_ZOOM_LEVEL_5 = 42 +ACTION_ZOOM_LEVEL_6 = 43 +ACTION_ZOOM_LEVEL_7 = 44 +ACTION_ZOOM_LEVEL_8 = 45 +ACTION_ZOOM_LEVEL_9 = 46 +ACTION_ZOOM_LEVEL_NORMAL = 37 +ACTION_ZOOM_OUT = 30 +ALPHANUM_HIDE_INPUT = 2 +CONTROL_TEXT_OFFSET_X = 10 +CONTROL_TEXT_OFFSET_Y = 2 +ICON_OVERLAY_HD = 6 +ICON_OVERLAY_LOCKED = 3 +ICON_OVERLAY_NONE = 0 +ICON_OVERLAY_RAR = 1 +ICON_OVERLAY_UNWATCHED = 4 +ICON_OVERLAY_WATCHED = 5 +ICON_OVERLAY_ZIP = 2 +ICON_TYPE_FILES = 106 +ICON_TYPE_MUSIC = 103 +ICON_TYPE_NONE = 101 +ICON_TYPE_PICTURES = 104 +ICON_TYPE_PROGRAMS = 102 +ICON_TYPE_SETTINGS = 109 +ICON_TYPE_VIDEOS = 105 +ICON_TYPE_WEATHER = 107 +INPUT_ALPHANUM = 0 +INPUT_DATE = 2 +INPUT_IPADDRESS = 4 +INPUT_NUMERIC = 1 +INPUT_PASSWORD = 5 +INPUT_TIME = 3 +KEY_APPCOMMAND = 53248 +KEY_ASCII = 61696 +KEY_BUTTON_A = 256 +KEY_BUTTON_B = 257 +KEY_BUTTON_BACK = 275 +KEY_BUTTON_BLACK = 260 +KEY_BUTTON_DPAD_DOWN = 271 +KEY_BUTTON_DPAD_LEFT = 272 +KEY_BUTTON_DPAD_RIGHT = 273 +KEY_BUTTON_DPAD_UP = 270 +KEY_BUTTON_LEFT_ANALOG_TRIGGER = 278 +KEY_BUTTON_LEFT_THUMB_BUTTON = 276 +KEY_BUTTON_LEFT_THUMB_STICK = 264 +KEY_BUTTON_LEFT_THUMB_STICK_DOWN = 281 +KEY_BUTTON_LEFT_THUMB_STICK_LEFT = 282 +KEY_BUTTON_LEFT_THUMB_STICK_RIGHT = 283 +KEY_BUTTON_LEFT_THUMB_STICK_UP = 280 +KEY_BUTTON_LEFT_TRIGGER = 262 +KEY_BUTTON_RIGHT_ANALOG_TRIGGER = 279 +KEY_BUTTON_RIGHT_THUMB_BUTTON = 277 +KEY_BUTTON_RIGHT_THUMB_STICK = 265 +KEY_BUTTON_RIGHT_THUMB_STICK_DOWN = 267 +KEY_BUTTON_RIGHT_THUMB_STICK_LEFT = 268 +KEY_BUTTON_RIGHT_THUMB_STICK_RIGHT = 269 +KEY_BUTTON_RIGHT_THUMB_STICK_UP = 266 +KEY_BUTTON_RIGHT_TRIGGER = 263 +KEY_BUTTON_START = 274 +KEY_BUTTON_WHITE = 261 +KEY_BUTTON_X = 258 +KEY_BUTTON_Y = 259 +KEY_INVALID = 65535 +KEY_MOUSE_CLICK = 57344 +KEY_MOUSE_DOUBLE_CLICK = 57360 +KEY_MOUSE_DRAG = 57604 +KEY_MOUSE_DRAG_END = 57606 +KEY_MOUSE_DRAG_START = 57605 +KEY_MOUSE_END = 61439 +KEY_MOUSE_LONG_CLICK = 57376 +KEY_MOUSE_MIDDLECLICK = 57346 +KEY_MOUSE_MOVE = 57603 +KEY_MOUSE_NOOP = 61439 +KEY_MOUSE_RDRAG = 57607 +KEY_MOUSE_RDRAG_END = 57609 +KEY_MOUSE_RDRAG_START = 57608 +KEY_MOUSE_RIGHTCLICK = 57345 +KEY_MOUSE_START = 57344 +KEY_MOUSE_WHEEL_DOWN = 57602 +KEY_MOUSE_WHEEL_UP = 57601 +KEY_TOUCH = 61440 +KEY_UNICODE = 61952 +KEY_VKEY = 61440 +KEY_VMOUSE = 61439 +AID_LEFT = 1 +MOVE_RIGHT = 2 +AID_RIGHT = 2 +AID_UP = 3 +AID_DOWN = 4 +FOCUS_LIST_DEVICE_GROUP = 4 +FOCUS_LIST_SENSORLIST = 5 +AID_ENTER = 7 +AID_ESC = 10 +HP_CEC_ENTER = 11 +AID_BACK = 92 +FOCUS_LIST_SCENES = 94 +FOCUS_LIST_FAV = 95 +FOCUS_LIST_DEVICES = 96 +FOCUS_LIST_SENSOR = 97 +FOCUS_LIST_CONFIG = 98 +MOUSE_LEFT_CLICK = 100 +SZENEN_DETAILS = 100 +FAVORITEN = 101 +FAVORITEN_LOKAL = 102 +ENTER = 135 +HP_CEC_UP = 166 +HP_CEC_DOWN = 167 +HP_CEC_RIGHT = 168 +HP_CEC_LEFT = 169 +HP_CEC_BACK = 216 +FOCUS_SCROLL_FAVLIST_SCN = 226 +FOCUS_LIST_FAVLIST_AKTOREN = 255 +FOCUS_LIST_DEVICE_TYP = 257 +FOCUS_LIST_SCENE_LIST = 258 +FOCUS_SCROLL_SCENELIST = 259 +FOCUS_LIST_FAVLIST_SZENEN = 264 +FOCUS_SCROLL_FAVLIST_DEV = 993 +FOCUS_SCROLL_DEVGROUP = 998 +FOCUS_SCROLL_DEVLIST = 999 +SENSOREN = 32007 +SZENEN = 32005 +SZENENTYPEN = 32016 +GRUPPEN = 32015 +#GERAETE = 32021 + +ROLLADEN = 32010 +SCHALTER = 32011 +DIMMER = 32012 +THERMOSTATE = 32013 +TORE = 32014 +ALLE = 32020 + +SZENEN_MANUELL = 32017 +SZENEN_NICHT_MANUELL = 32018 +SZENEN_ALLE = 32019 + +HP_VK_DOWN = 61569 +HP_VK_UP = 61568 +HP_VK_LEFT = 61570 +HP_VK_RIGHT = 61571 +HP_VK_ENTER = 61453 +HP_VK_BACK = 61448 +HP_VK_ESC = 61467 + + +FAVORITEN_VIEW = str(FAVORITEN) + "_view" +FAVORITEN_LOKAL_VIEW = str(FAVORITEN_LOKAL) + "_view" +GERAETETYP_VIEW = "geraetetyp_view" # String wird so noch irgendwo anders verwendet Anpassung nicht trivial str(GERAETE) + "_view" +DEVICE_GRUPPEN_VIEW = str(GRUPPEN) + "_view" +DEVICE_ALLE_VIEW = str(ALLE) + "_view" +SENSOREN_VIEW = str(SENSOREN) + "_view" +DEVICE_ROLLADEN_VIEW = str(ROLLADEN) + "_view" +DEVICE_SCHALTER_VIEW = str(SCHALTER) + "_view" +DEVICE_DIMMER_VIEW = str(DIMMER) + "_view" +DEVICE_THERMOSTATE_VIEW = str(THERMOSTATE) + "_view" +DEVICE_TORE_VIEW = str(TORE) + "_view" +SZENEN_MANUELL_VIEW = str(SZENEN_MANUELL) + "_view" +SZENEN_NICHT_MANUELL_VIEW = str(SZENEN_NICHT_MANUELL) + "_view" +SZENEN_ALLE_VIEW = str(SZENEN_ALLE) + "_view" +SZENENTYP_VIEW = str(SZENENTYPEN) + "_view" +SZENEN_DETAILS_VIEW = str(SZENEN_DETAILS) + "_view" +EMPTY_VIEW = "empty_view" +SZENEN_FOKUS_VIEW = str(FOCUS_LIST_SCENE_LIST) + "_view" +#scene Window + + + +#Homepilot Client +icons = {"iconset1": "aquarium_72_", + "iconset2": "bargraph_vertikal_72_", + "iconset4": "deckenlampe_72_", + "iconset5": "ein_aus_schalter1_72_", + "iconset6": "jalousie_72_", + "iconset7": "markise_72_", + "iconset8": "rollladen1_72_", + "iconset9": "schiebetuer_72_", + "iconset10": "steckdose_72_", + "iconset11": "tischlampe_72_", + "iconset12": "tuer_72_", + "iconset13": "stehlampe_72_", + "iconset14": "schiebeladen_72_", + "iconset15": "rollladen2_72_", + "iconset16": "pumpe_72_", + "iconset17": "kaffeemaschine_72_", + "iconset18": "gartensprenkler_72_", + "iconset20": "sunscreen_72_", + "iconset21": "birne1_72_", + "iconset22": "bargraph_horizontal_72_", + "iconset23": "bewegungsmelder_72_", + "iconset24": "fenster_72_", + "iconset25": "genericsensor_72_", + "iconset26": "rauchmelder_72_", + "iconset27": "schliesskontakt_72_", + "iconset28": "thermostat_72_", + "iconset30": "garage_72_", + "iconset31": "sektionaltor_72_", + "iconset32": "lichterkette_72_", + "iconset33": "weihnachtsbaum_72_", + "iconset34": "dachfenster_72_", + "iconset35": "handsender_72_", + "iconset36": "leinwand_72_", + "iconset37": "radio_72_", + "iconset38": "smartphone_72_", + "iconset39": "ventilator_72_"} + +DAWN = "dawn" +DUSK = "dusk" +TIME = "time" +WIND = "wind" +TEMPERATUR = "temperature" +TEMPERATOR = "temperator" +GENERIC = "generic" +TRIGGER = "trigger" +CLOSINGCONTACT = "closingContact" +SMOKE = "smoke" +SUN = "sun" +MANUAL = "manual" +DUST = "dust" +FAVORED = "favored" +SMARTPHONE = "smartphone" +MOTION = "motion" +WARNING = "warning" +RAIN = "rain" + +DEVICESET = [DEVICE_ROLLADEN_VIEW, DEVICE_SCHALTER_VIEW, + DEVICE_DIMMER_VIEW, DEVICE_THERMOSTATE_VIEW, + DEVICE_TORE_VIEW, DEVICE_ALLE_VIEW] +SCENE_SET = [SZENEN_MANUELL_VIEW, SZENEN_NICHT_MANUELL_VIEW, + SZENEN_ALLE_VIEW] +SHUTDOWN_SET = [FOCUS_LIST_FAV, FOCUS_LIST_DEVICES, FOCUS_LIST_SCENES, FOCUS_LIST_SENSOR, FOCUS_LIST_CONFIG] + +SCROLLBAR_IDS = [FOCUS_LIST_FAVLIST_AKTOREN, FOCUS_LIST_FAVLIST_SZENEN, FOCUS_LIST_DEVICE_GROUP] \ No newline at end of file diff --git a/script.homepilot/resources/skins/Default/720p/homepilot.xml b/script.homepilot/resources/skins/Default/720p/homepilot.xml index b00047d..139e33f 100644 --- a/script.homepilot/resources/skins/Default/720p/homepilot.xml +++ b/script.homepilot/resources/skins/Default/720p/homepilot.xml @@ -165,6 +165,7 @@ MenuItemFO.png MenuItemNF.png + 257 Button Szenen @@ -179,6 +180,7 @@ MenuItemFO.png MenuItemNF.png + 260 Button Sensoren @@ -219,8 +221,7 @@ 320 251 4 - Action(enter) - 96 + 61 @@ -394,7 +395,7 @@ 20 12 200 - SetFocus(4) + 4 noop vertical true @@ -577,8 +578,8 @@ 750 20 12 - - Action(zoomin) + noop vertical true @@ -794,7 +795,7 @@ 258 258 259 - 94 + 257 259 @@ -912,7 +913,7 @@ 20 12 500 - 258 + noop vertical true diff --git a/script.homepilot/resources/skins/skin.aeon.nox.5/720p/homepilot.xml b/script.homepilot/resources/skins/skin.aeon.nox.5/720p/homepilot.xml index 296e08e..aca3c32 100644 --- a/script.homepilot/resources/skins/skin.aeon.nox.5/720p/homepilot.xml +++ b/script.homepilot/resources/skins/skin.aeon.nox.5/720p/homepilot.xml @@ -206,8 +206,8 @@ 760 320 251 - 4 - Action(enter) + 61 @@ -369,7 +369,7 @@ 20 12 200 - SetFocus(4) + 4 noop vertical true @@ -545,7 +545,7 @@ 0 8 540 - Action(zoomin) + noop vertical true @@ -747,7 +747,8 @@ 760 500 258 - 258 + 259 + 257 259 @@ -860,7 +861,7 @@ 20 8 540 - Action(zoomin) + noop vertical true diff --git a/script.homepilot/resources/skins/skin.aeon.nox.5/720p/scene_window.xml b/script.homepilot/resources/skins/skin.aeon.nox.5/720p/scene_window.xml index d7ab072..4f54dc3 100644 --- a/script.homepilot/resources/skins/skin.aeon.nox.5/720p/scene_window.xml +++ b/script.homepilot/resources/skins/skin.aeon.nox.5/720p/scene_window.xml @@ -16,7 +16,7 @@ dialog_back3.png - + true 400