Skip to content

Commit

Permalink
Restart transport if stopped
Browse files Browse the repository at this point in the history
Sometimes this happens now with caching.
  • Loading branch information
declension committed Mar 27, 2019
1 parent a727c38 commit 351c3b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 7 additions & 3 deletions squeezealexa/squeezebox/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,13 @@ def _request(self, lines, raw=False, wait=True) -> List[str]:
first_word = (match.group(2) if match
else ' '.join(lines[0].split()[:2]))
if not (self.transport.is_connected or first_word == 'login'):
raise SqueezeboxException(
"Can't do '{cmd}', {transport} is not connected".format(
cmd=first_word, transport=self.transport))
try:
print_w("Transport wasn't connected - trying to restart")
self.transport.start()
except Exception:
raise SqueezeboxException(
"Can't do '{cmd}', {transport} is not connected".format(
cmd=first_word, transport=self.transport))

if self._debug:
print_d("<<<< " + "\n..<< ".join(lines))
Expand Down
14 changes: 6 additions & 8 deletions tests/squeezebox/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,15 @@ def test_track_details(self):
details = self.server.get_track_details()
assert ["Jamie Cullum"] == details['artist']

def test_disconnected_transport(self):
def test_disconnected_transport_reconnects(self):
self.transport.is_connected = False
with raises(SqueezeboxException) as e:
self.server._request(["foo"])
assert "Can't do 'foo'" in str(e)
self.server._request(["foo"])
assert self.transport.is_connected

def test_disconnected_transport_player_request(self):
def test_disconnected_transport_player_request_reconnects(self):
self.transport.is_connected = False
with raises(SqueezeboxException) as e:
self.server.player_request("foo", player_id=A_PLAYER_ID)
assert "Can't do 'foo'" in str(e)
self.server.player_request("foo", player_id=A_PLAYER_ID)
assert self.transport.is_connected


class TestServerWithStubbedTransport:
Expand Down

0 comments on commit 351c3b9

Please sign in to comment.