forked from jasonacox/tinytuya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud.py
82 lines (66 loc) · 2.12 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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)
# Get device logs
# Note: the returned timestamps are unixtime*1000
# event_id 7 (data report) will probably be the most useful
# More information can be found at https://developer.tuya.com/en/docs/cloud/cbea13f274?id=Kalmcohrembze
# Get device logs from the last day
result = c.getdevicelog(id)
print("Device logs:\n", result)
# Get device logs from 7 days ago through 5 days ago (2 days worth)
#result = c.getdevicelog(id, start=-7, end=-5)
#print("Device logs:\n", result)
# Get device logs for one day ending an hour ago
#result = c.getdevicelog(id, end=time.time() - 3600)
#print("Device logs:\n", result)