Skip to content

Commit

Permalink
Merge pull request #587 from uzlonewolf/bcast-err-msg
Browse files Browse the repository at this point in the history
Add better error message when sending scanner broadcasts fails
  • Loading branch information
jasonacox authored Jan 26, 2025
2 parents 5acd134 + c70e3a5 commit 443e9c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# RELEASE NOTES

## v1.16.1 - Scanner Error Handling

* 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

## v1.16.0 - Code Refactoring

* 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.
Expand Down
2 changes: 1 addition & 1 deletion tinytuya/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
# Colorama terminal color capability for all platforms
init()

version_tuple = (1, 16, 0)
version_tuple = (1, 16, 1)
version = __version__ = "%d.%d.%d" % version_tuple
__author__ = "jasonacox"

Expand Down
14 changes: 11 additions & 3 deletions tinytuya/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def send_discovery_request( iface_list=None ):
addr = client_bcast_addrs[bcast]
iface_list[addr] = { 'broadcast': bcast }

at_least_one_succeeded = False
bcast_error_messages = []
for address in iface_list:
iface = iface_list[address]
if 'socket' not in iface:
Expand All @@ -233,17 +235,23 @@ def send_discovery_request( iface_list=None ):
iface['port'] = 7000

log.debug( 'Sending discovery broadcast from %r to %r on port %r', address, iface['broadcast'], iface['port'] )
# the official app always sends it twice, so do the same
try:
iface['socket'].sendto( iface['payload'], (iface['broadcast'], iface['port']) )
iface['socket'].sendto( iface['payload'], (iface['broadcast'], iface['port']) )
at_least_one_succeeded = True
except socket.error as e:
log.error(f"Failed to send discovery broadcast to {iface['broadcast']}:{iface['port']}: {e}")
log.debug( f"Failed to send discovery broadcast from {address} to {iface['broadcast']}:{iface['port']}: {e}" )
bcast_error_messages.append( f"Failed to send discovery broadcast from {address} to {iface['broadcast']}:{iface['port']}: {e}" )

if close_sockets:
iface['socket'].close()
del iface['socket']

if not at_least_one_succeeded:
if log.level != logging.DEBUG:
for line in bcast_error_messages:
log.error( line )
log.error( 'Sending broadcast discovery packet failed, certain v3.5 devices will not be found!' )

class KeyObj(object):
def __init__( self, gwId, key ):
self.gwId = gwId
Expand Down

0 comments on commit 443e9c8

Please sign in to comment.