iotcs.client.device.device module¶
-
class
iotcs.client.device.device.
Alert
¶ Bases:
abc.ABC
An Alert to be sent to the server.
The alert is sent by calling the
raise_()
method. The time of the alert is set whenraise_()
is called, allowingraise_()
to be called more than once.The
set()
method returns theAlert
instance to allow the fields of the alert to be set in fluent style. Seeiotcs.client.device.VirtualDevice.createAlert()
-
raise_
()¶ Send the alert. The event time is set when this method is called.
The onError handler of the parent virtual device will be called if there is error sending the alert.
All fields defined in the format that are “optional”, True must be set before calling
raise_()
. Ifraise_()
is called before setting all “optional” True fields, IllegalStateException is raised.Raises: ValueError – if raise_()
is called if the alert message cannot be queued before setting all “optional”, True fields
-
set
(field, value)¶ Set the value of a field in the Alert.
The fields are determined by the format given when the Alert is created. The value is validated according to the constraints in the format. If the value is not valid, an IllegalArgumentException is raised.
All fields defined in the format that are ‘optional”, True must be set before calling
raise_()
.:param field the name of a field from the alert format :param value the value to set :return: this Alert instance :raises ValueError: if the value is not valid, or field is None See
iotcs.client.device.VirtualDevice.createAlert()
-
-
class
iotcs.client.device.device.
AlertImpl
(virtualDevice, alertUrn, deviceModel=None, msgDispatcher=None, endpointId=None)¶ Bases:
iotcs.client.device.device.Alert
Create an AlertImpl instance.
Parameters: - virtualDevice – the virtual device creating this Alert, must not be None
- alertUrn – the alert format urn, must not be None
Raises: ArgumentException
if a required argument is not set-
static
getDeviceModelFormat
(virtualDevice, alertUrn)¶
-
raise_
()¶ Raise an alert. :raises:
StateException
if a non optional field’s valueis not set
-
set
(fieldName, value)¶ Parameters: - fieldName –
- value –
Raises: ArgumentException
if fieldName is None, fieldName’s type is not aDeviceModelAttribute.Type
,Returns: this Alert
-
class
iotcs.client.device.device.
Data
¶ Bases:
abc.ABC
Represents a set of custom data fields.
The custom data fields are key, value pairs to be sent to the server. The custom data is sent by calling the
submit()
method. The time of the data fields are set whensubmit()
is called, allowingsubmit()
to be called more than once.The
set()
method returns the Data instance to allow fields of data to be set in fluent style. Seeiotcs.client.device.VirtualDevice.createData()
-
set
(field, value)¶ Set the value of a field in the Data.
The fields are determined by the format given when the Data is created. The value is validated according to the constraints in the format. If the value is not valid, an IllegalArgumentException is raised.
All fields defined in the format that are “optional” : false must be set before calling
submit()
.See
iotcs.client.device.VirtualDevice.createData()
Parameters: - field – the name of a field from the custom data format
- value – the value to set
Returns: this
Data
instanceRaises: ValueError – if the value is not valid, or field is None
-
submit
()¶ Submit the data.
The event time is set when this method is called. The onError handler of the parent virtual device will be called if there is error submiting the custom data fields. See
iotcs.client.device.VirtualDevice.setOnError()
All fields defined in the format that are “optional” : false must be set before calling
submit()
. If submit is called before setting all non optional fields, an IllegalStateException is raised.Raises: ValueError – if submit is called before setting all optional fields
-
-
class
iotcs.client.device.device.
DataImpl
(virtualDevice, dataUrn)¶ Bases:
iotcs.client.device.device.Data
# TODO: inherit doc ?
Parameters: - virtualDevice – the iotcs.client.device.VirtualDevice that owns the data
- dataUrn – the iotcs.client.DeviceModelFormat urn
Raises: ArgumentException
if dataUrn does not identify a known DeviceModelFormat-
dataUrn
¶
-
deviceModelFormat
¶
-
fieldValues
¶
-
set
(fieldName, value)¶ Parameters: - fieldName –
- value –
Returns: this
DataImpl
instanceRaises: ArgumentException
if there is a type mismatch, between fieldName and value, fieldName is None or if fieldName’s type is not aDeviceModelAttribute.Type
-
submit
()¶ Raises: StateException
if a non optional field’s value is not set
-
virtualDevice
¶
-
class
iotcs.client.device.device.
DirectlyConnectedDevice
(path=None, passphrase=None, dcdImpl=None)¶ Bases:
iotcs.client.client.Client
A DirectlyConnnectedDevice can send and receive messages.
A DirectlyConnectedDevice sends and receives messages to and from an IoT server. The directly-connected device is assigned an activation identifier when the device is registered on the server. When the directly-connected device is activated, the server assigns an endpoint identifer that is used by the DirectlyConnectedDevice for sending messages to, and receiving messages from, the server.
See
activate()
,getEndpointId()
Create a DirectlyConnectedDevice instance.
Load the device configuration from the given path and passphrase. See Configuration for details.
Parameters: - path – configFilePath the path of the configuration file
- passphrase – configFilePassword the configuration file password, or None if the configurationFile is not encrypted
Raises: ValueError – if the configuration could not be loaded, or the server scheme is not supported.
-
activate
(deviceModels)¶ Activate the device.
The device will be activated on the server if necessary. When the device is activated on the server, the server assigns an endpoint identifier to the device.
If the device is already activated, this method will raise an IllegalArgumentException. The user should call the
isActivated()
method prior to calling activate.Parameters: deviceModels – should contain the device model type URNs of this directlyconnected device. The device is activated with the given device models. The deviceModels parameter is zero or more, comma separated, device model URNs. Raises: ValueError – if there is an I/O exception, when key or signature algorithm class cannot be loaded, or the key is not in the trusted assets store, or the private key is invalid or if the device has already been activated See
isActivated()
-
close
()¶ Close the directly connected device and its resources.
Raises: IOEerror – if an I/O error occurs
-
createStorageObject
(name, contentType)¶ Create a new StorageObject.
The created storage object that will have a name with the given object name prefixed with the device’s endpoint ID and a directory separator. The prefix addition can be disabled by setting the
config
property disable_storage_object_prefix in section media_storage to True.if contentType is None, the mime-type defaults to application/octet-stream.
:param name the unique name to be used to reference the content in storage :param contentType The mime-type of the content or None :return a
StorageObject <.messaging.client.device.StorageObjectDelegate
# noqa: E501 :raises TransportError: if exception raised by the runtime, or an abnormal response from the storage cloud :raises SecurityException: if there is an exception establishing a secure connection to the storage cloud
-
createVirtualDevice
(endpointId, deviceModel)¶ Create a
iotlic.clien.device.VirtualDevice
instance.The virtual device is created with the given device model and given device identifier.
This method creates a new
iotcs.client.device.VirtualDevice
instance for the given parameters. The client library does not cache previously created VirtualDevice objects.Parameters: - endpointId – The device identifier of the device being modeled
- deviceModel – The device model URN that this device implements
Raises: ValueError – if the device does not implement the model, if deviceId or deviceModel are None
Returns: a new VirtualDevice
-
getDeviceModel
(urn)¶ Get the DeviceModel for the device model URN.
This method may return None if there is no device model for the URN. None may also be returned if the device model is a “draft” and the property allow_draft_device_models is set to False, which is the default.
Parameters: urn – the URN of the device model Returns: A representation of the device model iotcs.client.DeviceModel
or None if it does not existRaises: ValueError – if deviceModel is None, if there is an I/O error when communicating with the server or when key or signature algorithm class cannot be loaded, or the key is not in the trusted assets store, or the private key is invalid
-
getEndpointId
()¶ Return the endpoint identifier of this directly connected device.
The endpoint identifier is assigned by the server as part of the activation process.
Returns: the endpoint identifier of this directly-connected device. See
activate()
-
isActivated
()¶ Return True if the device has been activated.
Returns: True if activated else False
-
class
iotcs.client.device.device.
GatewayDevice
(path, passphrase)¶ Bases:
iotcs.client.device.device.DirectlyConnectedDevice
A GatewayDevice is a directly connected device.
A GatewayDevice differs from other directly connected devices in that it is capable of registering indirectly connected devices and proxies messages for indirectly connected devices.
Create a GatewayDevice instance.
The device configuration is loaded from the given file path and passphrase. See Configuration for details.
Parameters: - path – the path of the configuration file
- passphrase – the configuration file passphrase, or None if the configurationFile is not encrypted
Raises: ValueError – if the configuration file could not be loaded
-
DEVICE_CLASS
= 'deviceClass'¶ The deviceClass attribute. This attribute is to be used when setting the deviceClass value in the meta-data.
-
MANUFACTURER
= 'manufacturer'¶ The manufacturer attribute. This attribute is to be used when setting the manufacturer value in the meta-data.
-
MODEL_NUMBER
= 'modelNumber'¶ The modelNumber attribute. This attribute is to be used when setting the modelNumber value in the meta-data.
-
PROTOCOL
= 'protocol'¶ The protocol attribute. This attribute is to be used when setting the protocol value in the meta-data.
-
PROTOCOL_DEVICE_CLASS
= 'protocolDeviceClass'¶ The protocolDeviceClass attribute. This attribute is to be used when setting the protocolDeviceClass value in the meta-data.
-
PROTOCOL_DEVICE_ID
= 'protocolDeviceId'¶ The protocolDeviceId attribute. This attribute is to be used when setting the protocolDeviceId value in the meta-data.
-
SERIAL_NUMBER
= 'serialNumber'¶ The serialNumber attribute. This attribute is to be used when setting the serialNumber value in the meta-data.
-
registerDevice
(hardwareId, metaData, deviceModels, restricted=True)¶ Register an indirectly-connected device with the cloud service.
The restricted parameter controls whether or not the client library is required to supply credentials for activating the indirectly-connected device. The client library will always supply credentials for an indirectly-connected device whose trusted assets have been provisioned to the client. If however, the trusted assets of the indirectly-connected device have not been provisioned to the client, the client library can create credentials that attempt to restrict the indirectly connected device to this gateway device.
If the restricted parameter is True the indirectly-connected device cannot be activated by this gateway device without presenting credentials. If restricted is True, the client library will provide credentials to the server. The server will reject the activation request if the indirectly connected device is not allowed to roam to this gateway device.
If the restricted parameter is False the indirectly-connected can be activated without presenting credentials if the trusted assets of the indirectly-connected device have not been provisioned to the client. If restricted is False, the client library will provide credentials if, and only if, the credentials have been provisioned to the client. The server will reject the activation if credentials are required but not supplied, or if the provisioned credentials do not allow the indirectly connected device to roam to this gateway device.
The hardwareId is a unique identifier within the cloud service instance and may not be None. If one is not present for the device, it should be generated based on other metadata such as, model niumber, manufacturer, serial number, etc.
The metaData dict() should typically contain all the standard metadata (the constants documented in this class) along with any other vendor defined metadata.
Parameters: - restricted – indicate whether or not credentials are required for activating the indirectly connected device
- hardwareId – an identifier unique within the Cloud Service instance
- metaData – The metadata of the device
- deviceModels – should contain the device model type URNs supported by the indirectly connected device. The deviceModels parameter is one or more, comma separated, device model URNs.
Returns: The endpoint id of the indirectly-connected device
Raises: - IOError – if the message could not be sent
- ValueError – when key or signature algorithm class cannot be loaded, or the key is not in the trusted assets store, or the private key is invalid or if hardwareId is null, or deviceModels is null or zero length
-
class
iotcs.client.device.device.
VirtualDevice
¶ Bases:
iotcs.client.client.AbstractVirtualDevice
The VirtualDevice to represent a device-client.
The VirtualDevice provides methods to handle write-only and executable actions.
-
class
ActionCallback
¶ Bases:
abc.ABC
A callback interface for receiving notification of a
DeviceModelAction
.-
onAction
(actionEvent)¶ Called to perform a
DeviceModelAction
action.Parameters: actionEvent – the ActionEvent
-
-
class
ActionEvent
¶ Bases:
iotcs.client.client.Event
An
Event
class that is passed toActionCallback
callbacks.-
getName
()¶ Return the action name. :return: the action name
-
-
class
Callable
¶ Bases:
abc.ABC
Callback interface for device model actions.
This class is implemented to handle
iotcs.client.device.DeviceModel
actions. :deprecated:-
call
(virtualDevice, data)¶ Handle a device model action.
For an execute action the client library will pass None as the data parameter. For a write-only action, the type of data should match the expected data type of the action.
Parameters: - virtualDevice – the
iotcs.client.device.VirtualDevice
on which the action is being invoked - data – the data or None
- virtualDevice – the
-
-
createAlert
(alertformaturn)¶ Create an Alert for this VirtualDevice.
The alert will be created with the given format URN. :param alertformaturn: the alert format URN. :return: an iotcs.client.Device.Alert
-
createData
(messageformaturn)¶ Create a custom data object for this VirtualDevice.
The custom data object will be created with the given message format URN. :param messageformaturn: the custom data message format URN. :return: a custom data object
iotcs.client.device.Data
-
offer
(attributeName, value)¶ 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(String, Object) method were called. The value is validated according to the constraints in the device model. If the value is not valid, an IllegalArgumentException is raised. :param attributeName: the name of an attribute from the device type model :param value: the value to set :return: this VirtualDevice instance :raises ArgumentException: if the value is not valid, the attribute is not in the model, or attributeName is None
-
setCallable
(actionName, callable)¶ Set a
Callable
instance for handling an action, actionName.Parameters: - actionName – The action name
- callable – The
Callbable
instance to invoke
Deprecated:
-
setOnAction
(callback, actionName=None)¶ Set a callback for a specific action or all actions.
If actionName is None, callback is invoked any all requested actions. If actionName is not `None then callback is invoked for that specific actionName
If there is a callback for a specific action and for all actions, both callbacks will be invoked, with the specific action invoked first. :param actionName: The action name from the device model, or None :param callback: the
ActionCallback
that is inkoked. If None an existing callback is removed.
-
class
-
class
iotcs.client.device.device.
VirtualDeviceBase
(adapter, endpointId, deviceModel)¶ Bases:
object
Implementation of VirtualDevice.
Create a
VirtualDeviceBase
instance.:param adapter the device or enterprise specific implementation of the Adapter interface :param endpointId: the server’s endpoint id for the device :param deviceModel: the device model the device implements
-
class
Adapter
¶ Bases:
abc.ABC
An interface for adapting to the device or enterprise client.
Different implementations of the virtual device interfaces
AbstractVirtualDevice
are required for device clients and enterprise clients.-
getAttribute
(name)¶ Return a :class:.`VirtualDeviceAttribute` instance.
The virtual device attribute is appropriate for either the enterprise or device client. :param name: the name of the attribute :return: The VirtualDeviceAttribute for the given name
-
setValue
(deviceAttribute, value)¶ Set the the value for attribute.
For enterprise client make a resource request to set the the attribute. For device client calls the attribute’s set method. Invokes the on error handlers on error. :param deviceAttribute: the device attribute name :param value: the device attribute value
-
updateFields
(updatedAttributes)¶ Set all the attributes in an update batch.
Errors are handled in the set call, including calling the on error handler. :param updatedAttributes: The attributes modified during an update
-
-
class
ChangeEvent
(virtualDevice, value)¶ Bases:
iotcs.client.client.ChangeEvent
An event that describes a change to the virtual device.
Create a
ChangeEvent
instance.Parameters: - virtualDevice – a
VirtualDevice
instance - value – the
NamedValue
related to this change
-
getNamedValue
()¶ Return the
NamedValue
instance.
-
getVirtualDevice
()¶ Return the
VirtualDevice
instance.
-
value
¶
-
virtualDevice
¶
- virtualDevice – a
-
class
ErrorEvent
(virtualDevice, value, message)¶ Bases:
iotcs.client.client.ErrorEvent
An event that describes an error.
Create a
VirtualDeviceBase
instance.Parameters: - virtualDevice – a
VirtualDevice
instance - value – the
NamedValue
related to this error - message – the error event message
-
getMessage
()¶ Return the error message.
-
getNamedValue
()¶ Return the
NamedValue
instance.
-
getVirtualDevice
()¶ Return the
VirtualDevice
instance.
-
message
¶
-
value
¶
-
virtualDevice
¶
- virtualDevice – a
-
class
NamedValueImpl
(name, value)¶ Bases:
iotcs.client.client.NamedValue
The implementation of
AbstractVirtualDevice.NamedValue
.Create a
NamedValue
instance.Parameters: - name – the name of the value
- value – the value
-
getName
()¶ Return the value name.
-
getValue
()¶ Return the value.
-
next
()¶ Return the next
NamedValue
instance.
-
setNext
(next)¶ Set the next
NamedValue
instance.
-
SYNC_LOCK
¶
-
UPDATE_LOCK
¶
-
adapter
¶
-
changeCallback
¶
-
deviceModel
¶
-
endpointId
¶
-
errorCallback
¶
-
getDeviceModel
()¶ Return the
DeviceModel
instance for the virtual device.
-
getEndpointId
()¶ Return the device client identifier.
-
getOnChangeCallback
()¶ Return the
ChangeCallback
callback instance or None.See
AbstractVirtualDevice.ChangeCallback
:return: theChangeCallback
callback instance or None
-
getOnErrorCallback
()¶ Return the
ErrorCallback
callback instance or None.See
AbstractVirtualDevice.ErrorCallback
:return: theErrorCallback
instance or None
-
isUpdateMode
()¶ Return True if the device is in update mode.
Returns: True if in update mode else False
-
set
(attributeName, value)¶ Set the value of attributeName to value.
If
isUpdateMode()
is True, set the value on the instance, and do not send any messages or change events. IfisUpdateMode()
is False, set the value and send messages and change events. :param attributeName: the name of the attibutes to change :param value: the new attribute value.
-
setOnChange
(callback)¶ Set the
ChangeCallback
callback instance.See
AbstractVirtualDevice.ChangeCallback
:param callback: aChangeCallback
instance or None :return:
-
setOnError
(callback)¶ Set the
ErrorCallback
callback instance.See
AbstractVirtualDevice.ErrorCallback
:param callback: aErrorCallback
instance or None :return:
-
update
()¶ Open an update transaction.
-
updateMode
¶
-
updateSetField
(attribute, value)¶ Add attribute attribute to the set of attributes for batch update.
Parameters: - attribute – the attribute being set
- value – the attribute value
-
updatedAttributes
¶
-
class
-
class
iotcs.client.device.device.
VirtualDeviceImpl
(dcd, endpointId, deviceModel)¶ Bases:
iotcs.client.device.device.VirtualDevice
,iotcs.client.device.device.Adapter
,iotcs.messaging.client.device.util.RequestHandler
,iotcs.messaging.client.device.policy.DeviceAnalog
,iotcs.messaging.client.device.policy.ChangeListener
-
class
ErrorCallbackBridge
¶ Bases:
iotcs.client.device.util.ErrorCallback
The default implementation of iotcs.device.MessageDispatcher.ErrorCallback that is called when there are errors sending messages to the IOT Cloud Service. Used for all virtual device instances
-
add
(virtualDevice)¶ Add virtualDevice to the list of devices to dispatch errors to. :param virtualDevice: iotcs.device.impl.VirtualDeviceImpl
-
deviceSet
¶
-
failed
(messages, exception)¶ Called when iotcs.device.MessageDispatcher.send fails to send messages. :param messages: The list of messages that could not be sent :param exception: The Exception that causes the send failure
-
invokeErrorCallback
(virtualDevice, messages, exception)¶ Parameters: - virtualDevice – VirtualDeviceImpl
- messages – List<Message>
- exception – Exception
-
-
addScheduledPolicy
(window, slide, timeZero, attributeName, pipelineIndex)¶ Add a
ScheduledPolicyData
to__scheduledPolicies
.Start the :class;`.TimedPolicyThread` if it is not running. :param window: :param slide: :param timeZero: :param attributeName: :param pipelineIndex: :return:
-
call
(actionName, args)¶ Parameters: - actionName –
- args – single argument or list of args
-
callImpl
(actionName, argumentValues)¶ Invoke an action callback.
Parameters: - actionName – the name of the action from the device model
- argumentValues – a map of argument names to values
Returns: a success or failure
StatusCode
code
-
checkComputedMetrics
(updatedAttributes)¶ Parameters: updatedAttributes – Returns:
-
createAlert
(format)¶ Create an Alert for this VirtualDevice.
The alert will be created with the given format URN. :param alertformaturn: the alert format URN. :return: an iotcs.client.Device.Alert
-
createData
(format)¶ Create a custom data object for this VirtualDevice.
The custom data object will be created with the given message format URN. :param messageformaturn: the custom data message format URN. :return: a custom data object
iotcs.client.device.Data
-
class
errorNotifyThread
(errorCallback, event, msg)¶ Bases:
threading.Thread
-
cb
¶
-
ev
¶
-
msg
¶
-
run
()¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
-
finish
()¶ Send the values in an update transaction to the server.
The
update()
method must have been called before calling finish. The update transaction mark is cleared.See
update()
-
get
(attributeName)¶ Return the value of attributeName.
This method returns the current value held by the virtual device model and no call is made to the physical device.
Parameters: attributeName – the name of an attribute from the device type model Returns: the attribute value Raises: ValueError – if attributeName is not in the model, or attributeName is None
-
getAttribute
(attributeName)¶ VirtualDeviceBase.Adapter API {@inheritDoc} :param attributeName: :return: the VirtualDeviceAttributeBase attribute for attributeName :raises:
ArgumentException
if attributeName is not anattribute in the model.
-
getAttributeValue
(attribute)¶ Parameters: attribute – Returns:
-
getDeviceModel
()¶ Return the
DeviceModel
instance for this device object.Returns: the device model DeviceModel
-
static
getDeviceModelAction
(deviceModel, actionName)¶
-
getEndpointId
()¶ Return the endpoint id of the device.
The endpoint id is the identifier that the server creates when a registered device is activated.
Returns: the device’s endpoint id
-
getErrorCallback
()¶
-
getLastKnown
(attributeName)¶ Return the last known value of attributeName.
The last known value is always the same as the current value. The last known value is maintained by the
AbstractVirtualDevice
instance. No REST API call is made to the server.Parameters: attributeName – the name of an attribute from the device type model Returns: the attribute value Raises: ValueError – if attributeName is not in the model, or attributeName is None
-
getPipelineData
(attribute)¶ Return device policy pipeline data for attribute else [] :param attribute: device model attribute name :return: device policy pipeline data for attribute else []
-
getValue
(attributeType, payload, name)¶ Parameters: - attributeType – DeviceModelAttribute.Type
- payload – bytearray
Raises: ValueError –
-
handlePatch
(requestMessage)¶ A ‘PATCH’ request is a multi attribute change request :param requestMessage: iotcs.shared.message.RequestMessage identifies the attributes to be changed :return: iotcs.shared.message.StatusCode
-
handlePost
(requestMessage)¶
-
handlePut
(requestMessage)¶
-
handleRequest
(requestMessage)¶ Dispatch the request message to the appropriate handler for the method
Parameters: requestMessage – request for device Returns: ResponseMessage
-
handleStorageObjectStateChange
(storageObject)¶ Parameters: storageObject – iotcs.client.device.StorageObjectImpl
-
notifyException
(attributes, e)¶
-
offer
(attributeName, value)¶ Parameters: - attributeName –
- value –
Returns:
-
offer0
(attribute, value, pipeline, pipelineData)¶
-
policyAssigned
(policy, assignedDevices)¶ Parameters: - policy –
- assignedDevices –
Returns:
-
policyUnassigned
(devicePolicy, unassignedDevices)¶ Parameters: - devicePolicy –
- unassignedDevices –
Returns:
-
processExpiredFunction
(updatedAttributes, attributeName, pipeline, pipelineData)¶ Invoke policy functions on attributeName as necessary.
Routine for handling invocation of a policy function when the window’s slide expires. This routine gets the value of the function, and then processes the remaining functions in the pipeline (if any).
Parameters: - updatedAttributes –
- attributeName –
- pipeline –
- pipelineData –
Returns:
-
processOnChange
(virtualDeviceAttribute, newValue)¶
-
queueMessage
(message, storageObjects=None)¶ Parameters: - message –
- storageObjects – list of
client.device.StorageObectImpl
Returns:
-
removeScheduledPolicy
(slide, attributeName, pipelineIndex, window)¶ Remove a
ScheduledPoiicyDate
from__scheduledPolicies
.Parameters: - slide –
- attributeName –
- pipelineIndex –
- window –
Returns:
-
set
(attributeName, value)¶ Set the value of attributeName to value.
This method is used by the application to synchronize the
AbstractVirtualDevice
state with the physical device and results in an endpointDATA
message REST API call to the server.value is validated according to the constraints in the
DeviceModel
. If value is not valid, a ValueError exception is raised.Parameters: - attributeName – the name of an attribute from the device type model
- value – the value to set
Returns: this AbstractVirtualDevice instance
Raises: ValueError – if value is not valid, attributeName is not in the model, or attributeName is None. or if attributeName is not writable.
-
setAttributeValue
(attribute, value)¶ Parameters: - attribute –
- value –
Returns:
-
setCallable
(actionName, callable)¶ Set a
Callable
instance for handling an action, actionName.Parameters: - actionName – The action name
- callable – The
Callbable
instance to invoke
Deprecated:
-
setOnAction
(actionCallback, actionName=None)¶ Set a callback for a specific action or all actions.
If actionName is None, callback is invoked any all requested actions. If actionName is not `None then callback is invoked for that specific actionName
If there is a callback for a specific action and for all actions, both callbacks will be invoked, with the specific action invoked first. :param actionName: The action name from the device model, or None :param callback: the
ActionCallback
that is inkoked. If None an existing callback is removed.
-
setOnChange
(callback, attributeName=None)¶ Set a
ChangeCallback
instance.If attributeName is None, callback is invoked when the value of any attribute changes.
If attributeName is not None, callback is invoked when the value of attributeName changes.
If callback is None, the callback instance is removed and no callback is invoked for attribute value changes.
Parameters: - attributeName – the name of an attribute from the device model
- callback – a
ChangeCallback
instance
Raises: ValueError – if attributeName is not in the model, or attributeName is None
-
setOnError
(callback, attributeName=None)¶ Set a
ErrorCallback
instance.If attributeName is None, callback is invoked if an error occurs when setting any attribute or an error occurs when raising an
Alert
.If attributeName is not None, callback is invoked if an error occurs when setting the value for attributeName or an error occurs when raising an
Alert
.If callback is None, the callback instance is removed and no callback is invoked if an error occurs.
Parameters: - attributeName – the name of an attribute from the device model
- callback – a
ErrorCallback
instance
Raises: ValueError – if attributeName is not in the model, or attributeName is None
-
setValue
(attribute, value)¶ VirtualDeviceBase.Adapter API.
#{@inheritDoc} :param attribute: VirtualDeviceAttributeBase :param value: obejct :raises:
ArgumentException
if attribute is None
-
update
()¶ Set a mark for beginning an update transaction.
If the update method had not been called and there is no open update transaction, calls to
set()
sends the new value to the server. The update method opens an update transaction and future calls toset()
do not immediatelly send the new value to the server, but accumulates the changes to be sent in one call to the server.The accumulated changes in an open update transaction are sent to the server when the
finish()
method is called.finish()
sends the updated values to the server and closes the open update transaction.For example:
virtualDevice.update().set("min", 10).set("max", 20).finish()
See
finish()
Returns: this AbstractVirtualDevice instance
-
updateFields
(updatedAttributes)¶ Set all the attributes in an update batch. Errors are handled in the set call, including calling the on error handler. {@inheritDoc} :param updatedAttributes: List<Pair<VirtualDeviceAttributeBase<VirtualDevice, Object>, Object>>
-
class