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 energy usage sensor to A. O. Smith integration #105616

Merged
merged 7 commits into from Dec 23, 2023

Conversation

bdr99
Copy link
Contributor

@bdr99 bdr99 commented Dec 13, 2023

Proposed change

Adds a sensor entity for energy usage to the A. O. Smith integration.

I wanted the data for this entity to update on a slower interval than the other entities, so I created a separate data update coordinator class. This required also creating a separate base entity class and moving the common attributes (used for device info) into a parent base entity class.

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

homeassistant/components/aosmith/__init__.py Outdated Show resolved Hide resolved
Comment on lines 29 to 31
device_details_list = [
build_device_details(device) for device in status_coordinator.data.values()
]
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I don't really feel the whole abstraction to have a separate object for device details. Can we maybe just pass on the status_coordinator.keys() to the energy coordinator and call it a day? The in the sensor platform you can just get the data from the status coordinator and pass that into the new entities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The status coordinator data is just a dict[str, dict[str, Any]]. If you don't mind, I'd prefer to keep it this way because I really think it makes the code cleaner to have a strongly typed dataclass rather than just passing a dict around everywhere. I do agree with the first part of your suggestion though, about passing the status coordinator keys to the energy coordinator, and I've made that change.

@home-assistant
Copy link

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.

@home-assistant home-assistant bot marked this pull request as draft December 21, 2023 09:49
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

My point was more, the status coordinator already has the data of the devices, so why construct a list of device info. For me that kinda feels like we're storing the stuff twice.

For real type safety you could look into adding types to the lib as return value

homeassistant/components/aosmith/__init__.py Outdated Show resolved Hide resolved
@bdr99 bdr99 force-pushed the aosmith_energy_usage_sensor branch from 44e577b to 835dd93 Compare December 23, 2023 01:34
@bdr99 bdr99 marked this pull request as ready for review December 23, 2023 02:04
@bdr99 bdr99 force-pushed the aosmith_energy_usage_sensor branch from 77ed066 to 5b31fe9 Compare December 23, 2023 14:03
@joostlek joostlek merged commit c629b43 into home-assistant:dev Dec 23, 2023
23 checks passed
Bre77 pushed a commit to Bre77/core that referenced this pull request Dec 23, 2023
…5616)

* Add energy usage sensor to A. O. Smith integration

* Address review comments

* Address review comment

* Address review comment

* Create device outside of the entity class

* Address review comment

* remove platinum
Bre77 pushed a commit to Bre77/core that referenced this pull request Dec 23, 2023
…5616)

* Add energy usage sensor to A. O. Smith integration

* Address review comments

* Address review comment

* Address review comment

* Create device outside of the entity class

* Address review comment

* remove platinum
@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 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