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

Fix Huisbaasje negative periodic gas readings (#103457) #108090

Merged
merged 7 commits into from Jan 31, 2024

Conversation

JeroenvIS
Copy link
Contributor

@JeroenvIS JeroenvIS commented Jan 15, 2024

Avoid negative gas readings in energy dashboard when using Huisbaasje / EnergyFlip integration. Use state_class "TOTAL_INCREASING" for entities related to periodic gas usage (day, week, month, year).

Proposed change

Fix issue #103457 in Huisbaasje 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)
  • 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
  • [X ] 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.

This is my first Home Assistant PR. I've read the "Contributing" document and the details of this minor fix were discussed in the ticket. It's still unclear to me how to test the changes locally; however, I believe that this change is so minor (and related tests have been performed by other users, see issue) that that doesn't need to be blocking.

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:

Avoid negative gas readings in energy dashboard when using Huisbaasje /
EnergyFlip integration. Use state_class "TOTAL_INCREASING" for entities
related to periodic gas usage (day, week, month, year).
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @JeroenvIS

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!

@home-assistant home-assistant bot marked this pull request as draft January 15, 2024 12:54
@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
Copy link

Hey there @dennisschroer, mind taking a look at this pull request as it has been labeled with an integration (huisbaasje) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of huisbaasje can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign huisbaasje Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@MartinHjelmare MartinHjelmare changed the title Huisbaasje: fix negative periodic gas readings (#103457) Fix Huisbaasje negative periodic gas readings (#103457) Jan 15, 2024
@JeroenvIS JeroenvIS marked this pull request as ready for review January 15, 2024 15:47
@frenck
Copy link
Member

frenck commented Jan 30, 2024

So, this was changed in #102945 to fix issue #102923

So is that isn't no longer an issue? Or? What is going on here?

/CC @bouwew

@JeroenvIS
Copy link
Contributor Author

Last night I finally managed to get a dev checkout of home assistant core up & running, so ran it with my patch over night. With this change, the energy dashboard doesn't start the new day with a negative gas reading anymore. I consider the PR as tested now, so ticked the box for that.

I'm not sure why @bouwew made the change in the first place; what stands out to me in his PR is that there is a revert where the change from 'TOTAL_INCREASING' to 'TOTAL' is undone for single-directivity-interval sensors, but there the entities for the various intervals with gas readings (daily, weekly etc) are not reverted.

I believe that gas metering is always single direction, it's not like we can bore our own gas well in our back yard and start feeding natural gas back into the pipes ;-)

@bouwew
Copy link
Contributor

bouwew commented Jan 31, 2024

I made the change to TOTAL because these period-sensors all reset at the end of the period.
But, after re-reading https://developers.home-assistant.io/docs/core/entity/sensor#state-class-total_increasing the change proposed here, is also OK.

Key point in solving the issue is this: unless the difference is negative.
I had not expected that using TOTAL would cause a negative value at the beginning of a new interval. Apparently it does.
So good find and solution @JeroenvIS !

Copy link
Contributor

@bouwew bouwew left a comment

Choose a reason for hiding this comment

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

As stated in above comment, this change is OK, so approved.

@bouwew
Copy link
Contributor

bouwew commented Jan 31, 2024

@JeroenvIS can you please also update the relevant test-code?
You can find this code in the ..tests/components/huisbaasje directory.
See more detail in Details of the failed tests.

@JeroenvIS
Copy link
Contributor Author

Will do ASAP!

@bouwew
Copy link
Contributor

bouwew commented Jan 31, 2024

And please sign the CLA too. See here #108090 (review)

@JeroenvIS
Copy link
Contributor Author

And please sign the CLA too. See here #108090 (review)

CLA was signed 2 weeks ago, I believe that the bot also corrected the labels.

@JeroenvIS
Copy link
Contributor Author

OK, found the relevant test and updated it - I wasn't aware that pytest tests did not include the component tests. Now the pytest tests/components/huisbaasje/ passes.

@JeroenvIS JeroenvIS requested a review from bouwew January 31, 2024 13:08
@bouwew
Copy link
Contributor

bouwew commented Jan 31, 2024

@frenck this PR should be ready now.

Copy link
Contributor

@bouwew bouwew left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Thanks both! 👍

../Frenck

@frenck frenck merged commit 3bd1162 into home-assistant:dev Jan 31, 2024
23 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants