Hi there,
I’ve been struggling with setting up the connection to my Sony Android TV (KD-55X8505C) for a while now. I’ve tried the ADB Server approach and the Python ADB Implementation.
Both approaches end up in connection issues after running OK for around 3 hours.
You’ll find the debug logs attached. Do you have any advise what to do and how to fix it, based on the logs?
2020-01-29 03:19:02 DEBUG (SyncWorker_14) [androidtv.adb_manager] Sending command to 192.168.0.11:5555 via adb-shell: (dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\c' || echo '0\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\- STREAM_MUSIC:' -A 12
2020-01-29 03:19:02 DEBUG (SyncWorker_14) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xe2\x02\x00\x00\x19\xeb\x00\x00\xb0\xaf\xba\xb1'
2020-01-29 03:19:02 DEBUG (SyncWorker_14) [adb_shell.adb_device] bulk_write: b"shell:(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\\c' || echo '0\\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\\- STREAM_MUSIC:' -A 12\x00"
2020-01-29 03:19:03 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.sony_tv fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 281, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 271, in _adb_exception_catcher
return func(self, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 471, in update
) = self.aftv.update()
File "/usr/local/lib/python3.7/site-packages/androidtv/androidtv.py", line 79, in update
screen_on, awake, audio_state, wake_lock_size, current_app, media_session_state, device, is_volume_muted, volume = self.get_properties(lazy=True)
File "/usr/local/lib/python3.7/site-packages/androidtv/androidtv.py", line 225, in get_properties
output = self._adb.shell(constants.CMD_ANDROIDTV_PROPERTIES_LAZY)
File "/usr/local/lib/python3.7/site-packages/androidtv/adb_manager.py", line 165, in shell
return self._adb.shell(cmd)
File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 212, in shell
return b''.join(self._streaming_command(b'shell', command.encode('utf8'), timeout_s, total_timeout_s)).decode('utf8')
File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 506, in _streaming_command
local_id, remote_id = self._open(b'%s:%s' % (service, command), timeout_s, total_timeout_s)
File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 269, in _open
_, remote_id, their_local_id, _ = self._read([constants.OKAY], timeout_s, total_timeout_s)
File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 319, in _read
msg = self._handle.bulk_read(constants.MESSAGE_SIZE, timeout_s)
File "/usr/local/lib/python3.7/site-packages/adb_shell/tcp_handle.py", line 107, in bulk_read
return self._connection.recv(numbytes)
ConnectionResetError: [Errno 104] Connection reset by peer
2020-01-29 03:19:13 DEBUG (SyncWorker_8) [androidtv.adb_manager] Sending command to 192.168.0.11:5555 via adb-shell: (dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\c' || echo '0\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\- STREAM_MUSIC:' -A 12
2020-01-29 03:19:13 DEBUG (SyncWorker_8) [adb_shell.adb_device] bulk_write: b'OPEN\x01\x00\x00\x00\x00\x00\x00\x00\xe2\x02\x00\x00\x19\xeb\x00\x00\xb0\xaf\xba\xb1'
2020-01-29 03:19:13 ERROR (SyncWorker_8) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: [Errno 32] Broken pipe
2020-01-29 03:19:13 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.sony_tv fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 271, in _adb_exception_catcher
return func(self, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 471, in update
) = self.aftv.update()
File "/usr/local/lib/python3.7/site-packages/androidtv/androidtv.py", line 79, in update
screen_on, awake, audio_state, wake_lock_size, current_app, media_session_state, device, is_volume_muted, volume = self.get_properties(lazy=True)
File "/usr/local/lib/python3.7/site-packages/androidtv/androidtv.py", line 225, in get_properties
output = self._adb.shell(constants.CMD_ANDROIDTV_PROPERTIES_LAZY)
File "/usr/local/lib/python3.7/site-packages/androidtv/adb_manager.py", line 165, in shell
return self._adb.shell(cmd)
File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 212, in shell
return b''.join(self._streaming_command(b'shell', command.encode('utf8'), timeout_s, total_timeout_s)).decode('utf8')
File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 506, in _streaming_command
local_id, remote_id = self._open(b'%s:%s' % (service, command), timeout_s, total_timeout_s)
File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 268, in _open
self._send(msg, timeout_s)
File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 472, in _send
self._handle.bulk_write(msg.pack(), timeout_s)
File "/usr/local/lib/python3.7/site-packages/adb_shell/tcp_handle.py", line 136, in bulk_write
return self._connection.send(data)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 281, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 278, in _adb_exception_catcher
self.aftv.adb_close()
File "/usr/local/lib/python3.7/site-packages/androidtv/basetv.py", line 150, in adb_close
self._adb.close()
File "/usr/local/lib/python3.7/site-packages/androidtv/adb_manager.py", line 66, in close
self._adb.close()
File "/usr/local/lib/python3.7/site-packages/adb_shell/adb_device.py", line 95, in close
self._handle.close()
File "/usr/local/lib/python3.7/site-packages/adb_shell/tcp_handle.py", line 63, in close
self._connection.shutdown(socket.SHUT_RDWR)
OSError: [Errno 107] Socket not connected
2020-01-29 03:19:24 DEBUG (SyncWorker_12) [androidtv.adb_manager] ADB command not sent to 192.168.0.11:5555 because adb-shell connection is not established: (dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\c' && (dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\c' || echo '0\c')) && dumpsys power | grep Locks | grep 'size=' && CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP && (dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {' || echo) && dumpsys audio | grep '\- STREAM_MUSIC:' -A 12
I’ve noticed one main difference between the two approaches.
While the ADB Server approach seems trying to recover itself for a few seconds in between,
the Python ADB approach remains in broken / unavailable state.
It won’t connect anymore to my TV, but instead throws the above seen error message in my HA logs.
I’m running HASSio as Docker installation on RPi 4. Currently installed version is 103.3
RPi and TV are both connected to the network by wire.
Any help would be highly appreciated