Skip to content

Commit

Permalink
Add CloudRequest example #541
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Oct 9, 2024
1 parent 7d8922e commit c51b4c3
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/cloudrequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# TinyTuya Example
# -*- coding: utf-8 -*-
"""
TinyTuya - CloudRequest
This examples uses the Tinytuya Cloud class and the cloudrequest function
to access the Tuya Cloud to control a door lock.
Author: Jason A. Cox
For more information see https://github.com/jasonacox/tinytuya
"""
import tinytuya

# Turn on Debug Mode
tinytuya.set_debug(True)

# You can have tinytuya pull the API credentials
# from the tinytuya.json file created by the wizard
# c = tinytuya.Cloud()
# Alternatively you can specify those values here:
# Connect to Tuya Cloud
c = tinytuya.Cloud(
apiRegion="us",
apiKey="xxxxxxxxxxxxxxxxxxxx",
apiSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
apiDeviceID="xxxxxxxxxxxxxxxxxxID")

# Example: Door Lock
device_id = "xxxxxxxxxxxxxxxxxxID"

# Get a password ticket
ticket = c.cloudrequest( f'/v1.0/smart-lock/devices/{device_id}/password-ticket' )

# Unlock the door
unlock = c.cloudrequest( f'/v1.1/devices/{device_id}/door-lock/password-free/open-door',
post={'ticket_id': ticket} )

0 comments on commit c51b4c3

Please sign in to comment.