Skip to content

Commit

Permalink
Handle StorageError in the Broadlink integration (#35986)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipediel authored and frenck committed May 24, 2020
1 parent 47995ed commit 1feb8ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions homeassistant/components/broadlink/__init__.py
Expand Up @@ -6,7 +6,7 @@
import logging
import re

from broadlink.exceptions import BroadlinkException, ReadError
from broadlink.exceptions import BroadlinkException, ReadError, StorageError
import voluptuous as vol

from homeassistant.const import CONF_HOST
Expand Down Expand Up @@ -85,10 +85,11 @@ async def async_learn_command(call):
_LOGGER.info("Press the key you want Home Assistant to learn")
start_time = utcnow()
while (utcnow() - start_time) < timedelta(seconds=20):
await asyncio.sleep(1)
try:
packet = await device.async_request(device.api.check_data)
except ReadError:
await asyncio.sleep(1)
except (ReadError, StorageError):
continue
except BroadlinkException as err_msg:
_LOGGER.error("Failed to learn: %s", err_msg)
return
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/broadlink/remote.py
Expand Up @@ -14,6 +14,7 @@
BroadlinkException,
DeviceOfflineError,
ReadError,
StorageError,
)
import voluptuous as vol

Expand Down Expand Up @@ -321,10 +322,11 @@ async def _async_capture_code(self, command, timeout):
code = None
start_time = utcnow()
while (utcnow() - start_time) < timedelta(seconds=timeout):
await asyncio.sleep(1)
try:
code = await self.device.async_request(self.device.api.check_data)
except ReadError:
await asyncio.sleep(1)
except (ReadError, StorageError):
continue
else:
break

Expand Down

0 comments on commit 1feb8ad

Please sign in to comment.