Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions homeassistant/components/media_player/samsungtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,25 @@ def send_key(self, key):
_LOGGER.info("TV is powering off, not sending command: %s", key)
return
try:
self.get_remote().control(key)
# recreate connection if connection was dead
retry_count = 1
for _ in range(retry_count + 1):
try:
self.get_remote().control(key)
break
except (self._exceptions_class.ConnectionClosed,
BrokenPipeError):
# BrokenPipe can occur when the commands is sent to fast
self._remote = None
self._state = STATE_ON
except (self._exceptions_class.UnhandledResponse,
self._exceptions_class.AccessDenied, BrokenPipeError):
self._exceptions_class.AccessDenied):
# We got a response so it's on.
# BrokenPipe can occur when the commands is sent to fast
self._state = STATE_ON
self._remote = None
_LOGGER.debug("Failed sending command %s", key, exc_info=True)
return
except (self._exceptions_class.ConnectionClosed, OSError):
except OSError:
self._state = STATE_OFF
self._remote = None
if self._power_off_in_progress():
Expand Down Expand Up @@ -207,6 +216,7 @@ def turn_off(self):
# Force closing of remote session to provide instant UI feedback
try:
self.get_remote().close()
self._remote = None
except OSError:
_LOGGER.debug("Could not establish connection.")

Expand Down