Skip to content
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

Merged
merged 6 commits into from
Oct 4, 2022

Conversation

uzlonewolf
Copy link
Collaborator

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 a list (instead of the int 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.

# 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

'' binds a socket to all 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

'' binds a socket to all interfaces.
@jasonacox jasonacox merged commit 02a46df into jasonacox:master Oct 4, 2022
@jasonacox
Copy link
Owner

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}}

@uzlonewolf
Copy link
Collaborator Author

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.

@uzlonewolf uzlonewolf deleted the dev-find-ip branch October 4, 2022 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants