core icon indicating copy to clipboard operation
core copied to clipboard

Starlink's Energy, Download and Upload accumulation using RestoreSensor

Open davidrapan opened this issue 11 months ago • 3 comments

Proposed change

Proposed change should tackle #137541 by implementing RestoreSensor and by ignoring terminal's history stats from last ~15m right after HA restarts...

Type of change

  • [ ] Dependency upgrade
  • [x] 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

  • This PR fixes or closes issue: fixes #137541
  • This PR is related to issue: #137541
  • Link to documentation pull request: https://github.com/home-assistant/home-assistant.io/pull/37416
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • [x] The code change is tested and works locally.
  • [x] Local tests pass. Your PR cannot be merged unless tests pass
  • [x] There is no commented out code in this PR.
  • [x] I have followed the development checklist
  • [x] I have followed the perfect PR recommendations
  • [x] The code has been formatted using Ruff (ruff format homeassistant tests)
  • [x] 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:

  • [x] The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • [x] New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • [x] 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:

davidrapan avatar Feb 08 '25 14:02 davidrapan

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

Code owner commands

Code owners of starlink 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 starlink 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.

home-assistant[bot] avatar Feb 08 '25 14:02 home-assistant[bot]

So what is exactly going wrong? What data is off? I think I understand that we do some aggregation in the library but why would a restore sensor fix this?

joostlek avatar Apr 10 '25 22:04 joostlek

Hi @joostlek, the current implementation aggregates duplicate data records from the last 15 minutes on every HA restart.

  • The new improved reimplementation fixes this and also moves the logic into sensor.py (from coordinator.py) for better clarity.
  • Aggregation requires a separate class from the regular sensor, and I simply chose RestoreSensor for quality of life reasons.

Edit: I noticed that I have selected incorrect Type of Change.

davidrapan avatar Apr 29 '25 10:04 davidrapan

So to put the question the other way around, why do we aggregate data and why don't we not do that? Because ideally users aggregate themselves. This being an aggregate also means that values are not comparable, hence you opened this PR and issue

joostlek avatar May 14 '25 15:05 joostlek

This being an aggregate also means that values are not comparable, hence you opened this PR and issue

No, I know because I wrote it.

I'm not sure I follow, For example, I consider the energy sensor a basic necessity and I would say that users expect it to ideally be there. Furthermore, the sampling that this is calculated with now is shorter than 5 s thus more precise.

davidrapan avatar May 14 '25 23:05 davidrapan

Can confirm, we are providing an aggregate sensor to match the bare minimum info exposed by the Starlink app. I think it's unreasonable for such a fundamental sensor to need extra setup from end users

boswelja avatar May 14 '25 23:05 boswelja

Exactly, it would simply be something that every user would do (have to do).

But I understand your point @joostlek, if we had something like blueprints for helpers that could even be, let's say, connected to integrations or something. I would be a pro for that too, but now it's calculated from samples directly from the dish, which is simply better. 😉

davidrapan avatar May 16 '25 21:05 davidrapan

Could someone please fix the label? I accidentally selected the wrong change type when creating the PR.

davidrapan avatar Jun 23 '25 13:06 davidrapan

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes. Thank you for your contribution!

github-actions[bot] avatar Aug 22 '25 14:08 github-actions[bot]

Keep Alive

davidrapan avatar Aug 22 '25 17:08 davidrapan

The aggregation happens in the library, but it needs help from core at startup to keep track of previously aggregated data. I think that's OK.

emontnemery avatar Aug 28 '25 08:08 emontnemery

Hey, thanks for the review and commit of the suggested changes. 🚀

davidrapan avatar Aug 28 '25 16:08 davidrapan