Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix IndexError in Opower #124478

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions homeassistant/components/opower/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
)

last_stat = await get_instance(self.hass).async_add_executor_job(
get_last_statistics, self.hass, 1, cost_statistic_id, True, set()
get_last_statistics, self.hass, 1, consumption_statistic_id, True, set()
)
if not last_stat:
_LOGGER.debug("Updating statistic for the first time")
Expand All @@ -124,7 +124,7 @@
cost_reads = await self._async_get_cost_reads(
account,
self.api.utility.timezone(),
last_stat[cost_statistic_id][0]["start"],
last_stat[consumption_statistic_id][0]["start"],
)
if not cost_reads:
_LOGGER.debug("No recent usage/cost data. Skipping update")
Expand All @@ -141,7 +141,7 @@
)
cost_sum = cast(float, stats[cost_statistic_id][0]["sum"])
consumption_sum = cast(float, stats[consumption_statistic_id][0]["sum"])
last_stats_time = stats[cost_statistic_id][0]["start"]
last_stats_time = stats[consumption_statistic_id][0]["start"]

Check warning on line 144 in homeassistant/components/opower/coordinator.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opower/coordinator.py#L144

Added line #L144 was not covered by tests

cost_statistics = []
consumption_statistics = []
Expand Down Expand Up @@ -187,7 +187,17 @@
else UnitOfVolume.CENTUM_CUBIC_FEET,
)

_LOGGER.debug(

Check warning on line 190 in homeassistant/components/opower/coordinator.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opower/coordinator.py#L190

Added line #L190 was not covered by tests
"Adding %s statistics for %s",
len(cost_statistics),
cost_statistic_id,
)
async_add_external_statistics(self.hass, cost_metadata, cost_statistics)
_LOGGER.debug(

Check warning on line 196 in homeassistant/components/opower/coordinator.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opower/coordinator.py#L196

Added line #L196 was not covered by tests
"Adding %s statistics for %s",
len(consumption_statistics),
consumption_statistic_id,
)
async_add_external_statistics(
self.hass, consumption_metadata, consumption_statistics
)
Expand Down