Skip to content

Commit 8189bfa

Browse files
authored
Add logging to the custom sleep function (#115)
1 parent 8f218dc commit 8189bfa

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

custom_components/ta_cmi/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ async def custom_sleep(delay: int) -> None:
114114
await asyncio.sleep(delay)
115115
except asyncio.CancelledError:
116116
elapsed = time.time() - start
117+
_LOGGER.debug(
118+
"Sleep cancelled after %s. Sleep remaining time: %s",
119+
elapsed,
120+
delay - elapsed,
121+
)
117122
await asyncio.sleep(delay - elapsed)
118123

119124
async def _async_update_data(self) -> dict[str, Any]:

custom_components/ta_cmi/config_flow.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from __future__ import annotations
33

44
import asyncio
5+
from copy import deepcopy
56
from datetime import timedelta
67
import time
78
from typing import Any
8-
from copy import deepcopy
99

1010
from aiohttp import ClientSession
1111
from homeassistant import config_entries
@@ -103,7 +103,7 @@ def __init__(self) -> None:
103103
self.start_time: float = ConfigFlow.init_start_time
104104

105105
async def async_step_user(
106-
self, user_input: dict[str, Any] | None = None
106+
self, user_input: dict[str, Any] | None = None
107107
) -> FlowResult:
108108
"""Handle the initial step."""
109109
errors: dict[str, Any] = {}
@@ -145,7 +145,7 @@ async def async_step_user(
145145
)
146146

147147
async def async_step_devices(
148-
self, user_input: dict[str, Any] | None = None
148+
self, user_input: dict[str, Any] | None = None
149149
) -> FlowResult:
150150
"""Step for setup devices."""
151151
errors: dict[str, Any] = {}
@@ -203,14 +203,17 @@ async def async_step_devices(
203203
else:
204204
errors["base"] = "unknown"
205205
_LOGGER.exception("Unexpected exception: %s", err)
206+
break
206207
except RateLimitError:
207208
errors["base"] = "rate_limit"
209+
break
208210
except InvalidDeviceError:
209211
errors["base"] = "invalid_device"
210212
_LOGGER.warning("Invalid device: %s", dev.id)
211213
except Exception as err: # pylint: disable=broad-except
212214
_LOGGER.exception("Unexpected exception: %s", err)
213215
errors["base"] = "unknown"
216+
break
214217
else:
215218
devices_list[dev.id] = str(dev)
216219

@@ -232,7 +235,7 @@ def _generate_channel_types(self) -> list[str]:
232235
return [x.title() for x in DEVICE_TYPE_STRING_MAP.values()]
233236

234237
async def async_step_channel(
235-
self, user_input: dict[str, Any] | None = None
238+
self, user_input: dict[str, Any] | None = None
236239
) -> FlowResult:
237240
"""Step for setup channels."""
238241

@@ -294,7 +297,7 @@ async def async_step_finish(self) -> FlowResult:
294297
@staticmethod
295298
@callback
296299
def async_get_options_flow(
297-
config_entry: config_entries.ConfigEntry,
300+
config_entry: config_entries.ConfigEntry,
298301
) -> OptionsFlowHandler:
299302
"""Get the options flow for this handler."""
300303
return OptionsFlowHandler(config_entry)
@@ -327,7 +330,7 @@ def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
327330
self.data = dict(self.config_entry.data)
328331

329332
async def async_step_init(
330-
self, user_input: dict[str, Any] | None = None
333+
self, user_input: dict[str, Any] | None = None
331334
) -> FlowResult:
332335
"""Handle options flow."""
333336

@@ -343,9 +346,7 @@ async def async_step_init(
343346
try:
344347
tmp = deepcopy(self.data)
345348
tmp[CONF_HOST] = user_input[CONF_HOST]
346-
await validate_login(
347-
tmp, async_get_clientsession(self.hass)
348-
)
349+
await validate_login(tmp, async_get_clientsession(self.hass))
349350
except CannotConnect:
350351
errors["base"] = "cannot_connect"
351352
except InvalidAuth:

0 commit comments

Comments
 (0)