|
1 | 1 | """Config flow for Technische Alternative C.M.I. integration."""
|
2 | 2 | from __future__ import annotations
|
3 | 3 |
|
4 |
| -import asyncio |
5 | 4 | from copy import deepcopy
|
6 | 5 | from datetime import timedelta
|
7 | 6 | import time
|
|
15 | 14 | from homeassistant.exceptions import HomeAssistantError
|
16 | 15 | from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
17 | 16 | import homeassistant.helpers.config_validation as cv
|
18 |
| -from ta_cmi import ( |
19 |
| - CMI, |
20 |
| - ApiError, |
21 |
| - Device, |
22 |
| - InvalidCredentialsError, |
23 |
| - InvalidDeviceError, |
24 |
| - RateLimitError, |
25 |
| -) |
| 17 | +from ta_cmi import CMI, ApiError, Device, InvalidCredentialsError, RateLimitError |
26 | 18 | import voluptuous as vol
|
27 | 19 |
|
| 20 | +from . import custom_sleep |
28 | 21 | from .const import (
|
29 | 22 | _LOGGER,
|
30 | 23 | CONF_CHANNELS,
|
@@ -69,13 +62,13 @@ async def fetch_device(device: Device, retry=False) -> None:
|
69 | 62 | _LOGGER.debug(
|
70 | 63 | f"Sleep mode for {DEVICE_DELAY} seconds to prevent rate limiting"
|
71 | 64 | )
|
72 |
| - await asyncio.sleep(DEVICE_DELAY) |
| 65 | + await custom_sleep(DEVICE_DELAY) |
73 | 66 | device.set_device_type("DUMMY-NO-IO")
|
74 | 67 |
|
75 | 68 | _LOGGER.debug("Try to fetch device type: %s", device.id)
|
76 | 69 | await device.fetch_type()
|
77 | 70 | _LOGGER.debug(f"Sleep mode for {DEVICE_DELAY} seconds to prevent rate limiting")
|
78 |
| - await asyncio.sleep(DEVICE_DELAY) |
| 71 | + await custom_sleep(DEVICE_DELAY) |
79 | 72 |
|
80 | 73 | _LOGGER.debug("Try to fetch available device channels: %s", device.id)
|
81 | 74 | await device.update()
|
@@ -189,7 +182,7 @@ async def async_step_devices(
|
189 | 182 | _LOGGER.debug(
|
190 | 183 | f"Sleep mode for {DEVICE_DELAY} seconds to prevent rate limiting"
|
191 | 184 | )
|
192 |
| - await asyncio.sleep(DEVICE_DELAY) |
| 185 | + await custom_sleep(DEVICE_DELAY) |
193 | 186 |
|
194 | 187 | try:
|
195 | 188 | await fetch_device(dev)
|
@@ -291,7 +284,7 @@ async def async_step_finish(self) -> FlowResult:
|
291 | 284 | end_time = time.time()
|
292 | 285 | time_lapsed = end_time - self.start_time
|
293 | 286 | if time_lapsed <= DEVICE_DELAY:
|
294 |
| - await asyncio.sleep(DEVICE_DELAY - time_lapsed) |
| 287 | + await custom_sleep(int(DEVICE_DELAY - time_lapsed)) |
295 | 288 | return self.async_create_entry(title="C.M.I", data=self.config)
|
296 | 289 |
|
297 | 290 | @staticmethod
|
|
0 commit comments