Skip to content

Commit

Permalink
Use zip_longest to fix behavior when no config_update_coordinators ar…
Browse files Browse the repository at this point in the history
…e present
  • Loading branch information
wlcrs committed Dec 24, 2022
1 parent f6b6fdd commit f7eb49d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Diagnostics support for Velbus."""
from __future__ import annotations

from itertools import zip_longest
from typing import Any

from homeassistant.components.diagnostics import async_redact_data
Expand Down Expand Up @@ -36,7 +37,9 @@ async def async_get_config_entry_diagnostics(
diagnostics_data = {
"config_entry_data": async_redact_data(dict(entry.data), TO_REDACT)
}
for coordinator, config_coordinator in zip(coordinators, config_coordinators):
for coordinator, config_coordinator in zip_longest(
coordinators, config_coordinators
):
diagnostics_data[
f"slave_{coordinator.bridge.slave_id}"
] = await _build_bridge_diagnostics_info(coordinator.bridge)
Expand Down
3 changes: 2 additions & 1 deletion sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any, Union
from itertools import zip_longest

from homeassistant.components.sensor import (
SensorDeviceClass,
Expand Down Expand Up @@ -682,7 +683,7 @@ async def async_setup_entry(

entities_to_add: list[SensorEntity] = []
for idx, (update_coordinator, configuration_update_coordinator) in enumerate(
zip(update_coordinators, configuration_update_coordinators)
zip_longest(update_coordinators, configuration_update_coordinators)
):
slave_entities: list[HuaweiSolarSensorEntity] = []

Expand Down
4 changes: 2 additions & 2 deletions switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _handle_coordinator_update(self) -> None:

async def async_turn_on(self, **kwargs) -> None:
"""Turn the setting on."""
with self._change_lock:
async with self._change_lock:

await self.bridge.set(rn.STARTUP, 0)

Expand All @@ -264,7 +264,7 @@ async def async_turn_on(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs) -> None:
"""Turn the setting off."""

with self._change_lock:
async with self._change_lock:
await self.bridge.set(rn.SHUTDOWN, 0)

# Turning on can take up to 5 minutes... We'll poll every 15 seconds
Expand Down

0 comments on commit f7eb49d

Please sign in to comment.