iotcs.client.attributes module

class iotcs.client.attributes.VirtualDeviceAttribute

Bases: abc.ABC

VirtualDeviceAttribute is an attribute in a VirtualDevice model.

The AbstractVirtualDevice.get() and AbstractVirtualDevice`set() methods are wrappers around the VirtualDeviceAttribute instances of a VirtualDevice.

get()

Return the value of an attribute.

This method returns the current value held by the virtual device model. For an enterprise client, no REST API call is made to the server. For a device client, no call is made to the physical device. :return: the attribute value :raises: ValueError if the attribute value is not the correct return type.

getLastKnown()

Return the last known value of an attribute.

This method returns the last known value of the attribute, which is not to be interpreted as the “previous” value. For a device client, the last known value is the device value. For an enterprise client, the last known value is the last value retrieved from the server for a specific attribute, irrespective of the local ‘set’ value. :return: the last known attribute value :raises: ValueError if the attribute value is not the correct return type.

set(value)

Set the value of an attribute.

This method is used by the application to synchronize the VirtualDevice state with the physical device. This results in a REST API call to the server. For an enterprise client, an endpoint resource REST API call is made to the server. For a device client, an endpoint iotcs.shared.message.Type message REST API call is made to the server. The value is validated according to the constraints in the device model. If the value is not valid, an ValueError is raised. :param value: the value to set :raises ValueError: if the value is not valid

setOnChange(callback)

Set a ChangeCallback callback instance.

The callback is invoked when the value of an attribute changes on the remote virtual device. See AbstractVirtualDevice.setOnChange() :param callback: a ChangeCallback instance to invoke when an attribute value changes. If callback is None, the existing callback isremoved

setOnError(callback)

Set an <.AbstractVirtualDevice.ErrorCallback> instance.

The callback is invoked when there is an error in setting the value of an attribute. An error may arise because of a network exception. In addition, on an enterprise client, an error indicates that a request timed out or was rejected by the device client.

See setOnError :param callback: a ErrorCallback callback instance to invoke when there is an error. If callback is None, the existing callback is removed.

class iotcs.client.attributes.VirtualDeviceAttributeBase(virtualDevice, modelAttr)

Bases: iotcs.client.attributes.VirtualDeviceAttribute

VirtualDeviceAttributeBase is an attribute in the virtualDevice model.

It is the virtualization of DeviceModelAttribute

Create a VirtualDeviceAttributeBase instance.

get()

Return the attribute’s value.

If the attribute’s value has not been set return the DeviceModelAttribute’s default value. See iotcs.client.VirtualDeviceAttribute.get() :return: the attribute’s value or the default value.

getDeviceModelAttribute()

Return the DeviceModelAttribute instance.

getLastKnown()

Return the last known attribute value.

See iotcs.client.VirtualDeviceAttribute.getLastKnown().

getOnChange()

Return the ChangeCallback callback for this attribute.

Returns:the on change callback ChangeCallback or None
getOnError()

Return the ErrorCallback callback for this attribute.

Returns:the on error callback ErrorCallback or`None
isSettable()

Return True if the attribute value may be set.

Return True if the attribute can be set. On the device client, an attribute should always be settable. On the enterprise client, an attribute is settable if the model defines the attribute as writable. :return: True if the attribute’s value can be set

setOnChange(callback)

Assign the ChangeCallback.

See iotcs.client.VirtualDeviceAttribute.setOnChange(). :param callack: a ChangeCallbake instance, if None, the existing callback is removed.

setOnError(callback)

Assign the ErrorCallback.

See iotcs.client.VirtualDeviceAttribute.setOnError(). :param callback: a ErrorCallback instance, if None, the existing callback will be removed

update(value)

Set the attribute’s value with value.

Sets the attribute’s value but does not generate an event. :param value: the new attribute value :return: True if the value was updated

validate(attribute, value)

Validate value of DeviceModelAttribute.Type.

Ensure that the value native type is valid for the iotcs.shared.DeviceModelAttribute attribute’s iotcs.shared.DeviceModelattribute.Type. :param attribute: a DeviceModelAttribute :param value: a the attribute value :raises: ArgumentException if value is not a valid type for attribute

class iotcs.client.attributes.VirtualDeviceAttributeImpl(virtualDevice, deviceModelAttribute)

Bases: iotcs.client.attributes.VirtualDeviceAttributeBase

VirtualDeviceAttribute is an attribute in the device model.

Create a VirtualDeviceAttribute instance.

Parameters:
  • virtualDevice – the VirtualDevice with this attribute
  • deviceModelAttribute – a DeviceModelAttribute represented by this VirtualDeviceAttribute
classmethod getLogger()

Return a logger for VirtualDeviceAttributeImpl.

isSettable()

Return True if the attribute value may be set.

See VirtualDeviceAttributeBase.isSettable() :return: True if the attribute’s value can be set

set(value)

Set the value of an attribute.

See VirtualDeviceAttribute.set() :param value: the new value for the attribute

update(value)

Set the attribute’s value with value.

See VirtualDeviceAttributeBase.update() :return: True if if the value was updated.