Add debug logging in get_cost_reads in opower (#124473)

Add debug statements in get_cost_reads in opower
This commit is contained in:
tronikos 2024-09-04 11:30:24 -07:00 committed by GitHub
parent c4c8e74a8a
commit c2b24dd355
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -236,9 +236,11 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]):
else:
start = datetime.fromtimestamp(start_time, tz=tz) - timedelta(days=30)
end = dt_util.now(tz)
_LOGGER.debug("Getting monthly cost reads: %s - %s", start, end)
cost_reads = await self.api.async_get_cost_reads(
account, AggregateType.BILL, start, end
)
_LOGGER.debug("Got %s monthly cost reads", len(cost_reads))
if account.read_resolution == ReadResolution.BILLING:
return cost_reads
@ -249,9 +251,11 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]):
start = cost_reads[0].start_time
assert start
start = max(start, end - timedelta(days=3 * 365))
_LOGGER.debug("Getting daily cost reads: %s - %s", start, end)
daily_cost_reads = await self.api.async_get_cost_reads(
account, AggregateType.DAY, start, end
)
_LOGGER.debug("Got %s daily cost reads", len(daily_cost_reads))
_update_with_finer_cost_reads(cost_reads, daily_cost_reads)
if account.read_resolution == ReadResolution.DAY:
return cost_reads
@ -261,8 +265,11 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]):
else:
assert start
start = max(start, end - timedelta(days=2 * 30))
_LOGGER.debug("Getting hourly cost reads: %s - %s", start, end)
hourly_cost_reads = await self.api.async_get_cost_reads(
account, AggregateType.HOUR, start, end
)
_LOGGER.debug("Got %s hourly cost reads", len(hourly_cost_reads))
_update_with_finer_cost_reads(cost_reads, hourly_cost_reads)
_LOGGER.debug("Got %s cost reads", len(cost_reads))
return cost_reads