From f7eb49df0cc9c1a75a808aa4ac09e986e4465d8b Mon Sep 17 00:00:00 2001 From: wlcrs Date: Sat, 24 Dec 2022 07:52:48 +0000 Subject: [PATCH] Use zip_longest to fix behavior when no config_update_coordinators are present --- diagnostics.py | 5 ++++- sensor.py | 3 ++- switch.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/diagnostics.py b/diagnostics.py index 4e5a3b4..066134c 100644 --- a/diagnostics.py +++ b/diagnostics.py @@ -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 @@ -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) diff --git a/sensor.py b/sensor.py index d1d977c..e0ad6c2 100644 --- a/sensor.py +++ b/sensor.py @@ -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, @@ -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] = [] diff --git a/switch.py b/switch.py index 029f446..e34d186 100644 --- a/switch.py +++ b/switch.py @@ -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) @@ -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