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 device classes for electrical measurement #36800

Merged
merged 3 commits into from
Aug 8, 2020
Merged

Add device classes for electrical measurement #36800

merged 3 commits into from
Aug 8, 2020

Conversation

fabiocastagnino
Copy link
Contributor

@fabiocastagnino fabiocastagnino commented Jun 14, 2020

Proposed change

I want to add 4 new device_classs, to handle the electrical measurement

fixes home-assistant/architecture#397

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

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:

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@homeassistant
Copy link
Contributor

Hi @fabiocastagnino,

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!

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

This is a good idea, I think. We have a requirement that changes to our entity model needs approval in an architecture issue.

Please open an issue:
https://developers.home-assistant.io/docs/core/entity#changing-the-entity-model

Also extend our developer docs here:
https://developers.home-assistant.io/docs/core/entity/sensor#available-device-classes

@fabiocastagnino
Copy link
Contributor Author

Hi,
I've:

@fabiocastagnino fabiocastagnino marked this pull request as ready for review June 15, 2020 17:27
@Adminiuga
Copy link
Contributor

Adminiuga commented Jun 15, 2020

Does DEVICE_CLASS_POWER_FACTOR has to be it's own device class? Isn't "power factor" a characteristic inherently associated with DEVICE_CLASS_POWER sensors?
in other words, if we don't have a DEVICE_CLASS_HUMIDITY_RELATIVE and DEVICE_CLASS_HUMIDITY_ABSOLUTE, what is the compelling case to have DEVICE_CLASS_POWER_FACTOR?

@fabiocastagnino
Copy link
Contributor Author

Your observation it's correct, but to have a correct power measurement you need both information.
You suggest to put all measurement of the "Power Triangle" (Real Power, Relative Power, Apparent Power, Power Factor) under DEVICE_CLASS_POWER ?
In this case I'll review the PR.

@Adminiuga
Copy link
Contributor

Adminiuga commented Jun 15, 2020

Just asking :) I think this is fine, cause even we don't have the DEVICE_CLASS_HUMIDITY_ABSOLUTE/RELATIVE, there's DEVICE_CLASS_DOOR and DEVICE_CLASS_GARAGE_DOOR and DEVICE_CLASS_GARAGE

@MartinHjelmare
Copy link
Member

I think it's good to keep power factor separate.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Please keep all lists sorted 🔡

homeassistant/components/sensor/device_condition.py Outdated Show resolved Hide resolved
tests/testing_config/custom_components/test/sensor.py Outdated Show resolved Hide resolved
@MartinHjelmare
Copy link
Member

@bramkragten do we need to add anything in the frontend when adding a new sensor device class?

@bramkragten
Copy link
Member

If the sensors will just have a unit of measurement, I think we don't have to change anything.

@MartinHjelmare
Copy link
Member

Do we want to set a specific default icon per class?

@bramkragten
Copy link
Member

Yes, you can set one https://github.com/home-assistant/frontend/blob/dev/src/common/entity/sensor_icon.ts#L6-L7

@fabiocastagnino
Copy link
Contributor Author

fabiocastagnino commented Jun 18, 2020

Yes, we can use:
current: "hass:flash",
energy: "hass:flash",
power_factor: "hass:flash",,
voltage: "hass:current-ac",

PR: home-assistant/frontend#6193
locally work

@fabiocastagnino
Copy link
Contributor Author

PR: home-assistant/frontend#6193 ready
All PR locally works:
image

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Some small comments. Otherwise looks good.

homeassistant/components/sensor/translations/it.json Outdated Show resolved Hide resolved
tests/testing_config/custom_components/test/sensor.py Outdated Show resolved Hide resolved
@homeassistant
Copy link
Contributor

Hi @fabiocastagninohorsa,

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!

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@dgomes dgomes left a comment

Choose a reason for hiding this comment

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

Someone needs to restart the CI

@MartinHjelmare
Copy link
Member

If the branch is rebased the new CI should run automatically.

(cherry picked from commit 2409fe19ed43bef568a0cca826652867d3a2d71a)
@fabiocastagnino
Copy link
Contributor Author

I've squashed and rebased the branch, waiting for CI

@fabiocastagnino
Copy link
Contributor Author

2 tests (test_get_conditions, test_get_triggers) fail for the same reason.
Tests load power_factor sensor without unit of measurement, as configured, but device_condition/device_trigger seems that it is required
This can fix the tests:
image
I'm not sure about the fix (in the test or in the device_condition/device_trigger).
What is the expected behaviour in the original design?

@MartinHjelmare
Copy link
Member

It seems the sensor device automations use the unit of measurement in the automation description.

@balloob what do you suggest?

@MartinHjelmare
Copy link
Member

Let's set % as unit of measurement for power factor device class so we can unblock this.

@fabiocastagnino
Copy link
Contributor Author

ok, tomorrow I'll push the change in all PR

@fabiocastagnino
Copy link
Contributor Author

ready

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

Add device classes for electrical measurement
6 participants