Skip to content

Commit

Permalink
Fix infinite loop on init
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe committed Nov 13, 2024
1 parent 2007aba commit fd95fd7
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions custom_components/eurotronic_cometblue/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,40 @@ async def send_command(
raise ServiceValidationError(
f"Invalid payload '{payload}' for '{caller_entity_id}': {ex}"
) from ex
return None

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

retry_count = 0
retrieved_temperatures = {}
battery = 0
holiday = {}

while retry_count < RETRY_COUNT:
retrieved_temperatures: dict | None = None
battery: int | None = None
holiday: dict | None = None

while (
retry_count < RETRY_COUNT
and retrieved_temperatures is None
and battery is None
and holiday is None
):
try:
async with self.device:
if not self.device.connected:
raise ConfigEntryNotReady(
f"Failed to connect to '{self.device.device.address}'"
)
# temperatures are required and must trigger a retry if not available
retrieved_temperatures = await self.device.get_temperature_async()
if not retrieved_temperatures:
retrieved_temperatures = (
await self.device.get_temperature_async()
)
# battery and holiday are optional and should not trigger a retry
try:
battery = await self.device.get_battery_async()
holiday = await self.device.get_holiday_async(1)
if battery is None:
battery = await self.device.get_battery_async()
if not holiday:
holiday = await self.device.get_holiday_async(1) or {}
except InvalidByteValueError as ex:
LOGGER.warning(
"Failed to retrieve optional data: %s (%s)",
Expand Down

0 comments on commit fd95fd7

Please sign in to comment.