Skip to content

Commit 443e9c8

Browse files
authored
Merge pull request #587 from uzlonewolf/bcast-err-msg
Add better error message when sending scanner broadcasts fails
2 parents 5acd134 + c70e3a5 commit 443e9c8

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

RELEASE.md

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

3+
## v1.16.1 - Scanner Error Handling
4+
5+
* Adds error handling for cases when the scanner broadcasts fails by @x011 in https://github.com/jasonacox/tinytuya/pull/585 and @uzlonewolf in https://github.com/jasonacox/tinytuya/pull/587
6+
37
## v1.16.0 - Code Refactoring
48

59
* This update refactors core.py by splitting it up into smaller, more logical files. It puts it in a `core` directory, so existing code that imports from `tinytuya.core` should be unaffected.

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, 0)
87+
version_tuple = (1, 16, 1)
8888
version = __version__ = "%d.%d.%d" % version_tuple
8989
__author__ = "jasonacox"
9090

tinytuya/scanner.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ def send_discovery_request( iface_list=None ):
213213
addr = client_bcast_addrs[bcast]
214214
iface_list[addr] = { 'broadcast': bcast }
215215

216+
at_least_one_succeeded = False
217+
bcast_error_messages = []
216218
for address in iface_list:
217219
iface = iface_list[address]
218220
if 'socket' not in iface:
@@ -233,17 +235,23 @@ def send_discovery_request( iface_list=None ):
233235
iface['port'] = 7000
234236

235237
log.debug( 'Sending discovery broadcast from %r to %r on port %r', address, iface['broadcast'], iface['port'] )
236-
# the official app always sends it twice, so do the same
237238
try:
238239
iface['socket'].sendto( iface['payload'], (iface['broadcast'], iface['port']) )
239-
iface['socket'].sendto( iface['payload'], (iface['broadcast'], iface['port']) )
240+
at_least_one_succeeded = True
240241
except socket.error as e:
241-
log.error(f"Failed to send discovery broadcast to {iface['broadcast']}:{iface['port']}: {e}")
242+
log.debug( f"Failed to send discovery broadcast from {address} to {iface['broadcast']}:{iface['port']}: {e}" )
243+
bcast_error_messages.append( f"Failed to send discovery broadcast from {address} to {iface['broadcast']}:{iface['port']}: {e}" )
242244

243245
if close_sockets:
244246
iface['socket'].close()
245247
del iface['socket']
246248

249+
if not at_least_one_succeeded:
250+
if log.level != logging.DEBUG:
251+
for line in bcast_error_messages:
252+
log.error( line )
253+
log.error( 'Sending broadcast discovery packet failed, certain v3.5 devices will not be found!' )
254+
247255
class KeyObj(object):
248256
def __init__( self, gwId, key ):
249257
self.gwId = gwId

0 commit comments

Comments
 (0)