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})
Example #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))
Example #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})
Example #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
 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})
Example #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})
Example #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)
Example #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)
    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
    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
    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
Example #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
    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
Example #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)
    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
Example #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)
Example #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
Example #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
Example #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
 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)
 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)
Example #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
    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)
    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)
Example #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
Example #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))
 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)
Example #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)
Example #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()
Example #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()
Example #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
Example #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
Example #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)
    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
Example #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
Example #36
0
 def get_pyapi(self, request):
     pyapi = SharedMethod.get_pyapi()
     returnData = {}
     returnData["pyapi"] = pyapi
     self.send_response(returnData, request.requestId)
Example #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