예제 #1
0
 def get_status(pairedDeviceId, language=AppInfo.DEFAULT_API_LANGUAGE):
     return SharedMethod.call(kbxMethodAppId=SharedMethod.get_system_id(),
                              kbxMethodName="get_status",
                              kbxModuleName="device_manager.horn_controller",
                              pyapi=SharedMethod.get_pyapi(),
                              pairedDeviceId=pairedDeviceId,
                              **{AppInfo.REQUEST_KEY_LANGUAGE:language})
예제 #2
0
    def list_groups(self, language, section, parentId=None):
        try:
            def sort_group_list(value):
                name = value.get("kbxGroupLabel")
                if name is None:
                    return ""
                else:
                    return str(name).lower()
                
            
            unknownGroupDict = {}
            unknownGroupId = self.__get_group_ids()
                
            parentId = AppConstants.GROUP_ID_AUTOMATION if parentId is None else parentId

            result = SharedMethod.list_shared_method_groups(kbxGroupParentId=parentId, kbxMethodTag=section,
                                                            enableTagCount=True, language=language)
            
            groupList = result["groupList"]
            
            # Level 1 groups which contain of SERVICES and LOCATIONS.
            if parentId == AppConstants.GROUP_ID_AUTOMATION:
                services = deque()
                groups =  deque()
                
                for groupDict in groupList:
                    kbxGroupId = groupDict["kbxGroupId"]
                    
                    # Add indicator for UI
                    groupDict["kbxGroupHasChild"] = True

                    # Reordering
                    if kbxGroupId == AppConstants.GROUP_ID_NOTIFICATION:
                        groupDict["kbxGroupDesc"] = KBXLang("group_notification_" + section)
                        services.appendleft(groupDict)
                    elif kbxGroupId == AppConstants.GROUP_ID_SERVICE:
                        groupDict["kbxGroupDesc"] = KBXLang("group_service_" + section)
                        services.append(groupDict)
                    elif kbxGroupId == unknownGroupId:
                        #append the group dict
                        unknownGroupDict = groupDict
                    else:
                        groups.append(groupDict)
                groups = sorted(groups, key=sort_group_list)
                if len(unknownGroupDict) > 0:
                    groups.append(unknownGroupDict)
                services.extend(groups)
                groupList = services
                parentGroup = None
                
            # Level 2 groups which are DEVICES or SERVICES.
            else:
                parentGroup = SharedMethod.get_shared_method_group_by_id(kbxGroupId=parentId, language=language)

            return parentGroup, groupList

        except Exception as e:
            Logger.log_error("APIService.list_groups ex:", e)
            raise AutomationException(11601, "Unexpected error - " + str(e))
예제 #3
0
 def get_status(pairedDeviceId, language=AppInfo.DEFAULT_API_LANGUAGE):
     return SharedMethod.call(
         kbxMethodAppId=SharedMethod.get_system_id(),
         kbxMethodName="get_status",
         kbxModuleName="device_manager.horn_controller",
         pyapi=SharedMethod.get_pyapi(),
         pairedDeviceId=pairedDeviceId,
         **{AppInfo.REQUEST_KEY_LANGUAGE: language})
예제 #4
0
 def update_method(self,
                   kbxMethodName,
                   kbxMethodFunc=SharedMethod.get_empty_placeholder(),
                   kbxMethodIsPrivate=SharedMethod.get_empty_placeholder(),
                   kbxMethodLabel=SharedMethod.get_empty_placeholder(),
                   kbxMethodDesc=SharedMethod.get_empty_placeholder(),
                   kbxMethodParams=SharedMethod.get_empty_placeholder(),
                   **kbxMethodProps):
     pass
예제 #5
0
 def set_off(pairedDeviceId, language=AppInfo.DEFAULT_API_LANGUAGE):
     '''
     Turn off switch.
     pairedDeviceId:Number :- Paired Device ID return from DeviceManagerService.get_paired_device_list
     transitionTime:Number :- Optional. the duration of the transition from the light's current state to the new state.
     '''
     return SharedMethod.call(kbxMethodAppId=SharedMethod.get_system_id(),
                              kbxMethodName="set_off",
                              kbxModuleName="device_manager.horn_controller",
                              pyapi=SharedMethod.get_pyapi(),
                              pairedDeviceId=pairedDeviceId,
                              **{AppInfo.REQUEST_KEY_LANGUAGE:language})
예제 #6
0
 def set_off(pairedDeviceId, language=AppInfo.DEFAULT_API_LANGUAGE):
     '''
     Turn off switch.
     pairedDeviceId:Number :- Paired Device ID return from DeviceManagerService.get_paired_device_list
     transitionTime:Number :- Optional. the duration of the transition from the light's current state to the new state.
     '''
     return SharedMethod.call(
         kbxMethodAppId=SharedMethod.get_system_id(),
         kbxMethodName="set_off",
         kbxModuleName="device_manager.horn_controller",
         pyapi=SharedMethod.get_pyapi(),
         pairedDeviceId=pairedDeviceId,
         **{AppInfo.REQUEST_KEY_LANGUAGE: language})
예제 #7
0
 def update_kbx_group(self):
     '''
     Updates information where necessary only.
     '''
     result = self.__db.execute_and_fetch_all('SELECT "kbxGroupId" FROM "kbx_group" WHERE "kbxGroupId" > 0')
     
     if len(result) == 0:
         return
     
     kbxGroupIds = set([])
     
     for row in result:
         kbxGroupId = row["kbxGroupId"]
         kbxGroupIds.add(kbxGroupId)
         
     result = SharedMethod.list_shared_method_groups(kbxGroupId=list(kbxGroupIds), enableTagCount=False, limit=len(kbxGroupIds))
     kbxGroups = result["groupList"]
     
     for kbxGroup in kbxGroups:
         # Variables
         kbxGroupId = kbxGroup["kbxGroupId"]
         
         kbxGroupIds.remove(kbxGroupId)
         self.__groupController.update(kbxGroup)
 
     for kbxGroupId in kbxGroupIds:
         self.__groupController.delete(kbxGroupId)
예제 #8
0
 def update_kbx_method(self):
     '''
     Update information of kbxMethod.
     Add and remove group ID if kbxGroupId is updated.
     Add listener if necessary.
     '''
     result = self.__db.execute_and_fetch_all('SELECT "kbxMethodId" FROM "kbx_method" WHERE "kbxMethodId" > 0')
     
     if len(result) == 0:
         return
     
     kbxMethodIds = set([])
     
     for row in result:
         kbxMethodId = row["kbxMethodId"]
         kbxMethodIds.add(kbxMethodId)
     
     result = SharedMethod.list_shared_methods(kbxMethodId=list(kbxMethodIds), 
                                               kbxMethodStatus=[SharedMethod.METHOD_STATUS_ACTIVE, SharedMethod.METHOD_STATUS_INACTIVE], 
                                               limit=len(kbxMethodIds))
     kbxMethods = result["methodList"]
     for kbxMethod in kbxMethods:
         # Variables
         kbxMethodId = kbxMethod["kbxMethodId"]
         
         kbxMethodIds.remove(kbxMethodId) # For each kbxMethod which has result when listing from system, pop it out from kbxMethodsFromDB
         self.__methodController.update(kbxMethod)
         
     # The kbxMethodIds left here are all removed methods.
     for kbxMethodId in kbxMethodIds:
         self.__methodController.delete(kbxMethodId)
예제 #9
0
    def list_shared_method_groups(kbxGroupId,
                                  language=AppInfo.DEFAULT_API_LANGUAGE,
                                  limit=100,
                                  **kwargs):
        '''
        limit - This will be override no matter what. Do not pass any argument for it.
        '''
        KBXLang.set_preferred_lang(language)

        kbxGroupIds = set(kbxGroupId)
        publicGroupIds, privateGroupIds = [
            gId for gId in kbxGroupIds if gId > 0
        ], (gId for gId in kbxGroupIds if gId < 0)
        finalGroupList = deque()

        publicGroupIdsLen = len(publicGroupIds)
        if publicGroupIdsLen > 0:
            result = SharedMethod.list_shared_method_groups(
                kbxGroupId=publicGroupIds,
                limit=publicGroupIdsLen,
                language=language,
                **kwargs)
            finalGroupList.extend(result["groupList"])

        for privateGroupId in privateGroupIds:
            privateGroup = SharedMethodWrapper.PRIVATE_GROUPS.get(
                privateGroupId)
            if privateGroup is not None:
                privateGroup["kbxGroupLabel"] = str(
                    privateGroup["kbxGroupLabel"])
                finalGroupList.append(privateGroup)

        return finalGroupList
예제 #10
0
    def list_shared_methods(kbxMethodId, language=AppInfo.DEFAULT_API_LANGUAGE, limit=100, **kwargs):
        '''
        limit - This will be override no matter what. Do not pass any argument for it.
        '''
        KBXLang.set_preferred_lang(language)
        
        kbxMethodIds = set(kbxMethodId)
        publicMethodIds, privateMethodIds = [mId for mId in kbxMethodIds if mId > 0], (mId for mId in kbxMethodIds if mId < 0)
        finalMethodList = deque()
        
        publicMethodIdsLen = len(publicMethodIds)
        if publicMethodIdsLen > 0:
            result = SharedMethod.list_shared_methods(kbxMethodId=publicMethodIds, 
                                                      limit=publicMethodIdsLen, 
                                                      language=language, 
                                                      **kwargs)
            finalMethodList.extend(result["methodList"])

        for privateMethodId in privateMethodIds:
            privateMethod = SharedMethodWrapper.PRIVATE_METHODS.get(privateMethodId)
            if privateMethod is not None:
                privateMethod["kbxMethodLabel"] = str(privateMethod["kbxMethodLabel"])
                finalMethodList.append(privateMethod)
                
        return finalMethodList
예제 #11
0
    def list_shared_method_groups(kbxGroupId, language=AppInfo.DEFAULT_API_LANGUAGE, limit=100, **kwargs):
        '''
        limit - This will be override no matter what. Do not pass any argument for it.
        '''
        KBXLang.set_preferred_lang(language)
        
        kbxGroupIds = set(kbxGroupId)
        publicGroupIds, privateGroupIds = [gId for gId in kbxGroupIds if gId > 0], (gId for gId in kbxGroupIds if gId < 0)
        finalGroupList = deque()
        
        publicGroupIdsLen = len(publicGroupIds)
        if publicGroupIdsLen > 0:
            result = SharedMethod.list_shared_method_groups(kbxGroupId=publicGroupIds, 
                                                            limit=publicGroupIdsLen, 
                                                            language=language, 
                                                            **kwargs)
            finalGroupList.extend(result["groupList"])

        for privateGroupId in privateGroupIds:
            privateGroup = SharedMethodWrapper.PRIVATE_GROUPS.get(privateGroupId)
            if privateGroup is not None:
                privateGroup["kbxGroupLabel"] = str(privateGroup["kbxGroupLabel"])
                finalGroupList.append(privateGroup)
                
        return finalGroupList
예제 #12
0
    def update_shared_method(self, kbxMethodName, kbxGroupId=None, kbxMethodFunc=SharedMethod.get_empty_placeholder(), kbxMethodIsPrivate=SharedMethod.get_empty_placeholder(),
                             kbxMethodLabel=SharedMethod.get_empty_placeholder(), kbxMethodDesc=SharedMethod.get_empty_placeholder(),
                             kbxMethodTag=SharedMethod.get_empty_placeholder(), kbxMethodParams=SharedMethod.get_empty_placeholder(), **kbxMethodProps):
        '''
        Update registered shared method by method properties.

        Params:
        kbxMethodName:Integer - [Required] Method name.
        kbxGroupId:Integer - [Required] Method group id.
        kbxModuleName:String - [Required] Module name.
        kbxMethodLabel:String - [Optional] New labe for the method.
        kbxMethodDesc:String - [Optional] New description of the method.
        kbxMethodTag:List<String> - [Optional] New method tags.
        kbxMethodParams:List<KBXParam> - [Optional] New method params.
        '''
        pass
예제 #13
0
    def list_shared_methods(kbxMethodId,
                            language=AppInfo.DEFAULT_API_LANGUAGE,
                            limit=100,
                            **kwargs):
        '''
        limit - This will be override no matter what. Do not pass any argument for it.
        '''
        KBXLang.set_preferred_lang(language)

        kbxMethodIds = set(kbxMethodId)
        publicMethodIds, privateMethodIds = [
            mId for mId in kbxMethodIds if mId > 0
        ], (mId for mId in kbxMethodIds if mId < 0)
        finalMethodList = deque()

        publicMethodIdsLen = len(publicMethodIds)
        if publicMethodIdsLen > 0:
            result = SharedMethod.list_shared_methods(
                kbxMethodId=publicMethodIds,
                limit=publicMethodIdsLen,
                language=language,
                **kwargs)
            finalMethodList.extend(result["methodList"])

        for privateMethodId in privateMethodIds:
            privateMethod = SharedMethodWrapper.PRIVATE_METHODS.get(
                privateMethodId)
            if privateMethod is not None:
                privateMethod["kbxMethodLabel"] = str(
                    privateMethod["kbxMethodLabel"])
                finalMethodList.append(privateMethod)

        return finalMethodList
예제 #14
0
    def update_kbx_group(self):
        '''
        Updates information where necessary only.
        '''
        result = self.__db.execute_and_fetch_all(
            'SELECT "kbxGroupId" FROM "kbx_group" WHERE "kbxGroupId" > 0')

        if len(result) == 0:
            return

        kbxGroupIds = set([])

        for row in result:
            kbxGroupId = row["kbxGroupId"]
            kbxGroupIds.add(kbxGroupId)

        result = SharedMethod.list_shared_method_groups(
            kbxGroupId=list(kbxGroupIds),
            enableTagCount=False,
            limit=len(kbxGroupIds))
        kbxGroups = result["groupList"]

        for kbxGroup in kbxGroups:
            # Variables
            kbxGroupId = kbxGroup["kbxGroupId"]

            kbxGroupIds.remove(kbxGroupId)
            self.__groupController.update(kbxGroup)

        for kbxGroupId in kbxGroupIds:
            self.__groupController.delete(kbxGroupId)
예제 #15
0
    def list_shared_methods_by_app_id(kbxMethodAppId,
                                      kbxMethodIds,
                                      language=AppInfo.DEFAULT_API_LANGUAGE):
        KBXLang.set_preferred_lang(language)

        kbxMethodIds = set(kbxMethodIds)
        publicMethodIds, privateMethodIds = [
            mId for mId in kbxMethodIds if mId > 0
        ], (mId for mId in kbxMethodIds if mId < 0)
        finalMethodDict = {}

        publicMethodIdsLen = len(publicMethodIds)
        if publicMethodIdsLen > 0:
            result = SharedMethod.list_shared_methods_by_app_id(
                kbxMethodAppId=kbxMethodAppId,
                kbxMethodIds=publicMethodIds,
                language=language)
            finalMethodDict.update(result)

        for privateMethodId in privateMethodIds:
            privateMethod = SharedMethodWrapper.PRIVATE_METHODS.get(
                privateMethodId)
            if privateMethod is not None:
                privateMethod["kbxMethodLabel"] = str(
                    privateMethod["kbxMethodLabel"])
                finalMethodDict[privateMethodId] = privateMethod
            else:
                finalMethodDict[privateMethodId] = None

        return finalMethodDict
예제 #16
0
    def set_advanced_setting(self, request):
        try:
            contentRaw = request.get_post_data()
            contentDecoded = contentRaw.decode("utf-8")
            contentDecoded = urllib.parse.unquote_plus(contentDecoded)
            kwargs = {
                str(x[0]): str(x[1])
                for x in (i.split("=", 1) for i in contentDecoded.split("&"))
            }

            params = json.loads(kwargs["kbxMethodParam"])
            params = {
                str(param["kbxParamName"]): param.get("kbxParamCurrentValue",
                                                      None)
                for param in params
            }
            params["kbxMethodId"] = int(kwargs["kbxMethodId"])

            returnStr = SharedMethod.call_by_method_id(**params)
            self.send_response(returnStr, request.requestId)
        except SystemException as se:
            self.send_response(se.value, request.requestId,
                               se.value["returnValue"],
                               se.value["returnMessage"])
        except Exception as e:
            self.send_response({"error": str(e)}, request.requestId, 1001)
예제 #17
0
    def __get_group_ids(self):
        try:
            if AppConstants.GROUP_ID_UNKNOWN_LOCATION is None:
                systemId = SharedMethod.get_system_id()
                results = SharedMethod.list_shared_method_groups(kbxGroupAppId=[systemId],
                                                                 kbxGroupParentId=AppConstants.GROUP_ID_AUTOMATION)
    
                #groups = {group.get("kbxGroupName", "_"):group.get("kbxGroupId") for group in results["groupList"]}
                for group in results["groupList"]:
                    if group.get("otherLocation") == True:
                        AppConstants.GROUP_ID_UNKNOWN_LOCATION = group.get("kbxGroupId")
                        break
                    
            return AppConstants.GROUP_ID_UNKNOWN_LOCATION

        except Exception as e:
            raise e
예제 #18
0
    def update_shared_method_group(
            self,
            kbxGroupName,
            kbxGroupParentId=None,
            kbxGroupLabel=SharedMethod.get_empty_placeholder(),
            kbxGroupDesc=SharedMethod.get_empty_placeholder(),
            **kbxGroupProps):
        '''
        Update registered shared method group by group properties.

        Params:
        kbxGroupName:String - [Required] Name of the group.
        kbxGroupParentId:Integer - [Required] Parent group id of the group
        kbxMethodLabel:String - [Optional] New label for the group.
        kbxMethodDesc:String - [Optional] New description for the group.
        '''
        pass
예제 #19
0
    def __get_default_group_ids(self):
        try:
            systemId = SharedMethod.get_system_id()

            results = SharedMethod.list_shared_method_groups(kbxGroupAppId=[systemId],
                                                             kbxGroupName=["automation_app", "notification", "service"])

            groups = {group.get("kbxGroupName", "_"):group.get("kbxGroupId") for group in results["groupList"]}

            AppConstants.GROUP_ID_AUTOMATION = groups["automation_app"]
            AppConstants.GROUP_ID_NOTIFICATION = groups["notification"]
            AppConstants.GROUP_ID_SERVICE = groups["service"]

        except Exception as e:
            Logger.log_error("AutomationApp on_system_connected retrying __get_default_group_ids, ex:", e)
            traceback.print_exc()
            raise e
예제 #20
0
 def get_shared_method_by_id(kbxMethodId, language=AppInfo.DEFAULT_API_LANGUAGE):
     KBXLang.set_preferred_lang(language)
     
     if kbxMethodId < 0:
         privateMethod = SharedMethodWrapper.PRIVATE_METHODS[kbxMethodId]
         if privateMethod is not None:
             privateMethod["kbxMethodLabel"] = str(privateMethod["kbxMethodLabel"])
             return privateMethod
         
     return SharedMethod.get_shared_method_by_id(kbxMethodId, language)
예제 #21
0
 def get_shared_method_group_by_id(kbxGroupId, enableTagCount=False, language=AppInfo.DEFAULT_API_LANGUAGE):
     KBXLang.set_preferred_lang(language)
     
     if kbxGroupId < 0:
         privateGroup = SharedMethodWrapper.PRIVATE_GROUPS[kbxGroupId]
         if privateGroup is not None:
             privateGroup["kbxGroupLabel"] = str(privateGroup["kbxGroupLabel"])
             return privateGroup
         
     return SharedMethod.get_shared_method_group_by_id(kbxGroupId, enableTagCount, language)
예제 #22
0
    def update_shared_method_group(self, kbxGroupName, kbxGroupParentId=None,
                                   kbxGroupLabel=SharedMethod.get_empty_placeholder(), kbxGroupDesc=SharedMethod.get_empty_placeholder(), **kbxGroupProps):
        '''
        Update registered shared method group by group properties.

        Params:
        kbxGroupName:String - [Required] Name of the group.
        kbxGroupParentId:Integer - [Required] Parent group id of the group
        kbxMethodLabel:String - [Optional] New label for the group.
        kbxMethodDesc:String - [Optional] New description for the group.
        '''
        pass
예제 #23
0
    def get_shared_method_by_id(kbxMethodId,
                                language=AppInfo.DEFAULT_API_LANGUAGE):
        KBXLang.set_preferred_lang(language)

        if kbxMethodId < 0:
            privateMethod = SharedMethodWrapper.PRIVATE_METHODS[kbxMethodId]
            if privateMethod is not None:
                privateMethod["kbxMethodLabel"] = str(
                    privateMethod["kbxMethodLabel"])
                return privateMethod

        return SharedMethod.get_shared_method_by_id(kbxMethodId, language)
예제 #24
0
    def get_shared_method_group_by_id(kbxGroupId,
                                      enableTagCount=False,
                                      language=AppInfo.DEFAULT_API_LANGUAGE):
        KBXLang.set_preferred_lang(language)

        if kbxGroupId < 0:
            privateGroup = SharedMethodWrapper.PRIVATE_GROUPS[kbxGroupId]
            if privateGroup is not None:
                privateGroup["kbxGroupLabel"] = str(
                    privateGroup["kbxGroupLabel"])
                return privateGroup

        return SharedMethod.get_shared_method_group_by_id(
            kbxGroupId, enableTagCount, language)
예제 #25
0
    def __get_default_group_ids(self):
        try:
            systemId = SharedMethod.get_system_id()

            results = SharedMethod.list_shared_method_groups(
                kbxGroupAppId=[systemId],
                kbxGroupName=["automation_app", "notification", "service"])

            groups = {
                group.get("kbxGroupName", "_"): group.get("kbxGroupId")
                for group in results["groupList"]
            }

            AppConstants.GROUP_ID_AUTOMATION = groups["automation_app"]
            AppConstants.GROUP_ID_NOTIFICATION = groups["notification"]
            AppConstants.GROUP_ID_SERVICE = groups["service"]

        except Exception as e:
            Logger.log_error(
                "AutomationApp on_system_connected retrying __get_default_group_ids, ex:",
                e)
            traceback.print_exc()
            raise e
예제 #26
0
    def list_methods(self, language, section, groupId):
        try:
            result = SharedMethod.list_shared_methods(kbxGroupId=groupId,
                                                      kbxMethodTag=section,
                                                      kbxMethodStatus=[SharedMethod.METHOD_STATUS_ACTIVE, SharedMethod.METHOD_STATUS_INACTIVE],
                                                      language=language)

            methodList = result["methodList"]

            #===================================================================
            # Get group information
            #===================================================================
            groupDict = SharedMethod.get_shared_method_group_by_id(kbxGroupId=groupId, language=language)
            
            # Append "kbxMethodHasEvent" indicator.
            for kbxMethod in methodList:
                kbxMethodEvent = kbxMethod.get("kbxMethodEvent")
                kbxMethodIdentifier = kbxMethod.get("kbxMethodIdentifier")
                kbxMethod["kbxMethodHasEvent"] = not Util.is_empty(kbxMethodEvent) and not Util.is_empty(kbxMethodIdentifier)

            return methodList, groupDict
        except Exception as e:
            Logger.log_error("APIService.list_methods ex:", e)
            raise AutomationException(11601, "Unexpected error - " + str(e))
예제 #27
0
 def set_advanced_setting(self, request):
     try:
         contentRaw = request.get_post_data()
         contentDecoded = contentRaw.decode("utf-8")
         contentDecoded = urllib.parse.unquote_plus(contentDecoded)
         kwargs = {str(x[0]):str(x[1]) for x in (i.split("=", 1) for i in contentDecoded.split("&"))}
         
         params = json.loads(kwargs["kbxMethodParam"])
         params = {str(param["kbxParamName"]):param.get("kbxParamCurrentValue", None) for param in params}
         params["kbxMethodId"] = int(kwargs["kbxMethodId"])
         
         returnStr = SharedMethod.call_by_method_id(**params)
         self.send_response(returnStr, request.requestId)
     except SystemException as se:
         self.send_response(se.value, request.requestId, se.value["returnValue"], se.value["returnMessage"])
     except Exception as e:
         self.send_response({"error":str(e)}, request.requestId, 1001)
예제 #28
0
    def __retry_seri_implementation(self, serId, serisWithError, seriIndexes):
        try:
            # Update statuses of all items to be retried to "busy".
            self.__serController.update_seri_status(serId=serId, seriIndexes=seriIndexes, seriStatus="busy", seriError=None)
            
            # Broadcast event.
            self.__broadcast_message__seri_retry_started(serId, seriIndexes=seriIndexes)
            
            # Retry process starts here.
            for seri in serisWithError:
                try:
                    kbxMethodId = seri["kbxMethodId"]
                    if kbxMethodId != -291: # Skips all -291 and declare as "ok" immediately.
                        params = {kbxMethodParam["kbxParamName"]:kbxMethodParam["kbxParamCurrentValue"] 
                                  for kbxMethodParam in seri["kbxMethodParams"]}
                        result = SharedMethod.call_by_method_id(kbxMethodId, **params)
                        seriError = str(result)
                    else:
                        seriError = None
                    
                    seriStatus = "ok"
                    
                except Exception as e:
                    seriStatus = "error"
                    seriError = str(e)
                    
                finally:
                    seriIndex = seri["seriIndex"]
                    
                    if not self.__serLock.is_deleted(serId):
                        # Update statuses and broadcast events only if ser is not deleted.
                        self.__serController.update_seri_status(serId=serId, seriIndexes=[seriIndex], 
                                                                seriStatus=seriStatus, seriError=seriError)
                        self.__broadcast_message__seri_retry_completed(serId, seriIndex, seriStatus, seriError)
                    
        except Exception as e:
            ''' THIS PORTION SHOULD NEVER RUN. (it's bug if this portion is executed) '''
            Logger.log_error("SceneExecutionResultService.retry_scene_execution_result_item ex:", e)

        finally:
            self.__serLock.unlock(serId)
예제 #29
0
 def execution_func(sceneThreadEvent, kbxMethodId, seri, **kwargs):
     try:
         if kbxMethodId == -291:
             # Delay Timer
             delayInSec = kwargs["delayInSec"]
             sceneThreadEvent.wait(delayInSec)
             seri["seriError"] = None
         else:
             # Execute method
             result = SharedMethod.call(**kwargs)
             seri["seriError"] = str(result)
             
         seri["seriStatus"] = "ok"
     
     except Exception as e:
         seri["seriStatus"] = "error"
         seri["seriError"] = str(e)
         Logger.log_debug("Execution failed, method:", kwargs["kbxMethodName"])
     
     finally:
         sceneThreadEvent.set()
예제 #30
0
        def execution_func(sceneThreadEvent, kbxMethodId, seri, **kwargs):
            try:
                if kbxMethodId == -291:
                    # Delay Timer
                    delayInSec = kwargs["delayInSec"]
                    sceneThreadEvent.wait(delayInSec)
                    seri["seriError"] = None
                else:
                    # Execute method
                    result = SharedMethod.call(**kwargs)
                    seri["seriError"] = str(result)

                seri["seriStatus"] = "ok"

            except Exception as e:
                seri["seriStatus"] = "error"
                seri["seriError"] = str(e)
                Logger.log_debug("Execution failed, method:",
                                 kwargs["kbxMethodName"])

            finally:
                sceneThreadEvent.set()
예제 #31
0
 def update_kbx_method(self, kbxMethodId):
     '''
     Returns: 
     None: Method Removed
     True: Method Active
     False: Method Inactive
     '''
     hasKBXMethod = self.__apiController.has_kbx_method(kbxMethodId)
     if not hasKBXMethod:
         raise AutomationException(11602, "Method ID provided: " + str(kbxMethodId))
     
     try:
         kbxMethod = SharedMethod.get_shared_method_by_id(kbxMethodId, language=AppInfo.DEFAULT_API_LANGUAGE)
     except SystemException as se:
         if se.value["returnValue"] == 1608:
             self.__methodController.delete(kbxMethodId)
             return None # None: Method Removed
         else:
             raise AutomationException(11601, "Unexpected returnValue when get method: " + str(se))
     else:
         self.__methodController.update(kbxMethod)
         return kbxMethod["kbxMethodStatus"] == SharedMethod.METHOD_STATUS_ACTIVE # True: Active, False: Inactive
예제 #32
0
 def update_kbx_group(self, kbxGroupId):
     '''
     Returns
     None: Group Removed
     True: Group Exists
     '''
     hasKBXGroup = self.__apiController.has_kbx_group(kbxGroupId)
     if not hasKBXGroup:
         raise AutomationException(11603, "Group ID provided: " + str(kbxGroupId))
     
     try:
         kbxGroup = SharedMethod.get_shared_method_group_by_id(kbxGroupId, enableTagCount=False, 
                                                               language=AppInfo.DEFAULT_API_LANGUAGE)
     except SystemException as se:
         if se.value["returnValue"] == 1609:
             self.__groupController.delete(kbxGroupId)
             return None
         else:
             raise AutomationException(11601, "Unexpected returnValue when get method group: " + str(se))
     else:
         self.__groupController.update(kbxGroup)
         return True
예제 #33
0
    def update_kbx_method(self):
        '''
        Update information of kbxMethod.
        Add and remove group ID if kbxGroupId is updated.
        Add listener if necessary.
        '''
        result = self.__db.execute_and_fetch_all(
            'SELECT "kbxMethodId" FROM "kbx_method" WHERE "kbxMethodId" > 0')

        if len(result) == 0:
            return

        kbxMethodIds = set([])

        for row in result:
            kbxMethodId = row["kbxMethodId"]
            kbxMethodIds.add(kbxMethodId)

        result = SharedMethod.list_shared_methods(
            kbxMethodId=list(kbxMethodIds),
            kbxMethodStatus=[
                SharedMethod.METHOD_STATUS_ACTIVE,
                SharedMethod.METHOD_STATUS_INACTIVE
            ],
            limit=len(kbxMethodIds))
        kbxMethods = result["methodList"]
        for kbxMethod in kbxMethods:
            # Variables
            kbxMethodId = kbxMethod["kbxMethodId"]

            kbxMethodIds.remove(
                kbxMethodId
            )  # For each kbxMethod which has result when listing from system, pop it out from kbxMethodsFromDB
            self.__methodController.update(kbxMethod)

        # The kbxMethodIds left here are all removed methods.
        for kbxMethodId in kbxMethodIds:
            self.__methodController.delete(kbxMethodId)
예제 #34
0
    def list_shared_methods_by_app_id(kbxMethodAppId, kbxMethodIds, language=AppInfo.DEFAULT_API_LANGUAGE):
        KBXLang.set_preferred_lang(language)
        
        kbxMethodIds = set(kbxMethodIds)
        publicMethodIds, privateMethodIds = [mId for mId in kbxMethodIds if mId > 0], (mId for mId in kbxMethodIds if mId < 0)
        finalMethodDict = {}
        
        publicMethodIdsLen = len(publicMethodIds)
        if publicMethodIdsLen > 0:
            result = SharedMethod.list_shared_methods_by_app_id(kbxMethodAppId=kbxMethodAppId, 
                                                                kbxMethodIds=publicMethodIds, 
                                                                language=language)
            finalMethodDict.update(result)

        for privateMethodId in privateMethodIds:
            privateMethod = SharedMethodWrapper.PRIVATE_METHODS.get(privateMethodId)
            if privateMethod is not None:
                privateMethod["kbxMethodLabel"] = str(privateMethod["kbxMethodLabel"])
                finalMethodDict[privateMethodId] = privateMethod
            else:
                finalMethodDict[privateMethodId] = None
                
        return finalMethodDict
예제 #35
0
    def update_shared_method(
            self,
            kbxMethodName,
            kbxGroupId=None,
            kbxMethodFunc=SharedMethod.get_empty_placeholder(),
            kbxMethodIsPrivate=SharedMethod.get_empty_placeholder(),
            kbxMethodLabel=SharedMethod.get_empty_placeholder(),
            kbxMethodDesc=SharedMethod.get_empty_placeholder(),
            kbxMethodTag=SharedMethod.get_empty_placeholder(),
            kbxMethodParams=SharedMethod.get_empty_placeholder(),
            **kbxMethodProps):
        '''
        Update registered shared method by method properties.

        Params:
        kbxMethodName:Integer - [Required] Method name.
        kbxGroupId:Integer - [Required] Method group id.
        kbxModuleName:String - [Required] Module name.
        kbxMethodLabel:String - [Optional] New labe for the method.
        kbxMethodDesc:String - [Optional] New description of the method.
        kbxMethodTag:List<String> - [Optional] New method tags.
        kbxMethodParams:List<KBXParam> - [Optional] New method params.
        '''
        pass
예제 #36
0
 def get_pyapi(self, request):
     pyapi = SharedMethod.get_pyapi()
     returnData = {}
     returnData["pyapi"] = pyapi
     self.send_response(returnData, request.requestId)
예제 #37
0
 def update_shared_method(self, kbxMethodName, kbxGroupId=None, kbxMethodFunc=SharedMethod.get_empty_placeholder(), kbxMethodIsPrivate=SharedMethod.get_empty_placeholder(),
                          kbxMethodLabel=SharedMethod.get_empty_placeholder(), kbxMethodDesc=SharedMethod.get_empty_placeholder(),
                          kbxMethodTag=SharedMethod.get_empty_placeholder(), kbxMethodParams=SharedMethod.get_empty_placeholder(), **kbxMethodProps):
     pass