Skip to content

Commit 7690e6c

Browse files
committed
fix: check connection state before sending command
AndroidTVRemote.send_key_command doesn't always raise ConnectionClosed Relates to #28
1 parent 0008322 commit 7690e6c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

intg-androidtv/tv.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,17 @@ async def _send_command(self, keycode: int | str, action: KeyPress = KeyPress.SH
420420
else:
421421
direction = "SHORT"
422422

423+
if self.is_on is None:
424+
return ucapi.StatusCodes.SERVICE_UNAVAILABLE
425+
426+
# workaround for "swallowed commands" since _atv.send_key_command doesn't provide a result
427+
# pylint: disable=W0212
428+
if (
429+
not (self._atv._remote_message_protocol and self._atv._remote_message_protocol.transport)
430+
or self._atv._remote_message_protocol.transport.is_closing()
431+
):
432+
return ucapi.StatusCodes.SERVICE_UNAVAILABLE
433+
423434
self._atv.send_key_command(keycode, direction)
424435

425436
if action == KeyPress.DOUBLE_CLICK:

0 commit comments

Comments
 (0)