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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor refactoring of periodic statistics #56492
Conversation
# Set meta data | ||
result[entity_id]["meta"] = { | ||
meta: StatisticMetaData = { | ||
"statistic_id": entity_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to allow integrations to define their own statistic IDs when importing? I guess we can, but we should enforce it starts with <domain>-
"unit_of_measurement": unit, | ||
"has_mean": "mean" in wanted_statistics[entity_id], | ||
"has_sum": "sum" in wanted_statistics[entity_id], | ||
} | ||
|
||
# Make calculations | ||
stat: dict = {} | ||
stat: StatisticData = {"start": start} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what's not so cool about TypedDict: handling of optional fields.
"""Statistic data class.""" | ||
|
||
meta: StatisticMetaData | ||
stat: tuple[StatisticData, ...] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be an Iterable
, not a tuple
.
The purpose is to allow inserting multiple datapoints for unchanged metadata, for example a day's or month's worth of hourly updates and not have to lookup the metadata already stored in the database for each point.
Proposed change
Minor refactoring of periodic statistics to prepare for import of statistics
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: