Skip to content

Commit 364097a

Browse files
authored
Poll for new status (#23)
1 parent 0e2848e commit 364097a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

hole/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,14 @@ async def enable(self):
7979
try:
8080
async with async_timeout.timeout(5):
8181
response = await self._session.get(self.base_url, params=params)
82+
_LOGGER.debug("Response from *hole: %s", response.status)
8283

83-
_LOGGER.debug("Response from *hole: %s", response.status)
84-
data = await response.json()
84+
while self.status != "enabled":
85+
_LOGGER.debug("Awaiting status to be enabled")
86+
await self.get_data()
87+
await asyncio.sleep(0.01)
88+
89+
data = self.status
8590
_LOGGER.debug(data)
8691

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

102-
_LOGGER.debug("Response from *hole: %s", response.status)
103-
data = await response.json()
108+
while self.status != "disabled":
109+
_LOGGER.debug("Awaiting status to be disabled")
110+
await self.get_data()
111+
await asyncio.sleep(0.01)
112+
113+
data = self.status
104114
_LOGGER.debug(data)
105115

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

0 commit comments

Comments
 (0)