VirtualDevice

public protocol VirtualDevice : AbstractVirtualDevice

VirtualDevice for a device-client adds methods to handle write-only and executable actions.

  • Set callback for handling an action

    Throws

    ClientError.argument if actionName is not an action on the model.

    • deprecated: This API does not support actions with multiple arguments Use setOnAction.

    Declaration

    Swift

    func setOnCall(actionName: String,
                   callback: ((VirtualDevice, Any?)->())?) throws

    Parameters

    actionName

    The action name

    callback

    The function to invoke

  • Set a callback that is invoked when an action for the given actionName is received.

    Note that it is possible to set a callback for a specific action and to set a callback for all actions via setOnAction. If there is a callback for the specific action and for all actions, both callbacks will be invoked, with the specific action invoked first.

    See setOnAction

    Declaration

    Swift

    func setOnAction(actionName: String, callback: ((ActionEvent) -> ())?) throws

    Parameters

    actionName

    The action name from the device model

    callback

    a callback to invoke when an action is received, if nil, the existing callback will be removed

  • Set a callback that is invoked when any action in the device model is received.

    Note that it is possible to set a callback for a specific action via setOnAction. If there is a callback for the specific action and for all actions, both callbacks will be invoked, wiht the specific action invoked first.

    Ssee setOnAction

    Declaration

    Swift

    func setOnAction(callback: ((ActionEvent) -> ())?) throws

    Parameters

    callback

    a callback to invoke when an action is received, if nil, the existing callback will be removed

  • Create a custom data object for this VirtualDevice. The custom data object will be created with the given format URN.

    Throws

    ClientError.argument if a device model format cannot be obtained from format or if the format type is not DeviceModelFormatType.DATA

    Declaration

    Swift

    func createData(format: String) throws -> Data

    Parameters

    format

    the custom data message format URN.

    Return Value

    a Data object

  • Create an Alert for this VirtualDevice. The alert will be created with the given format URN.

    Throws

    ClientError.argument if a device model format cannot be obtained from alertUrn or if the format is not DeviceModelFormatType.ALERT

    Declaration

    Swift

    func createAlert(format: String) throws -> Alert

    Parameters

    format

    the alert format URN.

    Return Value

    an Alert object

  • Offer to set the value of an attribute. The attribute value is set depending upon any policy that may have been configured for the attribute. If there is no policy for the given attribute, offer behaves as if the AbstractVirtualDevice.set(attributeName:attributeValue) method were called. The value is validated according to the constraints in the device model. If the value is not valid, a ClientError.argument exception is raised.

    Throws

    ClientError.argument if the value is not valid, the attribute is not in the model, attributeName is nil, or if the attribute is read-only

    Declaration

    Swift

    func offer(attributeName: String, attributeValue: AnyObject) throws -> VirtualDevice

    Parameters

    attributeName

    the name of an attribute from the device type model

    attributeValue

    the value to set

    Return Value

    this VirtualDevice instance