Skip to content

Commit 3fa3870

Browse files
authored
Merge pull request #609 from jasonacox/v1.16.3
Add cloud error handling and server recovery logic
2 parents 1130950 + bd8408b commit 3fa3870

6 files changed

Lines changed: 18 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,4 @@ mappings.json
129129

130130
# test scripts
131131
server/r
132+
server/tinytuya

RELEASE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# RELEASE NOTES
22

3+
## v1.16.3 - Cloud Error Handling
4+
5+
* Add error handling in Cloud getdevices() function for edge case where old devices.json has corrupt or malformed device entries.
6+
* Server p14 update: Add main loop logic to try to recover when exception occurs.
7+
38
## v1.16.2 - Invalid JSON Handling
49

510
* Handle invalid binary data in the JSON from the device better by @uzlonewolf in https://github.com/jasonacox/tinytuya/pull/607 re: #606

server/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ The UI at http://localhost:8888 allows you to view and control the devices.
113113
114114
## Release Notes
115115
116+
### p14 - Recovery Logic
117+
118+
* Add main loop logic to try to recover when exception occurs.
119+
116120
### p12 - Force Scan
117121
118122
* Added "Force Scan" button to cause server to run a network scan for devices not broadcasting.

server/server.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@
6161

6262
import tinytuya
6363
from tinytuya import scanner
64-
import os
6564

66-
BUILD = "p13"
65+
BUILD = "p14"
6766

6867
# Defaults from Environment
6968
APIPORT = int(os.getenv("APIPORT", "8888"))
@@ -103,6 +102,7 @@
103102
if len(sys.argv) > 1 and sys.argv[1].startswith("-d"):
104103
DEBUGMODE = True
105104
if DEBUGMODE:
105+
tinytuya.set_debug(True)
106106
logging.basicConfig(
107107
format="\x1b[31;1m%(levelname)s [%(asctime)s]:%(message)s\x1b[0m", level=logging.DEBUG,
108108
datefmt='%d/%b/%y %H:%M:%S'
@@ -819,9 +819,4 @@ def api(port):
819819
log.debug("Stoppping threads")
820820
requests.get('http://localhost:%d/stop' % APIPORT, timeout=5)
821821
except Exception as err:
822-
log.error(f"Error in main loop: {err}")
823-
running = False
824-
# Close down API thread
825-
print("Stopping threads...")
826-
log.debug("Stoppping threads")
827-
requests.get('http://localhost:%d/stop' % APIPORT, timeout=5)
822+
log.error("Error in main loop: %s", err)

tinytuya/Cloud.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ def getdevices(self, verbose=False, oldlist=[], include_map=False):
405405
old_devices = {}
406406
if oldlist:
407407
for dev in oldlist:
408+
# make sure dev is a dict and has an id
409+
if not isinstance( dev, dict ) or 'id' not in dev:
410+
log.warning("Skipping malformed device entry: %s", dev)
411+
continue
408412
dev_id = dev['id']
409413
old_devices[dev_id] = dev
410414

tinytuya/core/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
# Colorama terminal color capability for all platforms
8585
init()
8686

87-
version_tuple = (1, 16, 2)
87+
version_tuple = (1, 16, 3) # Major, Minor, Patch
8888
version = __version__ = "%d.%d.%d" % version_tuple
8989
__author__ = "jasonacox"
9090

0 commit comments

Comments
 (0)