def __init__(self, *args): BIPSimpleApplication.__init__(Mock()) self.elementService = Mock() #self.ResponseQueue = Mock() #self.ResponseQueue.get.return_value = ([21, 'degreesCelcius'], Event()) iocb = IOCB() apdu = ReadPropertyMultipleACK(listOfReadAccessResults=[ ReadAccessResult( objectIdentifier=('analogValue', 1), listOfResults=[ ReadAccessResultElement( propertyIdentifier='presentValue', readResult=ReadAccessResultElementChoice( propertyValue=Any(Real(21.0)), )), ReadAccessResultElement( propertyIdentifier='units', readResult=ReadAccessResultElementChoice( propertyValue=Any(Enumerated(62)), )), ], ) ]) iocb.complete(apdu) self.request = Mock() self.request.return_value = iocb
def do_ReadPropertyMultipleRequest(self, apdu): """ This function reads all values from request. :param apdu: incoming message :return: response """ self._debug('do_ReadPropertyMultipleRequest %r', apdu) # retrieve data result_dict = __do_PropertyMultipleRequest(self, apdu, write=False) # get result list result_list = result_dict.get('result_list', []) if 'result_list' in result_dict: del result_dict['result_list'] # create acknowledgement resp = ReadPropertyMultipleACK(context=apdu) resp.listOfReadAccessResults = result_list # return response return resp
def do_ReadPropertyMultipleRequest(self, apdu): """Respond to a ReadPropertyMultiple Request.""" if _debug: ReadPropertyMultipleApplication._debug("do_ReadPropertyMultipleRequest %r", apdu) # response is a list of read access results (or an error) resp = None read_access_result_list = [] # loop through the request for read_access_spec in apdu.listOfReadAccessSpecs: # get the object identifier objectIdentifier = read_access_spec.objectIdentifier if _debug: ReadPropertyMultipleApplication._debug(" - objectIdentifier: %r", objectIdentifier) # check for wildcard if (objectIdentifier == ('device', 4194303)): if _debug: ReadPropertyMultipleApplication._debug(" - wildcard device identifier") objectIdentifier = self.localDevice.objectIdentifier # get the object obj = self.get_object_id(objectIdentifier) if _debug: ReadPropertyMultipleApplication._debug(" - object: %r", obj) # make sure it exists if not obj: resp = Error(errorClass='object', errorCode='unknownObject', context=apdu) if _debug: ReadPropertyMultipleApplication._debug(" - unknown object error: %r", resp) break # build a list of result elements read_access_result_element_list = [] # loop through the property references for prop_reference in read_access_spec.listOfPropertyReferences: # get the property identifier propertyIdentifier = prop_reference.propertyIdentifier if _debug: ReadPropertyMultipleApplication._debug(" - propertyIdentifier: %r", propertyIdentifier) # get the array index (optional) propertyArrayIndex = prop_reference.propertyArrayIndex if _debug: ReadPropertyMultipleApplication._debug(" - propertyArrayIndex: %r", propertyArrayIndex) # check for special property identifiers if propertyIdentifier in ('all', 'required', 'optional'): for propId, prop in obj._properties.items(): if _debug: ReadPropertyMultipleApplication._debug(" - checking: %r %r", propId, prop.optional) if (propertyIdentifier == 'all'): pass elif (propertyIdentifier == 'required') and (prop.optional): if _debug: ReadPropertyMultipleApplication._debug(" - not a required property") continue elif (propertyIdentifier == 'optional') and (not prop.optional): if _debug: ReadPropertyMultipleApplication._debug(" - not an optional property") continue # read the specific property read_access_result_element = ReadPropertyToResultElement(obj, propId, propertyArrayIndex) # check for undefined property if read_access_result_element.readResult.propertyAccessError \ and read_access_result_element.readResult.propertyAccessError.errorCode == 'unknownProperty': continue # add it to the list read_access_result_element_list.append(read_access_result_element) else: # read the specific property read_access_result_element = ReadPropertyToResultElement(obj, propertyIdentifier, propertyArrayIndex) # add it to the list read_access_result_element_list.append(read_access_result_element) # build a read access result read_access_result = ReadAccessResult( objectIdentifier=objectIdentifier, listOfResults=read_access_result_element_list ) if _debug: ReadPropertyMultipleApplication._debug(" - read_access_result: %r", read_access_result) # add it to the list read_access_result_list.append(read_access_result) # this is a ReadPropertyMultiple ack if not resp: resp = ReadPropertyMultipleACK(context=apdu) resp.listOfReadAccessResults = read_access_result_list if _debug: ReadPropertyMultipleApplication._debug(" - resp: %r", resp) # return the result self.response(resp)