Skip to content

Commit fd95fd7

Browse files
committed
Fix infinite loop on init
1 parent 2007aba commit fd95fd7

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

custom_components/eurotronic_cometblue/coordinator.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,40 @@ async def send_command(
8989
raise ServiceValidationError(
9090
f"Invalid payload '{payload}' for '{caller_entity_id}': {ex}"
9191
) from ex
92+
return None
9293

9394
async def _async_update_data(self) -> dict[str, bytes]:
9495
"""Poll the device."""
9596
data: dict = {}
9697

9798
retry_count = 0
98-
retrieved_temperatures = {}
99-
battery = 0
100-
holiday = {}
101-
102-
while retry_count < RETRY_COUNT:
99+
retrieved_temperatures: dict | None = None
100+
battery: int | None = None
101+
holiday: dict | None = None
102+
103+
while (
104+
retry_count < RETRY_COUNT
105+
and retrieved_temperatures is None
106+
and battery is None
107+
and holiday is None
108+
):
103109
try:
104110
async with self.device:
105111
if not self.device.connected:
106112
raise ConfigEntryNotReady(
107113
f"Failed to connect to '{self.device.device.address}'"
108114
)
109115
# temperatures are required and must trigger a retry if not available
110-
retrieved_temperatures = await self.device.get_temperature_async()
116+
if not retrieved_temperatures:
117+
retrieved_temperatures = (
118+
await self.device.get_temperature_async()
119+
)
111120
# battery and holiday are optional and should not trigger a retry
112121
try:
113-
battery = await self.device.get_battery_async()
114-
holiday = await self.device.get_holiday_async(1)
122+
if battery is None:
123+
battery = await self.device.get_battery_async()
124+
if not holiday:
125+
holiday = await self.device.get_holiday_async(1) or {}
115126
except InvalidByteValueError as ex:
116127
LOGGER.warning(
117128
"Failed to retrieve optional data: %s (%s)",

0 commit comments

Comments
 (0)