Skip to content

Commit

Permalink
Fix stats data being fetched for all entities when there are no energ…
Browse files Browse the repository at this point in the history
…y/water stat ids (home-assistant#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
  • Loading branch information
bdraco authored Feb 11, 2023
1 parent 4a10c72 commit a325d32
Showing 1 changed file with 44 additions and 36 deletions.
80 changes: 44 additions & 36 deletions src/data/energy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"]
)
: {}),
};
}

Expand Down

0 comments on commit a325d32

Please sign in to comment.