tinytuya.XenonDevice

class tinytuya.XenonDevice(dev_id, address=None, local_key='', dev_type='default', connection_timeout=5, version=3.1, persist=False, cid=None, node_id=None, parent=None, connection_retry_limit=5, connection_retry_delay=5, port=6668, max_simultaneous_dps=0)

Bases: object

Low-level functions for devices.

Deprecated since version 1.x: Use tinytuya.Device instead.

Removed in version 2.0.

Methods provided by this class

__init__(dev_id[, address, local_key, ...])

Represents a Tuya device.

add_dps_to_request(dp_indicies)

Add a datapoint (DP) to be included in requests.

cache_clear()

cached_status([historic, nowait])

Return device last status if a persistent connection is open.

close()

detect_available_dps()

Return which datapoints are supported by the device.

find(did)

Mainly here for backwards compatibility.

generate_payload(command[, data, gwId, ...])

Generate the payload to send.

receive()

Poll device to read any payload in the buffer.

send(payload)

Send single buffer payload.

set_dpsUsed(dps_to_request)

set_retry(retry)

set_sendWait(s)

set_socketNODELAY(nodelay)

set_socketPersistent(persist)

set_socketRetryDelay(delay)

set_socketRetryLimit(limit)

set_socketTimeout(s)

set_version(version)

status([nowait])

Return device status.

subdev_query([nowait])

Query for a list of sub-devices and their status

Methods inherited from parent class

__init__(dev_id, address=None, local_key='', dev_type='default', connection_timeout=5, version=3.1, persist=False, cid=None, node_id=None, parent=None, connection_retry_limit=5, connection_retry_delay=5, port=6668, max_simultaneous_dps=0)

Represents a Tuya device.

Parameters:

dev_id (str) – The device id.

Keyword Arguments:
  • address (str, optional) – The network address.

  • local_key (str, optional) – The encryption key. Defaults to None.

  • cid (str, optional) – Optional sub-device id. Default to None.

  • node_id (str, optional) – alias for cid

  • parent (XenonDevice, optional) – gateway device this device is a child of

port

The port to connect to.

Type:

int

add_dps_to_request(dp_indicies)

Add a datapoint (DP) to be included in requests.

cache_clear()
cached_status(historic=False, nowait=False)

Return device last status if a persistent connection is open.

Parameters:

nowait (bool) – If cached status is is not available, either call status() (when nowait=False) or immediately return None (when nowait=True)

Response:
json if cache is available, else

json from status() if nowait=False, or None if nowait=True

close()
detect_available_dps()

Return which datapoints are supported by the device.

static find(did)

Mainly here for backwards compatibility. Calling tinytuya.find_device() directly is recommended.

Parameters:

for (did = The specific Device ID you are looking)

Response:

(ip, version)

generate_payload(command, data=None, gwId=None, devId=None, uid=None, rawData=None, reqType=None)

Generate the payload to send.

Parameters:
  • command (str) – The type of command. This is one of the entries from payload_dict

  • data (dict, optional) – The data to send. This is what will be passed via the ‘dps’ entry

  • gwId (str, optional) – Will be used for gwId

  • devId (str, optional) – Will be used for devId

  • uid (str, optional) – Will be used for uid

receive()

Poll device to read any payload in the buffer. Timeout results in None returned.

send(payload)

Send single buffer payload.

Parameters:

payload (bytes) – Data to send.

set_dpsUsed(dps_to_request)
set_retry(retry)
set_sendWait(s)
set_socketNODELAY(nodelay)
set_socketPersistent(persist)
set_socketRetryDelay(delay)
set_socketRetryLimit(limit)
set_socketTimeout(s)
set_version(version)
status(nowait=False)

Return device status.

subdev_query(nowait=False)

Query for a list of sub-devices and their status