Emulator

The Emulator resource can be used to interact with emulated devices. Various tasks can be performed by using the API Methods included in the class.

Each device fetched by an API Method is represented by an instance of the Device class that is returned to the user.

API Methods

disruptive.Emulator.create_device(project_id, device_type, display_name=None, labels={}, **kwargs)

Create a new emulated device with specified type and project.

Parameters:
  • project_id (str) – Unique ID of the target project.

  • device_type (str) – Specifies which device type to create.

  • display_name (str, optional) – Provides a display name to the device.

  • labels (dict[str, str], optional) – Set labels for the new device. Format: {‘key’: ‘value’}.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns:

device – Object representing the created emulated device.

Return type:

Device

Examples

>>> # Create a new emulated humidity sensor.
>>> disruptive.Emulator.create_device(
...     project_id='<PROJECT_ID>',
...     device_type=disruptive.Device.HUMIDITY,
...     display_name='new-humidity-sensor',
...     labels={
...         'room-number': '99',
...         'customer': 'x7',
...     },
... )
disruptive.Emulator.delete_device(device_id, project_id, **kwargs)

Deletes the specified emulated device.

Parameters:
  • device_id (str) – Specifies which device type to delete.

  • project_id (str) – Unique ID of the target project.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Examples

>>> # Delete an emulated device.
>>> disruptive.Emulator.delete_device('<DEVICE_ID>', '<PROJECT_ID>')
Return type:

None

disruptive.Emulator.publish_event(device_id, project_id, data, **kwargs)

From the specified device, publish an event of the given type.

Parameters:
  • device_id (str) – Unique ID of the target device.

  • project_id (str) – Unique ID of the target project.

  • data (Event Data) – An object representing the event data to be published. Can be any of the listed Event Data classes. labelsChanged is not supported when publishing emulated events. The chosen Event Data must be supported by the device.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Examples

>>> # Publish a Humidity event from an emulated device.
>>> disruptive.Emulator.publish_event(
...     device_id='<DEVICE_ID>',
...     project_id='<PROJECT_ID>',
...     data=disruptive.events.Humidity(
...         celsius=23,
...         humidity=76,
...     ),
... )