-
Notifications
You must be signed in to change notification settings - Fork 5
Allow discovering Broadlink device at a specific IP #13
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,7 +86,7 @@ def process_response(self, req, resp, resource, req_succeeded): | |
|
|
||
| class DiscoverRESTResource(object): | ||
| def on_get(self, req, resp): | ||
| resp.body = json.dumps(blaster_db.get_new_blasters()) | ||
| resp.body = json.dumps(blaster_db.get_new_blasters(at_ip=req.get_param("at_ip", required=False))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 suggestion (security): Consider adding input validation for the 'at_ip' parameter While the 'at_ip' parameter is optional, it's important to validate it as a valid IP address when provided. This will enhance the security and reliability of the API. |
||
|
|
||
|
|
||
| # Resource to interact with all discovered Blasters | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,10 +142,18 @@ def discover_blasters(timeout): | |||||||
| ] | ||||||||
|
|
||||||||
|
|
||||||||
| def get_new_blasters(timeout=DISCOVERY_TIMEOUT): | ||||||||
| def get_new_blasters(at_ip=None, timeout=DISCOVERY_TIMEOUT): | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider adding error handling for broadlink.hello(at_ip) call The function should handle potential exceptions or errors that may occur when calling broadlink.hello(at_ip). This will improve the robustness of the code. |
||||||||
| cnt = 0 | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Remove unused variable 'cnt' The 'cnt' variable is initialized but never used. Consider removing it to improve code clarity.
Suggested change
|
||||||||
| discovered = [] | ||||||||
|
|
||||||||
| for blaster in discover_blasters(timeout=timeout): | ||||||||
| if at_ip: | ||||||||
| d = broadlink.hello(at_ip) | ||||||||
| if d: | ||||||||
| discovered.append(d) | ||||||||
| else: | ||||||||
| discovered = discover_blasters(timeout=timeout) | ||||||||
|
|
||||||||
| for blaster in discovered: | ||||||||
| mac_hex = enc_hex(blaster.mac) | ||||||||
| mac = friendly_mac_from_hex(mac_hex) | ||||||||
| check_blaster = Blaster.get_or_none( | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (documentation): Fix typo: 'top tap' should be 'top right'