Fix stats data being fetched for all entities when there are no energy/water stat ids (#15428)

* Fix stats data being fetched for all entities when there are no energy/water stat ids

I noticed the following query was being sent
to the stats api since there were no water
stat ids. Since it sent an empty list it
enumerated everything

```
{
type: "recorder/statistics_during_period",
start_time: "2023-02-05T05:00:00.000Z",
end_time: "2023-02-12T05:59:59.999Z"
....
statistic_ids: [],
type: "recorder/statistics_during_period"
types: ["sum"]
units: {volume: "gal"}
}
```

* not python
This commit is contained in:
J. Nick Koston 2023-02-11 16:43:20 -06:00 committed by GitHub
parent 4a10c722ab
commit a325d32d09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -406,24 +406,28 @@ const getEnergyData = async (
};
const stats = {
...(await fetchStatistics(
hass!,
startMinHour,
end,
energyStatIds,
period,
energyUnits,
["sum"]
)),
...(await fetchStatistics(
hass!,
startMinHour,
end,
waterStatIds,
period,
waterUnits,
["sum"]
)),
...(energyStatIds.length
? await fetchStatistics(
hass!,
startMinHour,
end,
energyStatIds,
period,
energyUnits,
["sum"]
)
: {}),
...(waterStatIds.length
? await fetchStatistics(
hass!,
startMinHour,
end,
waterStatIds,
period,
waterUnits,
["sum"]
)
: {}),
};
let statsCompare;
@ -441,24 +445,28 @@ const getEnergyData = async (
endCompare = addMilliseconds(start, -1);
statsCompare = {
...(await fetchStatistics(
hass!,
compareStartMinHour,
endCompare,
energyStatIds,
period,
energyUnits,
["sum"]
)),
...(await fetchStatistics(
hass!,
compareStartMinHour,
endCompare,
waterStatIds,
period,
waterUnits,
["sum"]
)),
...(energyStatIds.length
? await fetchStatistics(
hass!,
compareStartMinHour,
endCompare,
energyStatIds,
period,
energyUnits,
["sum"]
)
: {}),
...(waterStatIds.length
? await fetchStatistics(
hass!,
compareStartMinHour,
endCompare,
waterStatIds,
period,
waterUnits,
["sum"]
)
: {}),
};
}