Request one data point in statistics_during_period in Opower (#124480)

This commit is contained in:
tronikos 2024-09-07 01:47:27 -07:00 committed by GitHub
parent cbd884d54a
commit 17994ff245
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -128,19 +128,22 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]):
if not cost_reads:
_LOGGER.debug("No recent usage/cost data. Skipping update")
continue
start = cost_reads[0].start_time
_LOGGER.debug("Getting statistics at: %s", start)
stats = await get_instance(self.hass).async_add_executor_job(
statistics_during_period,
self.hass,
cost_reads[0].start_time,
None,
start,
start + timedelta(seconds=1),
{cost_statistic_id, consumption_statistic_id},
"hour" if account.meter_type == MeterType.ELEC else "day",
"hour",
None,
{"sum"},
)
cost_sum = cast(float, stats[cost_statistic_id][0]["sum"])
consumption_sum = cast(float, stats[consumption_statistic_id][0]["sum"])
last_stats_time = stats[consumption_statistic_id][0]["start"]
assert last_stats_time == start.timestamp()
cost_statistics = []
consumption_statistics = []