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

Allow SensorDeviceClass.POWER_FACTOR unit None #85181

Merged
merged 2 commits into from
Jan 5, 2023
Merged

Conversation

emontnemery
Copy link
Contributor

@emontnemery emontnemery commented Jan 5, 2023

Proposed change

Allow SensorDeviceClass.POWER_FACTOR unit None

Background:
Power factor is the dimensionless ratio of the real power and apparent power. Partially because of now fixed limitations in frontend, Home Assistant has documented the only allowed unit as %, i.e. the ratio multiplied by 100. There are no longer such limitations in the frontend, and we can allow the unit to be None.

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

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
  • 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:

@emontnemery emontnemery requested a review from a team as a code owner January 5, 2023 08:28
@home-assistant
Copy link

home-assistant bot commented Jan 5, 2023

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (sensor) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of sensor can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign sensor Removes the current integration label and assignees on the issue, add the integration domain after the command.

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

This makes sense; looking at the original architectural discussion omitting the empty unit was mainly driven by showing history graphs.

LGTM ✅

Does need an end-user and dev docs adjustment too.

../Frenck

@epenet
Copy link
Contributor

epenet commented Jan 5, 2023

cc @farmio / ref #84374

@epenet
Copy link
Contributor

epenet commented Jan 5, 2023

Note: looking at knx #85160 and tasmota #85182 do we need to add Cos φ to the valid units for power factor?

@@ -253,7 +253,7 @@ class SensorDeviceClass(StrEnum):
POWER_FACTOR = "power_factor"
"""Power factor.

Unit of measurement: `%`
Unit of measurement: `%`, `None`
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be adjusted in NumberDeviceClass also.

@emontnemery
Copy link
Contributor Author

Note: looking at knx #85160 and tasmota #85182 do we need to add Cos φ to the valid units for power factor?

No, Cos φ is not a valid unit. Tasmota and knx should translate API unit Cos φ to None.

@farmio
Copy link
Contributor

farmio commented Jan 5, 2023

This is nice! I was just thinking of doing that too 🤣

Should there be conversion of % to unit-less? Not sure if that makes sense...

@emontnemery
Copy link
Contributor Author

Should there be conversion of % to unit-less? Not sure if that makes sense...

Yes, but not in a hotfix, it requires frontend and recorder support too.

@frenck frenck merged commit c1075eb into dev Jan 5, 2023
@frenck frenck deleted the power_factor_allow_none branch January 5, 2023 10:03
@balloob
Copy link
Member

balloob commented Jan 6, 2023

Untagging this from the hot fix because it depends on things moving to const.py from #84973, which is not in 2023.1. If we want this fix as part of a hot fix, we will need the fix backported on top of the rc branch.

@balloob balloob removed this from the 2023.1.1 milestone Jan 6, 2023
@epenet
Copy link
Contributor

epenet commented Jan 6, 2023

Backport PR created: #85287

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

7 participants