Skip to content

Commit 7d38ff6

Browse files
committed
Add waiting_for_response property
1 parent 0053fc1 commit 7d38ff6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

plugwise_usb/messages/requests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(
105105
self._unsubscribe_node_response: Callable[[], None] | None = None
106106
self._response_timeout: TimerHandle | None = None
107107
self._response_future: Future[PlugwiseResponse] = self._loop.create_future()
108+
self._waiting_for_response = False
108109

109110
def __repr__(self) -> str:
110111
"""Convert request into writable str."""
@@ -195,12 +196,19 @@ def start_response_timeout(self) -> None:
195196
self._response_timeout = self._loop.call_later(
196197
NODE_TIME_OUT, self._response_timeout_expired
197198
)
199+
self._waiting_for_response = True
198200

199201
def stop_response_timeout(self) -> None:
200202
"""Stop timeout for node response."""
203+
self._waiting_for_response = True
201204
if self._response_timeout is not None:
202205
self._response_timeout.cancel()
203206

207+
@property
208+
def waiting_for_response(self) -> bool:
209+
"""Indicate if request is actively waiting for a response."""
210+
return self._waiting_for_response
211+
204212
def _response_timeout_expired(self, stick_timeout: bool = False) -> None:
205213
"""Handle response timeout."""
206214
if self._response_future.done():
@@ -232,6 +240,7 @@ def assign_error(self, error: BaseException) -> None:
232240
self._unsubscribe_from_node()
233241
if self._response_future.done():
234242
return
243+
self._waiting_for_response = False
235244
self._response_future.set_exception(error)
236245

237246
async def process_node_response(self, response: PlugwiseResponse) -> bool:

0 commit comments

Comments
 (0)