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 bandwidth sensor for unifi device ports #115362

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

kimdv
Copy link
Contributor

@kimdv kimdv commented Apr 10, 2024

Proposed change

This PR aims to add bandwidth sensors for unify device ports.
It makes it possible to for users to track bandwidth usage on each port, so they can make nice dashboards.

I was considering to add only for WAN ports, but then I tought it might just be easier to add for all ports, and then let the users enable the ones they want to use.

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:

@home-assistant
Copy link

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.

@kimdv kimdv force-pushed the kimdv/add-wan-speed branch 2 times, most recently from 465335c to 01af544 Compare April 10, 2024 13:48
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.

Thanks! Make these sensors disabled by default, I think these are just too many to populate all at once with the setting. I think over time that config will be removed and just have them disabled by default.

homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
@home-assistant
Copy link

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.

@home-assistant home-assistant bot marked this pull request as draft April 10, 2024 18:43
@kimdv kimdv marked this pull request as ready for review April 11, 2024 13:55
@home-assistant home-assistant bot requested a review from Kane610 April 11, 2024 13:55
@kimdv
Copy link
Contributor Author

kimdv commented Apr 11, 2024

@Kane610 disabled by default now.
I also added more scenarios to the test case.

@wittypluck
Copy link
Contributor

wittypluck commented Apr 20, 2024

Hello,
this feature looks interesting !
Question/suggestion: why not leave the data in the native unit (bytes/seconds it seems), add a suggested unit, and let HA do the conversions ?
Something like :

        native_unit_of_measurement=UnitOfDataRate.BYTES_PER_SECOND,
        suggested_unit_of_measurement=UnitOfDataRate.MEGABITS_PER_SECOND,
..
        value_fn=lambda hub, port: port.raw.get("rx_bytes-r", 0),

@Kane610
Copy link
Member

Kane610 commented Apr 21, 2024

Hello, this feature looks interesting ! Question/suggestion: why not leave the data in the native unit (bytes/seconds it seems), add a suggested unit, and let HA do the conversions ? Something like :

        native_unit_of_measurement=UnitOfDataRate.BYTES_PER_SECOND,
        suggested_unit_of_measurement=UnitOfDataRate.MEGABITS_PER_SECOND,
..
        value_fn=lambda hub, port: port.raw.get("rx_bytes-r", 0),

Yes let's do this.

homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft April 21, 2024 18:14
@kimdv kimdv requested a review from Kane610 April 21, 2024 19:14
@kimdv kimdv marked this pull request as ready for review April 21, 2024 19:14
@kimdv
Copy link
Contributor Author

kimdv commented Apr 21, 2024

@Kane610 @wittypluck I change to what is was suggested.

I also removed the supported_fn.

@Kane610
Copy link
Member

Kane610 commented Apr 22, 2024

Looks ok, will review tonight

@kimdv kimdv force-pushed the kimdv/add-wan-speed branch 2 times, most recently from 011a3fa to a21fbfd Compare April 22, 2024 13:40
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.

Final thing, it's good to keep unique ids unique per source as well. Just in case some migration is needed down the line

homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft April 22, 2024 18:31
@kimdv kimdv marked this pull request as ready for review April 22, 2024 20:24
@home-assistant home-assistant bot requested a review from Kane610 April 22, 2024 20:24
@Kane610
Copy link
Member

Kane610 commented Apr 22, 2024

Thanks! Next time try to avoid doing a rebase after fixing a comment, takes longer to look through.

@Kane610 Kane610 merged commit b69f589 into home-assistant:dev Apr 22, 2024
24 checks passed
@Kane610
Copy link
Member

Kane610 commented Apr 22, 2024

Maybe you could add a small note to the integration documentation about it as well?

@kimdv kimdv deleted the kimdv/add-wan-speed branch April 23, 2024 05:16
@kimdv
Copy link
Contributor Author

kimdv commented Apr 23, 2024

Thanks! Next time try to avoid doing a rebase after fixing a comment, takes longer to look through.

Should i just add commits with fixes and you will squash them?

And then rebase before merge ?

@Kane610
Copy link
Member

Kane610 commented Apr 23, 2024

Thanks! Next time try to avoid doing a rebase after fixing a comment, takes longer to look through.

Should i just add commits with fixes and you will squash them?

And then rebase before merge ?

Squash and merge is the common approach on this github repo so just bring on the commits ;)

I'm not saying you can't rebase everything into one commit but then I can't see the incremental changes

Rebase at the end is only needed if there is a merge conflict with dev

tr4nt0r pushed a commit to tr4nt0r/ha-core that referenced this pull request Apr 23, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 24, 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.

None yet

3 participants