-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework device finding for auto-IP detection, and unpack_message() retcode fix #186
Conversation
…by IP instead of dev_id
# Enable UDP listening broadcasting mode on UDP port 6666 - 3.1 Devices | ||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | ||
client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | ||
client.bind(("", UDPPORT)) |
Check warning
Code scanning / CodeQL
Binding a socket to all network interfaces
# Enable UDP listening broadcasting mode on encrypted UDP port 6667 - 3.3 Devices | ||
clients = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | ||
clients.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | ||
clients.bind(("", UDPPORTS)) |
Check warning
Code scanning / CodeQL
Binding a socket to all network interfaces
Thanks @uzlonewolf ! I don't know why the commit was showing multiple core.py replacements, but I reviewed the final deltas and it looks good. More importantly, it works GREAT! Thank you! ❤️ >>> tinytuya.find_device('0123456789abcdef0123')
('10.0.3.3', '3.3', '0123456789abcdef0123')
>>> tinytuya.find_device(address='10.0.3.3')
('10.0.3.3', '3.3', '0123456789abcdef0123') >>> d = tinytuya.OutletDevice('0123456789abcdef0123', 'Auto', '0123456789abcdef')
>>> d
('0123456789abcdef0123', '10.0.3.3')
>>> d.status()
{'devId': '0123456789abcdef0123', 'dps': {'1': False, '101': 0}} |
It's showing core.py as replaced because I used a different text editor for part of it and it converted all the line endings from \r\n to just \n without telling me, so I then had to commit it again with that fixed. |
Update find() to use
select.select()
instead of a fixed wait so it processes broadcast packets as they come in. It was also moved out of XenonDevice and renamed to find_device() so you can use it without creating a device. It can also be used with an IP address instead of a device ID if you want to find out what device is at a certain IP (not sure why I added this one, this is getting into scanner territory).I also noticed
unpack_message()
was returning alist
(instead of theint
it should be) if a packet retcode is processed, so that is now fixed. I don't think anything in tinytuya ever uses the retcode, but my scanner uses it to help detect brute-force failures.