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 sensors for Unifi latency #116737

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

kimdv
Copy link
Contributor

@kimdv kimdv commented May 3, 2024

Breaking change

Proposed change

This PR aims to add Unifi latency to HA.
Screenshot 2024-05-03 at 22 58 25

By adding this we have the ability to automate if it increase etc or other trigger what people can think of.

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

home-assistant bot commented May 3, 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.

@kimdv
Copy link
Contributor Author

kimdv commented May 3, 2024

If this accepted and almost done I will add documentation.

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.

Nice addition, some small changes needed based on mypy

@home-assistant home-assistant bot marked this pull request as draft May 3, 2024 21:13
@home-assistant
Copy link

home-assistant bot commented May 3, 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.

@Kane610
Copy link
Member

Kane610 commented May 11, 2024

I've published aiounifi v78 Kane610/aiounifi@v77...v78

@kimdv
Copy link
Contributor Author

kimdv commented May 11, 2024

I've published aiounifi v78 Kane610/aiounifi@v77...v78

Should I update the dependency in this PR or does it need to be. Sperrte PR?

@Kane610
Copy link
Member

Kane610 commented May 11, 2024

I've published aiounifi v78 Kane610/aiounifi@v77...v78

Should I update the dependency in this PR or does it need to be. Sperrte PR?

You can do it in this one

@kimdv kimdv force-pushed the kimdv/add-latency-for-unifi branch from 0963377 to f1dbcb2 Compare May 12, 2024 12:08
@kimdv kimdv force-pushed the kimdv/add-latency-for-unifi branch from f1dbcb2 to 4448e15 Compare May 12, 2024 12:12
@kimdv kimdv force-pushed the kimdv/add-latency-for-unifi branch from 4448e15 to 8264e58 Compare May 12, 2024 12:13
@kimdv kimdv force-pushed the kimdv/add-latency-for-unifi branch from fb9b5a7 to 311ce78 Compare May 12, 2024 13:51
@kimdv kimdv force-pushed the kimdv/add-latency-for-unifi branch from 311ce78 to ec79efa Compare May 12, 2024 13:54
@kimdv kimdv requested a review from Kane610 May 12, 2024 14:06
@kimdv kimdv marked this pull request as ready for review May 12, 2024 14:06
@Kane610
Copy link
Member

Kane610 commented May 12, 2024

It's way too much duplication here so need to figure out how it can be boiled down to one instance

@kimdv
Copy link
Contributor Author

kimdv commented May 12, 2024

It's way too much duplication here so need to figure out how it can be boiled down to one instance

Any suggestions ?

Tried to look at bit into it.
Couldn't find a way

@Kane610
Copy link
Member

Kane610 commented May 12, 2024

You can deduplicate all instances of wan/wan2 with partial

@Kane610
Copy link
Member

Kane610 commented May 12, 2024

We could simplify the PR initially and only take one value from Wan as a start anf then look at improving it.

@Kane610
Copy link
Member

Kane610 commented May 12, 2024

Maybe some extra thing can be added to be the entity description that can be used to deduce that each entity is based on more data

@kimdv
Copy link
Contributor Author

kimdv commented May 13, 2024

We could simplify the PR initially and only take one value from Wan as a start anf then look at improving it.

Will start with WAN.
Having a bit hard to see how it can be done. Python is not my primary language 😅

Maybe some extra thing can be added to be the entity description that can be used to deduce that each entity is based on more data

Yes we have the same "problem" with storage.
As here it's possible to attach multiple storage devices to the Unifi.
I even think the new Dream Machine Pro Max have two disk bays.

@kimdv
Copy link
Contributor Author

kimdv commented May 13, 2024

Maybe some extra thing can be added to be the entity description that can be used to deduce that each entity is based on more data

If you can guide me a bit, I'm willing to try to implement this

@Kane610
Copy link
Member

Kane610 commented May 14, 2024

Having a bit hard to see how it can be done. Python is not my primary language 😅

image

image

@Kane610
Copy link
Member

Kane610 commented May 14, 2024

So if you start with WAN and decide on just one latency source you can hard code it all.

So I have a few alternate paths forward, they are not concrete but only notions yet.

1 Change a bit more how its exposed in the library, not sure how
2 Add an extra property on UnifiEntityDescription which can provide one more layer of data source, which it can iterate over, not sure how pretty this would be
3 Do a method that would generate additional list items for ENTITY_DESCRIPTIONS, this is closer to what you have done now but still less duplication

I think both 2 and 3 would benefit other sensors like TX/RX sensors as well

@Kane610
Copy link
Member

Kane610 commented May 15, 2024

Thinking more about it maybe 3 is the way to go for now

@kimdv
Copy link
Contributor Author

kimdv commented May 23, 2024

@Kane610 I just did a rebase. I was more than 400 commits behind.

I use a Mac with VSCode and dev containers.
Do you know why I now get this error when I try > Run Task -> Install requirements

 *  Executing task: uv pip install -r requirements_all.txt 

error: error sending request for url (https://pypi.org/simple/aiobotocore/)
  Caused by: client error (Connect)
  Caused by: invalid peer certificate: BadSignature

 *  The terminal process "/usr/bin/zsh '-c', 'uv pip install -r requirements_all.txt'" terminated with exit code: 2. 
 *  Press any key to close the terminal. 

@Kane610
Copy link
Member

Kane610 commented May 23, 2024

Try starting with a./script/setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants