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

Add Traffic Rule switches to UniFi Network #118821

Merged
merged 10 commits into from
Jul 30, 2024

Conversation

bdowden
Copy link
Contributor

@bdowden bdowden commented Jun 4, 2024

Breaking change

Proposed change

Add switch entities for unifi traffic rules. This is branched from ViViDboarder's PR with fixes and implementations for the suggestions in that PR. I know what it's like to have a newborn and how time slips away.

It's also my first PR for home assistant so suggestions/clarifications on some classes are welcome!

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @bdowden

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

home-assistant bot commented Jun 4, 2024

Hey there @Kane610, mind taking a look at this pull request as it has been labeled with an integration (unifi) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of unifi can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign unifi Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@EliSchleifer
Copy link

@bdowden - you need to sign the CLA for copyright issues before this can move forward

@bdowden
Copy link
Contributor Author

bdowden commented Jun 5, 2024

@EliSchleifer I did. When I go to the link it says no pending request.

@EliSchleifer
Copy link

EliSchleifer commented Jun 5, 2024 via email

@bdowden bdowden marked this pull request as ready for review June 5, 2024 01:12
@bdowden bdowden requested a review from Kane610 as a code owner June 5, 2024 01:12
Copy link
Member

@Kane610 Kane610 left a comment

Choose a reason for hiding this comment

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

First round of comments, I need to think about the updatecoordinator and read up on it a bit

homeassistant/components/unifi/hub/entity_loader.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/hub/hub.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/switch.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/switch.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/switch.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/switch.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/switch.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/hub/entity_loader.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft June 7, 2024 08:38
@home-assistant
Copy link

home-assistant bot commented Jun 7, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@bdowden
Copy link
Contributor Author

bdowden commented Jun 7, 2024

First round of comments, I need to think about the updatecoordinator and read up on it a bit

@Kane610 I wasn't sure about updatecoordinator either. I saw your comment in the other PR that a simple polling mechanism to get the updated status of the traffic rule would be fine and began to implement that. I saw that there was an update coordinator that did polling based on a given time so I didn't want to reinvent the wheel.

@bdowden bdowden marked this pull request as ready for review June 7, 2024 22:47
@home-assistant home-assistant bot requested a review from Kane610 June 7, 2024 22:47
Copy link
Member

@Kane610 Kane610 left a comment

Choose a reason for hiding this comment

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

I have rewritten test fixtures in the integration so you would need to adapt to the new testing style, should affect you very much. Two other minor things to correct.

homeassistant/components/unifi/switch.py Show resolved Hide resolved
homeassistant/components/unifi/hub/hub.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft June 22, 2024 11:36
@bdowden
Copy link
Contributor Author

bdowden commented Jul 13, 2024

@Kane610 Do you mind helping me out? I can't figure out how to get the traffic rule config added to the entities. I've spent far longer than I care to admit looking for the magic code and I can't find it :(

@james-fry
Copy link

Really looking forward to this, thank you for making HA better 👍

Me too - great work guys!

@Kane610
Copy link
Member

Kane610 commented Jul 21, 2024

@Kane610 Do you mind helping me out? I can't figure out how to get the traffic rule config added to the entities. I've spent far longer than I care to admit looking for the magic code and I can't find it :(

Sorry, I missed this.

Run only the traffic rule test and do some printing in the entity_loader should give you everything you need

…e appended to support v2 api requests

Fix traffic rule unit tests;
@bdowden bdowden requested a review from Kane610 July 22, 2024 01:19
Copy link
Member

@Kane610 Kane610 left a comment

Choose a reason for hiding this comment

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

Almost there

homeassistant/components/unifi/switch.py Show resolved Hide resolved
homeassistant/components/unifi/switch.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/switch.py Outdated Show resolved Hide resolved
tests/components/unifi/test_switch.py Outdated Show resolved Hide resolved
tests/components/unifi/test_switch.py Outdated Show resolved Hide resolved
@bdowden
Copy link
Contributor Author

bdowden commented Jul 23, 2024

Almost there

re: Update Coordinator

This is an interesting situation. Currently it won't reset the polling timer because the update coordinator isn't tied specifically to the traffic rules; instead it uses its timer to call a function on the entity loader to update a group of entities (it just so happens that it's only traffic rules).

I think there are benefits to resetting the timer for any entities that are updated outside of the update coordinator. As it's currently written, though, it's polling for a group of entities. To support resetting for a single item, I think there would have to be a single coordinator per entity; for only traffic rules is fine but there may be performance issues with multiples

tests/components/unifi/test_switch.py Outdated Show resolved Hide resolved
tests/components/unifi/test_switch.py Outdated Show resolved Hide resolved
@bdowden bdowden marked this pull request as ready for review July 24, 2024 11:34
@home-assistant home-assistant bot requested a review from Kane610 July 24, 2024 11:34
Copy link
Member

@Kane610 Kane610 left a comment

Choose a reason for hiding this comment

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

Some minor things left to handle

homeassistant/components/unifi/hub/hub.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/switch.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/switch.py Outdated Show resolved Hide resolved
tests/components/unifi/test_switch.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft July 25, 2024 11:45
@bdowden bdowden marked this pull request as ready for review July 30, 2024 01:31
@home-assistant home-assistant bot requested a review from Kane610 July 30, 2024 01:31
@Kane610 Kane610 merged commit 18a7d15 into home-assistant:dev Jul 30, 2024
26 checks passed
@Kane610
Copy link
Member

Kane610 commented Jul 30, 2024

Thanks!

control_fn=async_traffic_rule_control_fn,
device_info_fn=async_unifi_network_device_info_fn,
is_on_fn=lambda hub, traffic_rule: traffic_rule.enabled,
name_fn=lambda traffic_rule: traffic_rule.description,
Copy link
Member

Choose a reason for hiding this comment

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

As there is a name property in the test data for traffic rules, why did you go for description over name?

@github-actions github-actions bot locked and limited conversation to collaborators Aug 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants