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 Unifi bandwidth sensors #101598

Merged
merged 8 commits into from Oct 22, 2023
Merged

Update Unifi bandwidth sensors #101598

merged 8 commits into from Oct 22, 2023

Conversation

wittypluck
Copy link
Contributor

@wittypluck wittypluck commented Oct 7, 2023

Proposed change

This Pull request aim is to improve Unifi network bandwidth sensor. Currently, bandwidth sensors (RX, TX) have the unit set as MEGABYTE, and are not flagged as Measurement. They need to be wrapped in template sensors to be used as bandwidth sensors.

Updating the unit of measurement to MEGABYTES_PER_SECOND and the device class to DATA_RATE ensure that the sensors can be used "as is" in Home assistant without adding additional template sensors to convert to the correct units.
Additionally the sensors are now automatically picked up by the History feature of Home assistant to provide long term statistics.
The PR also adds a suggested unit of measurement (MEGABITS_PER_SECOND) and an icon to each of the TX, RX sensors.

I have tested locally that the PR does not provoke regressions for existing users of the integration, and that changes to the sensors are picked up correctly for existing and new users of the integration.

I have also tested locally through bandwidth tests that although the Unifi documentation of the underlying sensors (rx_bytes-r / tx_bytes-r / wired-rx_bytes-r / wired-tx_bytes-r) is not very explicit, they do indeed correspond to a measure in bytes over the last second.

I have also tested locally that somewhat un-intuitively the "TX" sensor corresponds to download bandwidth (as seen from the device) and the "RX" sensor corresponds to upload bandwidth (as seen from the device).

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 Black (black --fast 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 @wittypluck

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 Oct 7, 2023

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 October 7, 2023 16:47
@home-assistant
Copy link

home-assistant bot commented Oct 7, 2023

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.

@Kane610
Copy link
Member

Kane610 commented Oct 8, 2023

Thanks for the PR. Please start by fixing the failing checks which seems to be related to unsorted imports. If you use the pre-commit tools this would be fixed automatically

@wittypluck
Copy link
Contributor Author

Thank you for the comment and the tip, I'm still having issues with the pre commit tools but will make sure the formatting is correct.

@wittypluck wittypluck marked this pull request as ready for review October 8, 2023 17:06
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

@wittypluck
Copy link
Contributor Author

Hi @Kane610, thanks for approving the change. It seems I still have a few tests to fix, I'm working on it.

@Kane610
Copy link
Member

Kane610 commented Oct 21, 2023

Hi @Kane610, thanks for approving the change. It seems I still have a few tests to fix, I'm working on it.

Apologies for loosing track of the review. Let's get this in before next beta branches off

@wittypluck
Copy link
Contributor Author

No problem!
I have reverted the suggested_unit_of_measurement which was converting from MEGABYTES_PER_SECOND to MEGABITS_PER_SECOND as it was causing issues with unit tests and could be an unwanted change for some users.
I have also updated and added unit tests on the new attributes so hopefully everything should pass now.

@frenck frenck requested a review from Kane610 October 22, 2023 13:33
@Kane610 Kane610 merged commit b79eae2 into home-assistant:dev Oct 22, 2023
23 checks passed
@Kane610
Copy link
Member

Kane610 commented Oct 22, 2023

Thank you @wittypluck

@wittypluck
Copy link
Contributor Author

Thank you @Kane610 as this was my first commit in home assistant !

@Kane610
Copy link
Member

Kane610 commented Oct 22, 2023

Welcome to the club @wittypluck

@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2023
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

2 participants