Skip to content

Commit

Permalink
Poll for new status (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
natefox authored Nov 1, 2024
1 parent 0e2848e commit 364097a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions hole/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ async def enable(self):
try:
async with async_timeout.timeout(5):
response = await self._session.get(self.base_url, params=params)
_LOGGER.debug("Response from *hole: %s", response.status)

_LOGGER.debug("Response from *hole: %s", response.status)
data = await response.json()
while self.status != "enabled":
_LOGGER.debug("Awaiting status to be enabled")
await self.get_data()
await asyncio.sleep(0.01)

data = self.status
_LOGGER.debug(data)

except (asyncio.TimeoutError, aiohttp.ClientError, socket.gaierror):
Expand All @@ -98,9 +103,14 @@ async def disable(self, duration=True):
try:
async with async_timeout.timeout(5):
response = await self._session.get(self.base_url, params=params)
_LOGGER.debug("Response from *hole: %s", response.status)

_LOGGER.debug("Response from *hole: %s", response.status)
data = await response.json()
while self.status != "disabled":
_LOGGER.debug("Awaiting status to be disabled")
await self.get_data()
await asyncio.sleep(0.01)

data = self.status
_LOGGER.debug(data)

except (asyncio.TimeoutError, aiohttp.ClientError, socket.gaierror):
Expand Down

0 comments on commit 364097a

Please sign in to comment.