API¶
This part of the documentation covers all the interfaces of AllThingsTalk SDK.
Assets¶
-
class
allthingstalk.
Asset
(*, kind=’sensor’, name=None, title=None, description=”, handler=None, profile=None, **kwargs)[source]¶ -
__init__
(*, kind=’sensor’, name=None, title=None, description=”, handler=None, profile=None, **kwargs)[source]¶ References the asset identified by name. The asset is created on the platform if it doesn’t already exist. If the asset is initialized from a device class, it’s default name is set to the member name referencing it.
Parameters: - kind (str) – Asset kind: sensor, actuator, virtual or config
- name (str) – Asset’s name. If the asset is initialized from a device class, the name defaults to the name of the member referencing the asset, e.g. for
my_asset = IntegerAsset()
, the integer asset’s name will be set to'my_asset'
- title (str) – Asset’s title. By default it gets set to capitalized name.
- description (str) – Asset’s description
- profile (Profile) – Asset’s profile. For default profiles, it’s recommend to use Asset variants with preset profile, like IntegerAsset or StringAsset.
-
-
class
allthingstalk.
NumberAsset
(*, kind=’sensor’, name=None, title=None, description=”, handler=None, profile=None, **kwargs)[source]¶
-
class
allthingstalk.
IntegerAsset
(*, kind=’sensor’, name=None, title=None, description=”, handler=None, profile=None, **kwargs)[source]¶
-
class
allthingstalk.
StringAsset
(*, kind=’sensor’, name=None, title=None, description=”, handler=None, profile=None, **kwargs)[source]¶
Asset State¶
Clients¶
-
class
allthingstalk.
BaseClient
[source]¶ BaseClient is a base class used for implementing AllThingsTalk Platform clients, which are used for interfacing the SDK code with the Platform. It doesn’t implement any of the client methods.
-
class
allthingstalk.
Client
(token, *, api=’api.allthingstalk.io’, http=None, mqtt=None)[source]¶ Client is the recommended class used for connecting to AllThingsTalk Platform, that uses HTTP and MQTT in the background. By default, it connects to api.allthingstalk.io.
-
__init__
(token, *, api=’api.allthingstalk.io’, http=None, mqtt=None)[source]¶ Initializes the Client with an AllThingsTalk token, and optional endpoints.
Parameters: - token (str) – AllThingsTalk Token, e.g. a Device Token
- api (str) – AllThingsTalk API endpoint, shared by HTTP & MQTT
- http (str) – AllThingsTalk HTTP endpoint. Resolved from api by default
- mqtt (str) – AllThingsTalk MQTT endpoint. Resolved from api by default
-
create_asset
(device_id, asset)[source]¶ Creates a device asset.
Parameters: - device_id (str) – AllThingsTalk Device Identifier
- asset (Asset) – The asset
Returns: The asset
Return type:
-
get_asset_state
(device_id, asset_name)[source]¶ Low-level device asset state retrieval. Most of the time, you should be using device asset getters.
Parameters: - device_id (str) – AllThingsTalk Device Identifier
- asset_name (str) – Asset name
Returns: The Asset state
Return type:
-
get_assets
(device_id)[source]¶ Retrieves assets for the device identified by device_id.
Parameters: device_id (str) – AllThingsTalk Device Identifier Returns: Asset list returned by AllThingsTalk API. Return type: list of Asset
-
publish_asset_state
(device_id, asset_name, state)[source]¶ Low-level device asset state publishing. Most of the time, you should be using device asset setters.
Parameters: - device_id (str) – AllThingsTalk Device Identifier
- asset_name (str) – Asset name
- state (AssetState) – The asset state
-
Devices¶
-
class
allthingstalk.
Device
(*, client=None, id=None, connect=True, overwrite_assets=False, **kwargs)[source]¶ Device contains information about assets. It maps to AllThingsTalk Platform device resources.
-
__init__
(*, client=None, id=None, connect=True, overwrite_assets=False, **kwargs)[source]¶ Initializes the device
Parameters: - client (Client) – The client used to interface with the platform
- id (str) – Device resource id. If supplied, the device will be mapped to the device resource. If None, an attempt will be made to create the device.
- connect (bool) – If
True
, the device should connect to the cloud immediately. - overwrite_assets (bool) – If
True
, asset mismatch between the Platform and device definition will be resolved by configuring local assets on the Platform. IfFalse
, AssetMismatchException will be raised.
Raises: AssetMismatchException – if asset mismatch is found between the existing asset on the Platform and an asset definition, and overwrite_assets is
False
-
connect
(*, client=None, id=None, overwrite_assets=None)[source]¶ Connects to the device to AllThingsTalk Platform. The default
Client
calls this method automatically.Parameters: - client (Client) – The client used to interface with the platform
- id (str) – Device resource id. If supplied, the device will be mapped to the device resource. If None, an attempt will be made to create the device.
- overwrite_assets (bool) – If
True
, asset mismatch between the Platform and device definition will be resolved by configuring local assets on the Platform. IfFalse
, AssetMismatchException will be raised.
Raises: AssetMismatchException – if asset mismatch is found between the existing asset on the Platform and an asset definition, and overwrite_assets is
False
-