Add OPNSense device tracker#26834
Conversation
| "pyopnsense==0.2.0" | ||
| ], | ||
| "dependencies": [], | ||
| "codeowners": [] |
There was a problem hiding this comment.
Please add yourself as code owner.
There was a problem hiding this comment.
Oh, I just assumed I didn't need to because I'm not listed as a codeowner on any of the components I've contributed in the past. Figured it was a requirement. Fixed in: 914fce5
|
It looks like the linter job failed because of a network issue trying to talk to pypi: https://dev.azure.com/home-assistant/Home%20Assistant/_build/results?buildId=10835&view=logs&j=4e214fed-f310-53fa-0018-b38e7beb405b&t=065ca18d-6864-5af3-aac6-258b23c5c37b&l=87 |
| ) | ||
| try: | ||
| interfaces_client.get_arp() | ||
| except Exception: # pylint: disable=broad-except |
There was a problem hiding this comment.
Please catch a specific exception raised by the library on credentials or connection failure.
It's good if the library raises different exceptions for different type of problems.
There was a problem hiding this comment.
It depends on the failure mode, the library will raise a pyopnsense.exceptions.APIException if the api returns an error, because of invalid credentials for example. But if there is a connection issue or something else that happens at a lower level like requests or urllib3 that will get raised verbatim. Which is why I used a broad catch here. It seemed like it would be better to catch any exception and log it rather than raise an unhandled exception from a lower layer.
There was a problem hiding this comment.
Preferably the library should catch RequestException and raise a library specific error.
|
If we need the library in the tests we need to add the library to the list in |
|
Hi @mtreinish! Looks like this PR is pretty close to the finish 🥇 At this point, I would recommend rebasing the PR onto the latest dev branch, regenerate the requirements, and go from there. Looking forward to it! 👍 |
|
Hello @mtreinish the failed tests seem to be unrelated to this PR, that is why I would recommend you to rebase onto the latest dev branch again. This way the tests have to rerun and hopefully pass 😅 so this can be finally merged ✌ |
87ebf81 to
baf01a1
Compare
This commit adds a new component for using an OPNSense router as a device tracker. It uses pyopnsense to query the api to look at the arptable for a list of devices on the network.
Co-Authored-By: Fabian Affolter <mail@fabian-affolter.ch>
Co-Authored-By: Fabian Affolter <mail@fabian-affolter.ch>
This commit updates several issues found in the module during code review.
Co-Authored-By: Martin Hjelmare <marhje52@kth.se>
This commit fixes several issues from review comments, including abandoning all the use of async code. This also completely reworks the tests to be a bit clearer.
This commit adds actual device detection to the unit test for the setup test. A fake api response is added to mocks for both api clients so that they will register devices as expected and asserts are added for that. The pyopnsense import is moved from the module level to be runtime in the class. This was done because it was the only way to make the MockDependency() call work as expected.
This commit updates the connection logic to return false if we're unable to connect to the configured OPNsense API endpoint for any reason. Previously we would not catch if an endpoint was incorrectly configured until we first tried to use it. In this case it would raise an unhandled exception. To handle this more gracefully this adds an api call early in the setup and catches any exception raised by that so we can return False to indicate the setup failed.
baf01a1 to
5b368c6
Compare
Since opening the PR originally yet another lint/style checker was added which failed the PR in CI. This commit makes the adjustments to have this pass the additional tool's checks.
This commit adds documentation for the opnsense device tracker which is being added in home-assistant/core#26834.
Description:
This commit adds a new component for using an OPNSense router as a
device tracker. It uses pyopnsense to query the api to look at the
arptable for a list of devices on the network.
Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#10427
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest.requirements_all.txtby runningpython3 -m script.gen_requirements_all..coveragerc.