Skip to content

Add state_class and use SensorEntityDescription for comfoconnect#54066

Merged
MartinHjelmare merged 11 commits intohome-assistant:devfrom
michaelarnauts:comfoconnect_state_class
Sep 24, 2021
Merged

Add state_class and use SensorEntityDescription for comfoconnect#54066
MartinHjelmare merged 11 commits intohome-assistant:devfrom
michaelarnauts:comfoconnect_state_class

Conversation

@michaelarnauts
Copy link
Copy Markdown
Contributor

@michaelarnauts michaelarnauts commented Aug 5, 2021

Proposed change

  • Add state_class so the power stats work with the new energy dashboard.
  • Use native_value and native_unit_of_measurement
  • Refactor to use SensorEntityDescriptions for templates in this integration.

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

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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

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

To help with the load of incoming pull requests:

@michaelarnauts michaelarnauts force-pushed the comfoconnect_state_class branch from 9ea534a to 45a3bd6 Compare August 5, 2021 13:56
@frenck frenck added energy Related to energy management smash Indicator this PR is close to finish for merging or closing labels Aug 9, 2021
@michaelarnauts
Copy link
Copy Markdown
Contributor Author

I have a conflict now since #48261 has been merged. Should I use native_unit_of_measurement and _attr_native_value now for all sensors?

@michaelarnauts
Copy link
Copy Markdown
Contributor Author

I also had to modify homeassistant/components/fan/__init__.py (https://github.com/home-assistant/core/pull/54066/files#diff-f432c8111ba270e7e035c3f131c7dcd5ff1398fdc740eaaa65e64873f13ecc55) since it didn't support the _attr_supported_features yet. This then caused issues in state_attributes since the typing is different.

{
vol.Optional(CONF_RESOURCES, default=[]): vol.All(
cv.ensure_list, [vol.In(SENSOR_TYPES)]
cv.ensure_list, [vol.In([desc.key for desc in SENSOR_TYPES])]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Side note: Long term we should remove this option and just allow users to enable/disable entities as wanted via the entity registry, and we set the less important entities as disabled by default. That means the description key will change to be the sensor_id.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I want to take a look at converting this to a config flow later, and then this will go away anyway.

@michaelarnauts
Copy link
Copy Markdown
Contributor Author

The required changes have been made, and it's up to date with the latest dev branch.

Is it okay for the small change in homeassistant/components/fan/__init__.py to go in here? Or should that happen in a separate PR?

@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label Aug 25, 2021
@michaelarnauts
Copy link
Copy Markdown
Contributor Author

The changes in fan have been reverted.

@MartinHjelmare
Copy link
Copy Markdown
Member

There's a test failure.

@michaelarnauts
Copy link
Copy Markdown
Contributor Author

There's a test failure.

Sorry. I'm looking into it.

@michaelarnauts
Copy link
Copy Markdown
Contributor Author

Sorry for the annoying commits. I'm still waiting for tox to fully install all dependencies so I can run the tests locally. This seems to take ages. :(

@michaelarnauts michaelarnauts force-pushed the comfoconnect_state_class branch from e148ff5 to 2c523b1 Compare September 3, 2021 15:19
@cdce8p
Copy link
Copy Markdown
Member

cdce8p commented Sep 3, 2021

@michaelarnauts You don't necessarily need tox for that. As long as the dependancies are installed locally, invoking pytest directly will also work. That's the setup I tend to use: venv with all basic requirements + those for the component I want to run the tests for. Than pytest tests/components/xxx/

That might be helpful as well: https://developers.home-assistant.io/docs/development_testing#testing-outside-of-tox

@michaelarnauts
Copy link
Copy Markdown
Contributor Author

@michaelarnauts You don't necessarily need tox for that. As long as the dependancies are installed locally, invoking pytest directly will also work. That's the setup I tend to use: venv with all basic requirements + those for the component I want to run the tests for. Than pytest tests/components/xxx/

That might be helpful as well: https://developers.home-assistant.io/docs/development_testing#testing-outside-of-tox

I tried that, but it complained about missing pool fixtures or something like that. I haven't had the time do fully dive into how home assistant runs its tests.

@cdce8p cdce8p added the project-code_style PRs related to #53201 - pylint CodeStyle update label Sep 4, 2021
@michaelarnauts
Copy link
Copy Markdown
Contributor Author

Reverted attribute key changes, and removed breaking change from ticket.

@michaelarnauts
Copy link
Copy Markdown
Contributor Author

All done!

Copy link
Copy Markdown
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!

@MartinHjelmare MartinHjelmare merged commit 5d3d6fa into home-assistant:dev Sep 24, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Sep 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

by-code-owner cla-signed code-quality energy Related to energy management integration: comfoconnect project-code_style PRs related to #53201 - pylint CodeStyle update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants