Small cleanups to list_statistic_ids (#124451)
parent
d94b1e6e8a
commit
242aae514e
|
@ -640,32 +640,31 @@ def list_statistic_ids(
|
|||
result: dict[str, StatisticMetaData] = {}
|
||||
|
||||
for state in entities:
|
||||
state_class = state.attributes[ATTR_STATE_CLASS]
|
||||
state_unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
entity_id = state.entity_id
|
||||
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]
|
||||
if statistic_type is not None and statistic_type not in provided_statistics:
|
||||
continue
|
||||
|
||||
if statistic_ids is not None and state.entity_id not in statistic_ids:
|
||||
continue
|
||||
|
||||
if (
|
||||
"sum" in provided_statistics
|
||||
and ATTR_LAST_RESET not in state.attributes
|
||||
and state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||
(has_sum := "sum" in provided_statistics)
|
||||
and ATTR_LAST_RESET not in attributes
|
||||
and state_class == SensorStateClass.MEASUREMENT
|
||||
):
|
||||
continue
|
||||
|
||||
result[state.entity_id] = {
|
||||
result[entity_id] = {
|
||||
"has_mean": "mean" in provided_statistics,
|
||||
"has_sum": "sum" in provided_statistics,
|
||||
"has_sum": has_sum,
|
||||
"name": None,
|
||||
"source": RECORDER_DOMAIN,
|
||||
"statistic_id": state.entity_id,
|
||||
"unit_of_measurement": state_unit,
|
||||
"statistic_id": entity_id,
|
||||
"unit_of_measurement": attributes.get(ATTR_UNIT_OF_MEASUREMENT),
|
||||
}
|
||||
continue
|
||||
|
||||
return result
|
||||
|
||||
|
|
Loading…
Reference in New Issue