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 sensor platform to laundrify integration #121378

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

xLarry
Copy link
Contributor

@xLarry xLarry commented Jul 6, 2024

Proposed change

This PR adds the sensor platform to the laundrify integration implementing two entities with the following device classes:

  • power: showing the latest measurement in Watts
  • energy: showing the total consumption in kWh

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.

To help with the load of incoming pull requests:

homeassistant/components/laundrify/icons.json Outdated Show resolved Hide resolved
homeassistant/components/laundrify/sensor.py Outdated Show resolved Hide resolved
async def async_update(self) -> None:
"""Fetch latest power measurement from the device."""
try:
power = await self._device.get_power()
Copy link
Member

Choose a reason for hiding this comment

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

This integration uses a coordinator, shouldn't that be used instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose to use a non-coordinated entity for the PowerSensor since the latest power measurements are polled locally from each individual power plug.

Opposed to that, the latest updates for the EnergySensor and BinarySensor are fetched from the backend in a single call (using the LaundrifyUpdateCoordinator).

Copy link
Member

Choose a reason for hiding this comment

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

Why not use a coordinator per device to handle this? As in, that would allow you to use coordinator entities, retry logic, and unavailable logic that is all provided by the datacoordinator.

Copy link
Contributor Author

@xLarry xLarry Jul 10, 2024

Choose a reason for hiding this comment

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

My understanding of a coordinator was to group data polling for several entities/devices to a single, coordinated API call.

Using a coordinator per device sounds a bit counter-intuitive to me. As per the developer docs:

If you can map exactly one device endpoint to a single entity, you can fetch the data for this entity inside the update()/async_update() methods.

Let me know if I miss something.

homeassistant/components/laundrify/sensor.py Outdated Show resolved Hide resolved
tests/components/laundrify/test_sensor.py Outdated Show resolved Hide resolved
tests/components/laundrify/test_sensor.py Outdated Show resolved Hide resolved
tests/components/laundrify/test_sensor.py Outdated Show resolved Hide resolved
tests/components/laundrify/test_sensor.py Outdated Show resolved Hide resolved
tests/components/laundrify/test_sensor.py Outdated Show resolved Hide resolved
@home-assistant
Copy link

home-assistant bot commented Jul 6, 2024

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 July 6, 2024 15:23
@xLarry
Copy link
Contributor Author

xLarry commented Jul 7, 2024

Hi @frenck,

Thanks for your prompt and thorough review.

I addressed the requested changes in my latest commits, referenced the corresponding commits in a comment and resolved the discussion if applicable.

Some discussions required further information and are left unresolved. Would be great if you could double-check them.

Enjoy your weekend!

// EDIT:
Just pulled the latest changes from dev and rebased this branch (after #121435 has already been merged). Hope I didn't break anything by force-pushing the updated branch.

@xLarry xLarry marked this pull request as ready for review July 7, 2024 14:19
@home-assistant home-assistant bot requested a review from frenck July 7, 2024 14:19
@xLarry xLarry marked this pull request as draft July 15, 2024 09:08
@xLarry xLarry marked this pull request as ready for review July 15, 2024 09:09
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.

None yet

2 participants