Import the cloud weigh-in history as long-term statistics - #3
Merged
Merged
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
….0.3 frenck's hacs/default review was against v1.0.0; the homeassistant floor and the README wording on body-composition/heart-rate sensors going unknown were already fixed by then. The remaining item was brand assets: custom_components/fitdays/brand/ held only a placeholder icon, no logo. Replace it with the real teal icon and logo (1x/2x, no dark variant needed) and update the README note that called it a placeholder.
The coordinator already downloads 400 days of measurements on every refresh and then kept only the newest one, so the recorder started every graph at install time. Issue #2 asked for the past readings. statistics.py groups each profile's history into hourly buckets per sensor and hands them to the recorder under the sensor's own entity id, min, max and mean per hour. It runs after the platforms are set up, because a statistics row is keyed by entity id. Re-importing an hour overwrites that row, so a restart rewrites rather than duplicates. Only sensors with a MEASUREMENT state class are backfilled; the counter and the timestamp sensors have no mean. Disabled entities are skipped. The import returns early when the recorder is not set up, which is why the manifest lists recorder under after_dependencies rather than dependencies. mean_type is used where the enum exists and has_mean otherwise: has_mean is the pre-2025.11 spelling and the recorder drops it in 2026.4. Closes #2 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Home Assistant 2026.9 logs a frame warning when async_import_statistics is called without unit_class, and the recorder stops accepting metadata without the key in 2026.11. Derive it from STATISTIC_UNIT_TO_UNIT_CONVERTER the way the recorder derives it, and skip the key on cores that predate it, so the 2024.11 floor in hacs.json still holds. Measured on the ha-dev instance (Home Assistant 2026.9, podman container ha-dev on nix1): before the change the metadata was accepted and the warning fired; after it the metadata carries unit_class 'mass' for a kg sensor, no warning appears, and the two hourly rows land in statistics_meta/statistics with min 80.0, max 81.0, mean 80.5 at 08:00 UTC and 79.5/79.5/79.5 at 09:00. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
AboveColin
force-pushed
the
feature/import-history
branch
from
September 15, 2026 12:33
cf9cf72 to
05aa0c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2. SteveJaye84 asked whether past scale reports can be pulled from the account, or whether only measurements taken after install are kept.
They already are pulled.
FitdaysClient.get_sync(days=HISTORY_DAYS)fetches 400 days on every 30-minute refresh, and the coordinator threw all of it away except the newest reading, so the recorder started each graph at install time.What this does
custom_components/fitdays/statistics.pygroups each profile's downloaded history into hourly buckets per sensor and callsasync_import_statisticswith the sensor's own entity id, writing min, max and mean per hour.measurements; the sensors still read onlylatest.async_setup_entry, afterasync_forward_entry_setups, because a statistics row is keyed by entity id and the entity id does not exist before the platform is set up.recorderunderafter_dependencies, notdependencies, so an installation without a recorder is not forced to load one. The import returns 0 whenrecorderis absent fromhass.config.components.Scope and limits, also written into the README
SensorStateClass.MEASUREMENTget a past; the measurement counter and the timestamp sensor do not.Compatibility
StatisticMetaDatachanged:has_meanis the pre-2025.11 spelling and the recorder drops it in 2026.4._metadatasetsmean_type=StatisticMeanType.ARITHMETICwhen the enum imports and falls back tohas_mean=Trueotherwise, so the 2024.11.0 floor inhacs.jsonstill holds.Receipts
async_import_statistics(hass, metadata, statistics),StatisticMetaDatanow carriesmean_typewithhas_meanmarked deprecated for removal in 2026.4, and_async_import_statisticsconverts a leftoverhas_meantomean_typeitself.StatisticData/StatisticMetaDatamodels with 5 synthetic measurements: 2 rows out, the 08:41 and 08:56 pair collapsing tomin=80.0 max=81.0 mean=80.5at 08:00 UTC, every start on the hour, rows sorted oldest first, and the rows with aNonetimestamp or aNonevalue dropped.ruff check custom_components/fitdays: all checks passed.ruff format: clean.Base
This branch starts at 26b0e1e, the v1.0.3 release commit, which is not an ancestor of
mainon GitHub.mainsits at a7679d3 with manifest version 1.0.2, so the release artwork and version bump never landed on the branch. Merging this PR brings that commit ontomainalong with the feature. That divergence predates this work.Manifest version bumped to 1.1.0.
🤖 Generated with Claude Code