def ReadPropertyToResultElement(obj, propertyIdentifier, propertyArrayIndex=None):
    """Read the specified property of the object, with the optional array index,
    and cast the result into an Any object."""
    if _debug: ReadPropertyToResultElement._debug("ReadPropertyToResultElement %s %r %r", obj, propertyIdentifier, propertyArrayIndex)

    # save the result in the property value
    read_result = ReadAccessResultElementChoice()

    try:
        read_result.propertyValue = ReadPropertyToAny(obj, propertyIdentifier, propertyArrayIndex)
        if _debug: ReadPropertyToResultElement._debug("    - success")
    except PropertyError as error:
        if _debug: ReadPropertyToResultElement._debug("    - error: %r", error)
        read_result.propertyAccessError = ErrorType(errorClass='property', errorCode='unknownProperty')
    except ExecutionError as error:
        if _debug: ReadPropertyToResultElement._debug("    - error: %r", error)
        read_result.propertyAccessError = ErrorType(errorClass=error.errorClass, errorCode=error.errorCode)

    # make an element for this value
    read_access_result_element = ReadAccessResultElement(
        propertyIdentifier=propertyIdentifier,
        propertyArrayIndex=propertyArrayIndex,
        readResult=read_result,
        )
    if _debug: ReadPropertyToResultElement._debug("    - read_access_result_element: %r", read_access_result_element)

    # fini
    return read_access_result_element
Ejemplo n.º 2
0
    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 ReadPropertyToResultElement(obj, propertyIdentifier, propertyArrayIndex=None):
    """Read the specified property of the object, with the optional array index,
    and cast the result into an Any object."""
    if _debug: ReadPropertyToResultElement._debug("ReadPropertyToResultElement %s %r %r", obj, propertyIdentifier, propertyArrayIndex)

    # save the result in the property value
    read_result = ReadAccessResultElementChoice()

    try:
        read_result.propertyValue = ReadPropertyToAny(obj, propertyIdentifier, propertyArrayIndex)
        if _debug: ReadPropertyToResultElement._debug("    - success")
    except PropertyError, error:
        if _debug: ReadPropertyToResultElement._debug("    - error: %r", error)
        read_result.propertyAccessError = ErrorType(errorClass='property', errorCode='unknownProperty')
def ReadPropertyToResultElement(obj,
                                propertyIdentifier,
                                propertyArrayIndex=None):
    """Read the specified property of the object, with the optional array index,
    and cast the result into an Any object."""
    if _debug:
        ReadPropertyToResultElement._debug(
            "ReadPropertyToResultElement %s %r %r", obj, propertyIdentifier,
            propertyArrayIndex)

    # save the result in the property value
    read_result = ReadAccessResultElementChoice()

    try:
        read_result.propertyValue = ReadPropertyToAny(obj, propertyIdentifier,
                                                      propertyArrayIndex)
        if _debug: ReadPropertyToResultElement._debug("    - success")
    except PropertyError as error:
        if _debug: ReadPropertyToResultElement._debug("    - error: %r", error)
        read_result.propertyAccessError = ErrorType(
            errorClass='property', errorCode='unknownProperty')
    except ExecutionError as error:
        if _debug: ReadPropertyToResultElement._debug("    - error: %r", error)
        read_result.propertyAccessError = ErrorType(
            errorClass=error.errorClass, errorCode=error.errorCode)

    # make an element for this value
    read_access_result_element = ReadAccessResultElement(
        propertyIdentifier=propertyIdentifier,
        propertyArrayIndex=propertyArrayIndex,
        readResult=read_result,
    )
    if _debug:
        ReadPropertyToResultElement._debug(
            "    - read_access_result_element: %r", read_access_result_element)

    # fini
    return read_access_result_element
Ejemplo n.º 5
0
def property_to_result(obj, prop_id, prop_index=None):
    """
    This function creates an appropriate ReadAccessResultElement.

    :param obj: object
    :param prop_id: property id
    :param prop_index: property array index
    :return: ReadAccessResultElement instance
    """
    self = property_to_result

    self._debug(
        'ReadPropertyToResultElement %s %r %r',
        obj,
        prop_id,
        prop_index,
    )

    # create read result
    read_result = ReadAccessResultElementChoice()

    # check if object exists
    if obj is None:
        # set access error
        read_result.propertyAccessError = ErrorType(
            errorClass='object',
            errorCode='unknownObject'
        )

        self._debug('   - error: object does not exist',)

    else:
        try:
            # set property value
            read_result.propertyValue = read_property_any(
                obj,
                prop_id,
                prop_index,
            )

            self._debug('   - success')

        except PropertyError as error:
            # set access error
            read_result.propertyAccessError = ErrorType(
                errorClass='property',
                errorCode='unknownProperty'
            )

            self._debug('   - error: %r', error)

        except ExecutionError as error:
            # set access error
            read_result.propertyAccessError = ErrorType(
                errorClass=error.errorClass,
                errorCode=error.errorCode
            )

            self._debug('   - error: %r', error)

    # create result element
    result_element = ReadAccessResultElement(
        propertyIdentifier=prop_id,
        propertyArrayIndex=prop_index,
        readResult=read_result,
    )

    # return result element
    return result_element