forked from jasonacox/tinytuya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud.py
66 lines (53 loc) · 1.52 KB
/
cloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# TinyTuya Example
# -*- coding: utf-8 -*-
"""
TinyTuya - Tuya Cloud Functions
This examples uses the Tinytuya Cloud class and functions
to access the Tuya Cloud to pull device information and
control the device via the cloud.
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")
# Display list of devices
devices = c.getdevices()
print("Device List: %r" % devices)
# Select a Device ID to Test
id = "xxxxxxxxxxxxxxxxxxID"
# Display Properties of Device
result = c.getproperties(id)
print("Properties of device:\n", result)
# Display Functions of Device
result = c.getfunctions(id)
print("Functions of device:\n", result)
# Display DPS IDs of Device
result = c.getdps(id)
print("DPS IDs of device:\n", result)
# Display Status of Device
result = c.getstatus(id)
print("Status of device:\n", result)
# Send Command - This example assumes a basic switch
commands = {
'commands': [{
'code': 'switch_1',
'value': True
}, {
'code': 'countdown_1',
'value': 0
}]
}
print("Sending command...")
result = c.sendcommand(id,commands)
print("Results\n:", result)