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 unifi power stats for PDU outlets #98081

Merged
merged 1 commit into from Aug 10, 2023

Conversation

Cisien
Copy link
Contributor

@Cisien Cisien commented Aug 8, 2023

Proposed change

This PR adds support for the Unifi component to pull power statistics from power outlets on PDU devices that support providing power data.

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 change was developed against the USP-PDU-Pro device, and tested with the USP-Plug as a device that shows up in the outlets API, but does not support power reporting. Additionally, the PDU-Pro has four outlets that are USB-C ports, which do not report power. In all cases, outlets that don't support this function are not included as power sensors.

My setup includes two PDU-Pro devices which properly associate their respective plugs.

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:

@home-assistant
Copy link

home-assistant bot commented Aug 8, 2023

Hi @Cisien

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 Aug 8, 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.

@Cisien
Copy link
Contributor Author

Cisien commented Aug 9, 2023

I did notice one issue when I run this locally in my "production" instance of HA, but suspect it's related to how I'm overriding.

The localized strings don't show up in the "Configure" wizard for the integration. I am testing this locally by simply copying the unifi folder from my branch to custom_components and adding a version to the manifest.

Please let me know if this doesn't sound like something related to my local hacked up setup and i'll dig into it further.

@MartinHjelmare MartinHjelmare changed the title Adds support for power stats for PDU outlets. Add unifi power stats for PDU outlets Aug 9, 2023
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!

Im mostly worried about properly matching devices supporting metering as with if looking at caps would be enough.

homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/unifi/sensor.py Outdated Show resolved Hide resolved
tests/components/unifi/test_sensor.py Show resolved Hide resolved
tests/components/unifi/test_sensor.py Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft August 9, 2023 10:14
@home-assistant
Copy link

home-assistant bot commented Aug 9, 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.

@Cisien
Copy link
Contributor Author

Cisien commented Aug 9, 2023

the PDU device has a few metrics that are exposed that provide info about the power budget and utilization all-up. I'm going to expand this PR to include diagnostics for those counters as well.

@Kane610
Copy link
Member

Kane610 commented Aug 9, 2023

the PDU device has a few metrics that are exposed that provide info about the power budget and utilization all-up. I'm going to expand this PR to include diagnostics for those counters as well.

If it's small else it's better to do a small separate pr

@Cisien Cisien force-pushed the add-support-for-outlet-power branch from 696bc98 to 6bd136a Compare August 9, 2023 18:20
@Cisien
Copy link
Contributor Author

Cisien commented Aug 9, 2023

I'll create a new PR for it

@Cisien Cisien marked this pull request as ready for review August 9, 2023 18:45
@home-assistant home-assistant bot requested a review from Kane610 August 9, 2023 18:46
homeassistant/components/unifi/entity.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft August 9, 2023 21:27
@Cisien Cisien force-pushed the add-support-for-outlet-power branch from 332054b to 0a3cc8f Compare August 9, 2023 22:04
@Cisien Cisien force-pushed the add-support-for-outlet-power branch from 0a3cc8f to 0be4e49 Compare August 9, 2023 22:09
@Cisien Cisien marked this pull request as ready for review August 9, 2023 22:10
@home-assistant home-assistant bot requested a review from Kane610 August 9, 2023 22:10
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.

Awesome! Now only an update to the integration documentation is needed.

@Cisien
Copy link
Contributor Author

Cisien commented Aug 9, 2023

Ok, i'll look into what is needed to make that happen.

I also just noticed that the PDU outlets don't get switch entities. I'm guessing because they are missing the "has_relay" property, so i'll probably look into a separate PR to address that.

@Kane610
Copy link
Member

Kane610 commented Aug 9, 2023

Ok, i'll look into what is needed to make that happen.

I also just noticed that the PDU outlets don't get switch entities. I'm guessing because they are missing the "has_relay" property, so i'll probably look into a separate PR to address that.

You can create a documentation PR in less than five minutes from github directly and you have two weeks to go :).

Maybe investigate if we can utilize caps for the switch? This is what I got stuck on last time trying to figure out the common denominator.

@Cisien
Copy link
Contributor Author

Cisien commented Aug 9, 2023

Maybe investigate if we can utilize caps for the switch? This is what I got stuck on last time trying to figure out the common denominator.

That would be convenient, wouldn't it? Unfortunately, the USP-Plug devices don't expose an outlet_caps property.

@Cisien
Copy link
Contributor Author

Cisien commented Aug 9, 2023

PR for docs repo: home-assistant/home-assistant.io#28524

@Kane610 Kane610 merged commit fe1f617 into home-assistant:dev Aug 10, 2023
21 checks passed
@Cisien Cisien deleted the add-support-for-outlet-power branch August 10, 2023 16:28
@github-actions github-actions bot locked and limited conversation to collaborators Aug 11, 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