tinytuya.CoverDevice

class tinytuya.CoverDevice(*args, **kwargs)

Bases: Device

Represents a Tuya based Smart Window Cover.

Supports 8 different command types with automatic detection.

Methods provided by this class

__init__(*args, **kwargs)

Represents a Tuya device.

close_cover([switch, nowait])

Close the cover.

continue_cover([switch, nowait])

Continue the cover motion (if supported).

open_cover([switch, nowait])

Open the cover.

set_cover_type(cover_type)

Manually set the cover device type.

stop_cover([switch, nowait])

Stop the cover motion.

Methods inherited from parent class

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.

heartbeat([nowait])

Send a keep-alive HEART_BEAT command to keep the TCP connection open.

product()

Request AP_CONFIG Product Info from device.

receive()

Poll device to read any payload in the buffer.

send(payload)

Send single buffer payload.

set_dpsUsed(dps_to_request)

set_multiple_values(data[, nowait])

Set multiple indexes at the same time

set_retry(retry)

set_sendWait(s)

set_socketNODELAY(nodelay)

set_socketPersistent(persist)

set_socketRetryDelay(delay)

set_socketRetryLimit(limit)

set_socketTimeout(s)

set_status(on[, switch, nowait])

Set status of the device to 'on' or 'off'.

set_timer(num_secs[, dps_id, nowait])

Set a timer.

set_value(index, value[, nowait])

Set int value of any index.

set_version(version)

status([nowait])

Return device status.

subdev_query([nowait])

Query for a list of sub-devices and their status

turn_off([switch, nowait])

Turn the device off

turn_on([switch, nowait])

Turn the device on

updatedps([index, nowait])

Request device to update index.

Attributes

COVER_TYPES

Cover type command mappings

DEFAULT_COVER_TYPE

DPS_2_STATE

DPS_INDEX_BL

DPS_INDEX_MOVE

__init__(*args, **kwargs)

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()
close_cover(switch=None, nowait=False)

Close the cover.

Parameters:
  • switch (str/int) – The DPS index. Defaults to DPS_INDEX_MOVE.

  • nowait (bool) – Don’t wait for device response.

continue_cover(switch=None, nowait=False)

Continue the cover motion (if supported).

Parameters:
  • switch (str/int) – The DPS index. Defaults to DPS_INDEX_MOVE.

  • nowait (bool) – Don’t wait for device response.

Note

Only Type 1 and Type 4 support the continue command.

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

heartbeat(nowait=True)

Send a keep-alive HEART_BEAT command to keep the TCP connection open.

Devices only send an empty-payload response, so no need to wait for it.

Parameters:

nowait (bool) – True to send without waiting for response.

open_cover(switch=None, nowait=False)

Open the cover.

Parameters:
  • switch (str/int) – The DPS index. Defaults to DPS_INDEX_MOVE.

  • nowait (bool) – Don’t wait for device response.

product()

Request AP_CONFIG Product Info from device. [BETA]

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_cover_type(cover_type)

Manually set the cover device type.

Parameters:

cover_type (int) – Cover type ID (1-8).

Raises:

ValueError – If cover_type is not between 1 and 8.

Example

cover.set_cover_type(1) # Set to Type 1 (open/close/stop/continue) cover.set_cover_type(6) # Set to Type 6 (on/off/stop)

set_dpsUsed(dps_to_request)
set_multiple_values(data, nowait=False)

Set multiple indexes at the same time

Parameters:
  • data (dict) – array of index/value pairs to set

  • nowait (bool) – True to send without waiting for response.

set_retry(retry)
set_sendWait(s)
set_socketNODELAY(nodelay)
set_socketPersistent(persist)
set_socketRetryDelay(delay)
set_socketRetryLimit(limit)
set_socketTimeout(s)
set_status(on, switch=1, nowait=False)

Set status of the device to ‘on’ or ‘off’.

Parameters:
  • on (bool) – True for ‘on’, False for ‘off’.

  • switch (int) – The switch to set

  • nowait (bool) – True to send without waiting for response.

set_timer(num_secs, dps_id=0, nowait=False)

Set a timer.

Parameters:
  • num_secs (int) – Number of seconds

  • dps_id (int) – DPS Index for Timer

  • nowait (bool) – True to send without waiting for response.

set_value(index, value, nowait=False)

Set int value of any index.

Parameters:
  • index (int) – index to set

  • value (int) – new value for the index

  • nowait (bool) – True to send without waiting for response.

set_version(version)
status(nowait=False)

Return device status.

stop_cover(switch=None, nowait=False)

Stop the cover motion.

Parameters:
  • switch (str/int) – The DPS index. Defaults to DPS_INDEX_MOVE.

  • nowait (bool) – Don’t wait for device response.

Note

Not all cover types support stop. Types 2 and 5 do not have a stop command.

subdev_query(nowait=False)

Query for a list of sub-devices and their status

turn_off(switch=1, nowait=False)

Turn the device off

turn_on(switch=1, nowait=False)

Turn the device on

updatedps(index=None, nowait=False)

Request device to update index.

Parameters:
  • index (array) – list of dps to update (ex. [4, 5, 6, 18, 19, 20])

  • nowait (bool) – True to send without waiting for response.

COVER_TYPES = {}

Cover type command mappings

  • 1 - {‘open’: ‘open’, ‘close’: ‘close’, ‘stop’: ‘stop’, ‘continue’: ‘continue’, ‘detect_values’: [‘open’, ‘close’, ‘stop’, ‘continue’]}

  • 2 - {‘open’: True, ‘close’: False, ‘stop’: None, ‘continue’: None, ‘detect_values’: [True, False]}

  • 3 - {‘open’: ‘1’, ‘close’: ‘2’, ‘stop’: ‘0’, ‘continue’: None, ‘detect_values’: [‘0’, ‘1’, ‘2’]}

  • 4 - {‘open’: ‘01’, ‘close’: ‘02’, ‘stop’: ‘00’, ‘continue’: ‘03’, ‘detect_values’: [‘00’, ‘01’, ‘02’, ‘03’]}

  • 5 - {‘open’: ‘fopen’, ‘close’: ‘fclose’, ‘stop’: None, ‘continue’: None, ‘detect_values’: [‘fopen’, ‘fclose’]}

  • 6 - {‘open’: ‘on’, ‘close’: ‘off’, ‘stop’: ‘stop’, ‘continue’: None, ‘detect_values’: [‘on’, ‘off’, ‘stop’]}

  • 7 - {‘open’: ‘up’, ‘close’: ‘down’, ‘stop’: ‘stop’, ‘continue’: None, ‘detect_values’: [‘up’, ‘down’, ‘stop’]}

  • 8 - {‘open’: ‘ZZ’, ‘close’: ‘FZ’, ‘stop’: ‘STOP’, ‘continue’: None, ‘detect_values’: [‘ZZ’, ‘FZ’, ‘STOP’]}

DEFAULT_COVER_TYPE = 1
DPS_2_STATE = {}
  • 1 - ‘movement’

  • 101 - ‘backlight’

DPS_INDEX_BL = '101'
DPS_INDEX_MOVE = '1'