Skip to main content

Tuya Cloud Client package based on http-API for Tuya IoT Development Platform

Project description

Tuya Cloud Client

Tuya Cloud Client Python package based on http-API for Tuya IoT Development Platform. TuyaCloudClient provides full fuctionality for remote manipulation with Tuya IoT platform based smart devices.

Overview

Tuya Cloud Client implies quick client functionality for an easy interaction with Tuya services. Most suitable for building software with Tuya API integrated services.

Major fuctionality of Tuya Cloud Client package is based on two classes: TuyaCloudClient & TuyaCloudClientNicer. TuyaCloudClientNicer is an extension over TuyaCloudClient. It provides just the same methods, but brings more significant data in responses, cleaned from meta. Usage of TuyaCloudClientNicer class is preferable for the most cases.

Functionality

Intuitive functional interface of a service object

  • get_user_homes()
  • get_user_devices()
  • get_device_information(device_id:uuid)
  • get_device_details(device_id:uuid)
  • get_device_functions(device_id:uuid)
  • get_device_specifications(device_id:uuid)
  • get_device_status(device_id:uuid)
  • get_device_logs(device_id:uuid)
  • get_home_data(home_id:int)
  • get_home_rooms(home_id:int)
  • get_home_devices(home_id:int)
  • get_home_members(home_id:int)
  • get_room_devices(home_id:int, room_id:int)
  • get_category_list()
  • get_category_instruction(category:str)
  • exec_device_command(device_id:uuid, commands:JSON)

Installation

pip install tuyacloud

Getting started

OOP based package

Initiation of an object

tcc = tuyacloud.TuyaCloudClientNicer(
    ACCESS_ID       = 'XXXXXXXXXXXXXX',
    ACCESS_SECRET   = 'XXXXXXXXXXXXXX',
    UID             = 'XXXXXXXXXXXXXX',
    ENDPOINT_URL    = 'XXXXXXXXXXXXXX'
)

Credentials ACCESS_ID, ACCESS_SECRET, UID could be claimed at iot.tuya.com. ENDPOINT_URL is to be chosen by user from

List of tuya endpoints:

Availability zone	Endpoint
America	            openapi.tuyaus.com
China	            openapi.tuyacn.com
Europe	            openapi.tuyaeu.com
India	            openapi.tuyain.com
Eastern America	    openapi-ueaz.tuyaus.com
Western Europe	    openapi-weaz.tuyaeu.com

Getting data from tuya endpoint, example

Call methods

homes = tcc.get_user_homes()
print(homes)

Get response

[
    {
        "geo_name": "Hong-Kong, Main str. 2716",
        "home_id": 1490003,
        "lat": 00.460004060004,
        "lon": 00.219918549988,
        "name": "Bachelor Condo",
        "role": "OWNER"
    },
    ...
]

Execute command over device, example

Call methods

device_uuid = "3217xxxxxxxxxxx"
commands = []
commands.append({
    "code": "switch_led_1",
    "value": True
})
exec_result = tcc.exec_device_command(device_uuid, {"commands": commands})
print(exec_result)

Get response

{
    "result": True,
    "success": True,
    "t": 1676636545787,
    "tid": "bcc21939aebd11ed838e2a0aa76353ad"
}

Use built-in logger functionality, example

You may capture debug, error messages by capture default logs by its id 'tuyacloud.TuyaCloudClient' like so

def setup_logger():
    logger_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    logger_file_handler = logging.handlers.RotatingFileHandler('tuyacloud.log', maxBytes=51200, backupCount=2)
    logger_file_handler.setLevel(logging.DEBUG)
    logger_file_handler.setFormatter(logger_formatter)
    logger_tuya_cloud_client = logging.getLogger('tuyacloud.TuyaCloudClient')
    logger_tuya_cloud_client.setLevel(logging.DEBUG)
    logger_tuya_cloud_client.addHandler(logger_file_handler)
    logger_tuya_cloud_client.info("script started")
setup_logger()

Links

For more info see github.com/mrtxee/tuyacloud

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tuyacloud-1.0.tar.gz (164.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tuyacloud-1.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file tuyacloud-1.0.tar.gz.

File metadata

  • Download URL: tuyacloud-1.0.tar.gz
  • Upload date:
  • Size: 164.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for tuyacloud-1.0.tar.gz
Algorithm Hash digest
SHA256 5fdf5677865572dd732ac33c2cea1810f0bdb81a1206d7616a681b9b48d02fdd
MD5 d054fa11e46ea729f8f9d7e911aa85f4
BLAKE2b-256 bb102c2eaff5387a34ded4c8ac5d5284320c6a02cceba1733a199583e84a7e84

See more details on using hashes here.

File details

Details for the file tuyacloud-1.0-py3-none-any.whl.

File metadata

  • Download URL: tuyacloud-1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for tuyacloud-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cdf601c688b726234f469174d3123dd6f9a886dd178ac06e2085ce556511d13
MD5 1d0556f015659d2baee9d2172b36a52c
BLAKE2b-256 1bd266f0c8031e1c37e8108a20b1f3899d9f7f4347737d57fd5505ac633db805

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page