Skip to content

Commit 775ba05

Browse files
committed
Protocol 3.4 and 3.5 support
1 parent 3a713d6 commit 775ba05

File tree

7 files changed

+72
-21
lines changed

7 files changed

+72
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Pulling data from Tuya devices on your network requires that you have the Device
3333
1. Download the "Smart Life" - Smart Living app for iPhone or Android. Pair with your smart plug (this is important as you cannot monitor a plug that has not been paired).
3434
* https://itunes.apple.com/us/app/smart-life-smart-living/id1115101477?mt=8
3535
* https://play.google.com/store/apps/details?id=com.tuya.smartlife&hl=en
36-
2. For Device IP, ID and VERSION: Run the tuyapower scan to get a list of Tuya devices on your network along with their device IP, ID and VERSION number (3.1 or 3.3):
36+
2. For Device IP, ID and VERSION: Run the tuyapower scan to get a list of Tuya devices on your network along with their device IP, ID and VERSION number (3.1 to 3.5 - most are 3.3):
3737
```bash
3838
python3 -m tuyapower
3939
```
@@ -100,7 +100,7 @@ Notes:
100100
* PLUGID = Device ID e.g. 01234567891234567890
101101
* PLUGIP = Device IP Address e.g. 10.0.1.99
102102
* PLUGKEY = Device Key e.g. 0123456789abcdef
103-
* PLUGVERS = Version of Protocol 3.1 or 3.3
103+
* PLUGVERS = Version of Protocol 3.1, 3.2, 3.3, 3.4 or 3.5
104104
* verbose = Print more details - True or False (default is False)
105105
* max_retries = Number of times to retry scan of new devices (default is 15)
106106

RELEASE.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# RELEASE NOTES
2+
3+
## v0.2.0 - New Tuya Device Support
4+
5+
* PyPI 0.2.0
6+
* Add support for Tuya protocols 3.2, 3.4 and 3.5 devices
7+
8+
## v0.1.0
9+
10+
* PyPI 0.1.0
11+
* Added support for multi-switch devices
12+
* Update to use tinytuya in Docker by @stevoh6 in #16
13+
* Added err variable to output by @gamuama in #23
14+
15+
## v0.0.25
16+
17+
* Bug fix in deviceRaw() not honoring timeout settings
18+
* Set sw response variable to False as default
19+
20+
## v0.0.24
21+
22+
* deviceInfo() - Added better error handling for devices without expect outlet/power data in their dps response.
23+
* deviceRaw() - Added new function to return raw device data response.
24+
* test.py & plugpower.py - Updated to add device raw data to output.
25+
26+
## v0.0.23 - TinyTuya
27+
28+
* Added support to use tinytuya, replacing pytuya:
29+
* dds support for Device IDs that are 22 characters long (pytuya only supports 20)
30+
* Removed misleading productKey (product SKU identity, not local Key) from scan() output
31+
* Attempts to import tinytuya but falls back to pytuya if unavailable
32+
33+
## v0.0.22 - Scan Max Retry Option
34+
35+
* Added option to allow users to specify maximum retries for scan functions:
36+
37+
```bash
38+
# specify 50 retries via command line
39+
python3 -m tuyapower 50
40+
```
41+
42+
```python
43+
# invoke verbose interactive scan
44+
tuyapower.scan(50)
45+
46+
# return payload of devices
47+
devices = tuyapower.deviceScan(false, 50)
48+
```
49+

plugjson.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
print("Usage: %s <PLUGID> <PLUGIP> <PLUGKEY> <PLUGVERS>\n" % sys.argv[0])
1818
print(" Required: <PLUGID> is the Device ID e.g. 01234567891234567890")
1919
print(" <PLUGIP> is the IP address of the smart plug e.g. 10.0.1.99")
20-
print(" Optional: <PLUGKEY> is the Device Keyy (default 0123456789abcdef)")
21-
print(" <PLUGVERS> is the Firmware Version 3.1 (defualt) or 3.3\n")
20+
print(" Optional: <PLUGKEY> is the Device Key (default 0123456789abcdef)")
21+
print(" <PLUGVERS> is the Firmware Version 3.1 (default), 3.2, 3.3, 3.4 or 3.5\n")
2222
print(" Note: You may also send values via Environmental variables: ")
2323
print(" PLUGID, PLUGIP, PLUGKEY, PLUGVERS\n")
2424
exit()

plugpower.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
print(" Required: <PLUGID> is the Device ID e.g. 01234567891234567890")
1919
print(" <PLUGIP> is the IP address of the smart plug e.g. 10.0.1.99")
2020
print(" Optional: <PLUGKEY> is the Device Key (default 0123456789abcdef)")
21-
print(" <PLUGVERS> is the Firmware Version 3.1 (default) or 3.3\n")
21+
print(" <PLUGVERS> is the Firmware Version 3.1 (default), 3.2, 3.3, 3.4 or 3.5\n")
2222
print(" Note: You may also send values via Environmental variables: ")
2323
print(" PLUGID, PLUGIP, PLUGKEY, PLUGVERS\n")
2424
exit()

test-json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
print("Usage: %s <PLUGID> <PLUGIP> <PLUGKEY> <PLUGVERS>\n" % sys.argv[0])
1818
print(" Required: <PLUGID> is the Device ID e.g. 01234567891234567890")
1919
print(" <PLUGIP> is the IP address of the smart plug e.g. 10.0.1.99")
20-
print(" Optional: <PLUGKEY> is the Device Keyy (default 0123456789abcdef)")
21-
print(" <PLUGVERS> is the Firmware Version 3.1 (defualt) or 3.3\n")
20+
print(" Optional: <PLUGKEY> is the Device Key (default 0123456789abcdef)")
21+
print(" <PLUGVERS> is the Firmware Version (default), 3.2, 3.3, 3.4 or 3.5\n")
2222
print(" Note: You may also send values via Environmental variables: ")
2323
print(" PLUGID, PLUGIP, PLUGKEY, PLUGVERS\n")
2424
exit()

test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
print(" Required: <PLUGID> is the Device ID e.g. 01234567891234567890")
1919
print(" <PLUGIP> is the IP address of the smart plug e.g. 10.0.1.99")
2020
print(" Optional: <PLUGKEY> is the Device Key (default 0123456789abcdef)")
21-
print(" <PLUGVERS> is the Firmware Version 3.1 (default) or 3.3\n")
21+
print(" <PLUGVERS> is the Firmware Version 3.1 (default), 3.2, 3.3, 3.4 or 3.5\n")
2222
print(" Note: You may also send values via Environmental variables: ")
2323
print(" PLUGID, PLUGIP, PLUGKEY, PLUGVERS\n")
2424
exit()

tuyapower/__init__.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
id = Device ID e.g. 01234567891234567890
1919
ip = Device IP Address e.g. 10.0.1.99
2020
key = Device Key e.g. 0123456789abcdef
21-
vers = Version of Protocol 3.1 or 3.3
21+
vers = Version of Protocol 3.1, 3.2, 3.3, 3.4 and 3.5
2222
verbose = True or False (print output)
2323
port = UDP port to scan (default 6666)
2424
@@ -55,7 +55,7 @@
5555
api_ver = "unknown"
5656

5757
name = "tuyapower"
58-
version_tuple = (0, 1, 0)
58+
version_tuple = (0, 2, 0)
5959
version = version_string = __version__ = "%d.%d.%d" % version_tuple
6060
__author__ = "jasonacox"
6161

@@ -88,7 +88,7 @@ def deviceInfo(deviceid, ip, key, vers):
8888
id = Device ID e.g. 01234567891234567890
8989
ip = Device IP Address e.g. 10.0.1.99
9090
key = Device Key e.g. 0123456789abcdef
91-
vers = Version of Protocol 3.1 or 3.3
91+
vers = Version of Protocol 3.1, 3.2, 3.3, 3.4 and 3.5
9292
9393
Response :
9494
on = Switch state - true or false
@@ -107,8 +107,9 @@ def deviceInfo(deviceid, ip, key, vers):
107107
d = tinytuya.OutletDevice(deviceid, ip, key)
108108
else:
109109
d = pytuya.OutletDevice(deviceid, ip, key)
110-
if vers == "3.3":
111-
d.set_version(3.3)
110+
if float(vers) > 3.3:
111+
return (sw, w, mA, V, "Unsupported Version: Use tinytuya")
112+
d.set_version(float(vers))
112113

113114
try:
114115
data = d.status()
@@ -151,7 +152,7 @@ def deviceInfo(deviceid, ip, key, vers):
151152
if e in dps.keys():
152153
swDict[e] = dps[e]
153154
sw = swDict
154-
# Check for power data - DP 19 on some 3.1/3.3 devices
155+
# Check for power data - DP 19 on some devices
155156
if "19" in dps.keys():
156157
w = float(dps["19"]) / 10.0
157158
mA = float(dps["18"])
@@ -202,7 +203,7 @@ def deviceRaw(deviceid, ip, key, vers):
202203
id = Device ID e.g. 01234567891234567890
203204
ip = Device IP Address e.g. 10.0.1.99
204205
key = Device Key e.g. 0123456789abcdef
205-
vers = Version of Protocol 3.1 or 3.3
206+
vers = Version of Protocol 3.1, 3.2, 3.3, 3.4 and 3.5
206207
207208
Response :
208209
rawData = Data response from device
@@ -214,9 +215,10 @@ def deviceRaw(deviceid, ip, key, vers):
214215
d = tinytuya.OutletDevice(deviceid, ip, key)
215216
else:
216217
d = pytuya.OutletDevice(deviceid, ip, key)
218+
if float(vers) > 3.3:
219+
return ("ERROR: Unsupported Version: Use tinytuya")
217220

218-
if vers == "3.3":
219-
d.set_version(3.3)
221+
d.set_version(float(vers))
220222

221223
try:
222224
data = d.status()
@@ -256,7 +258,7 @@ def devicePrint(deviceid, ip, key='0123456789abcdef', vers='3.1'):
256258
id = Device ID e.g. 01234567891234567890
257259
ip = Device IP Address e.g. 10.0.1.99
258260
key = Device Key e.g. 0123456789abcdef
259-
vers = Version of Protocol 3.1 or 3.3
261+
vers = Version of Protocol 3.1, 3.2, 3.3, 3.4 and 3.5
260262
261263
"""
262264
# Poll Smart Switch for Power Data
@@ -295,7 +297,7 @@ def deviceJSON(deviceid, ip, key='0123456789abcdef', vers='3.1'):
295297
id = Device ID e.g. 01234567891234567890
296298
ip = Device IP Address e.g. 10.0.1.99
297299
key = Device Key e.g. 0123456789abcdef
298-
vers = Version of Protocol 3.1 or 3.3
300+
vers = Version of Protocol 3.1, 3.2, 3.3, 3.4 and 3.5
299301
300302
Response:
301303
JSON String
@@ -319,7 +321,7 @@ def deviceJSON(deviceid, ip, key='0123456789abcdef', vers='3.1'):
319321
MAXCOUNT = 15 # How many tries before stopping
320322
DEBUG = False # Additional details beyond verbose
321323
UDPPORT = 6666 # Tuya 3.1 UDP Port
322-
UDPPORTS = 6667 # Tuya 3.3 encrypted UDP Port
324+
UDPPORTS = 6667 # Tuya 3.3+ encrypted UDP Port
323325
TIMEOUT = 3.0 # Seconds to wait for a broadcast
324326

325327
# Return positive number or zero
@@ -374,7 +376,7 @@ def deviceScan(verbose = False,maxretry = MAXCOUNT):
374376
client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
375377
client.bind(("", UDPPORT))
376378
client.settimeout(TIMEOUT)
377-
# Enable UDP lisenting broadcasting mode on encrypted UDP port 6667 - 3.3 Devices
379+
# Enable UDP lisenting broadcasting mode on encrypted UDP port 6667 - 3.3+ Devices
378380
clients = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
379381
clients.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
380382
clients.bind(("", UDPPORTS))

0 commit comments

Comments
 (0)