Skip to content

Commit

Permalink
Handle TimeoutError
Browse files Browse the repository at this point in the history
  • Loading branch information
rrooggiieerr committed May 12, 2023
1 parent db9fb11 commit b1d6c1d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions custom_components/benqprojector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ def __init__(self, hass, serial_port: str, baud_rate: int):
self.projector = BenQProjector(self._serial_port, baud_rate)

async def connect(self):
if not self.projector.connect():
try:
if not self.projector.connect():
raise ConfigEntryNotReady(
f"Unable to connect to BenQ projector on {self._serial_port}"
)
except TimeoutError as ex:
raise ConfigEntryNotReady(
f"Unable to connect to BenQ projector on {self._serial_port}"
f"Unable to connect to BenQ projector on {self._serial_port}", ex
)


self.unique_id = self.projector.unique_id
self.model = self.projector.model
Expand Down Expand Up @@ -142,8 +148,13 @@ async def _async_update_data(self):
"""Fetch data from BenQ Projector."""
_LOGGER.debug("BenQProjectorCoordinator._async_updadatata")

if not self.projector.update_power():
return None
try:
if not self.projector.update_power():
return None
except TimeoutError as ex:
raise UpdateFailed(
f"Error communicating with BenQ projector on {self._serial_port}", ex
)

power_status = self.projector.power_status
if power_status is None:
Expand Down

0 comments on commit b1d6c1d

Please sign in to comment.