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

Update discover single to handle hostnames #539

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

sdb9696
Copy link
Collaborator

@sdb9696 sdb9696 commented Nov 1, 2023

While looking at merged PR #528 I noticed some users were using hostnames to add their devices and the current discover_single will not work with hostnames. This PR does a simple DNS lookup using getaddrinfo if a hostname is used so that it can match to the datagram response ip.

According to the getaddrinfo docs dns lookup only happens if node parameter is a hostname:

node specifies either a
numerical network address (for IPv4, numbers-and-dots notation as
supported by inet_aton(3); for IPv6, hexadecimal string format as
supported by inet_pton(3)), or a network hostname, whose network
addresses are looked up and resolved

Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Files Coverage Δ
kasa/discover.py 86.06% <93.75%> (+0.99%) ⬆️

📢 Thoughts on this report? Let us know!.

kasa/discover.py Outdated Show resolved Hide resolved
@sdb9696 sdb9696 force-pushed the do_discover_single_dns branch 2 times, most recently from ec98015 to 15b5c85 Compare November 1, 2023 16:36
@sdb9696 sdb9696 requested a review from bdraco November 1, 2023 17:27
Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never realized that this wasn't already working as initializing device instances manually just worked(tm) 👍

kasa/discover.py Outdated Show resolved Hide resolved
kasa/discover.py Outdated Show resolved Hide resolved
kasa/discover.py Show resolved Hide resolved
kasa/discover.py Show resolved Hide resolved
Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! 🥇

@rytilahti rytilahti added the enhancement New feature or request label Nov 7, 2023
@rytilahti rytilahti merged commit 2650298 into python-kasa:master Nov 7, 2023
29 checks passed
@sdb9696 sdb9696 deleted the do_discover_single_dns branch December 6, 2023 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants