From 17994ff245cc32dd27a8455e49cf530feb5383b6 Mon Sep 17 00:00:00 2001 From: tronikos Date: Sat, 7 Sep 2024 01:47:27 -0700 Subject: [PATCH] Request one data point in statistics_during_period in Opower (#124480) --- homeassistant/components/opower/coordinator.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/opower/coordinator.py b/homeassistant/components/opower/coordinator.py index 1e00243f6573f0..cd2e28ed63850f 100644 --- a/homeassistant/components/opower/coordinator.py +++ b/homeassistant/components/opower/coordinator.py @@ -128,19 +128,22 @@ async def _insert_statistics(self) -> None: 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 = []