mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Small cleanups to list_statistic_ids (#124451)
This commit is contained in:
parent
d94b1e6e8a
commit
242aae514e
@ -640,32 +640,31 @@ def list_statistic_ids(
|
|||||||
result: dict[str, StatisticMetaData] = {}
|
result: dict[str, StatisticMetaData] = {}
|
||||||
|
|
||||||
for state in entities:
|
for state in entities:
|
||||||
state_class = state.attributes[ATTR_STATE_CLASS]
|
entity_id = state.entity_id
|
||||||
state_unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
if statistic_ids is not None and entity_id not in statistic_ids:
|
||||||
|
continue
|
||||||
|
|
||||||
|
attributes = state.attributes
|
||||||
|
state_class = attributes[ATTR_STATE_CLASS]
|
||||||
provided_statistics = DEFAULT_STATISTICS[state_class]
|
provided_statistics = DEFAULT_STATISTICS[state_class]
|
||||||
if statistic_type is not None and statistic_type not in provided_statistics:
|
if statistic_type is not None and statistic_type not in provided_statistics:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if statistic_ids is not None and state.entity_id not in statistic_ids:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
"sum" in provided_statistics
|
(has_sum := "sum" in provided_statistics)
|
||||||
and ATTR_LAST_RESET not in state.attributes
|
and ATTR_LAST_RESET not in attributes
|
||||||
and state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
and state_class == SensorStateClass.MEASUREMENT
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result[state.entity_id] = {
|
result[entity_id] = {
|
||||||
"has_mean": "mean" in provided_statistics,
|
"has_mean": "mean" in provided_statistics,
|
||||||
"has_sum": "sum" in provided_statistics,
|
"has_sum": has_sum,
|
||||||
"name": None,
|
"name": None,
|
||||||
"source": RECORDER_DOMAIN,
|
"source": RECORDER_DOMAIN,
|
||||||
"statistic_id": state.entity_id,
|
"statistic_id": entity_id,
|
||||||
"unit_of_measurement": state_unit,
|
"unit_of_measurement": attributes.get(ATTR_UNIT_OF_MEASUREMENT),
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user