Starlink's Energy, Download and Upload accumulation using RestoreSensor
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:
- [ ] Documentation added/updated for www.home-assistant.io
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 runningpython3 -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:
- [x] I have reviewed two other open pull requests in this repository.
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 closeCloses the pull request. -
@home-assistant rename Awesome new titleRenames the pull request. -
@home-assistant reopenReopen the pull request. -
@home-assistant unassign starlinkRemoves the current integration label and assignees on the pull request, add the integration domain after the command. -
@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the pull request. -
@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.
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?
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(fromcoordinator.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.
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
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.
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
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. 😉
Could someone please fix the label? I accidentally selected the wrong change type when creating the PR.
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!
Keep Alive
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.
Hey, thanks for the review and commit of the suggested changes. 🚀