That seems to happen from time to time, maybe once a week to once a month if I had to guess. Aside from toggling ADB off and then back on, restarting the device should fix it.
If someone posts a debug log, Iâll take a look. But that might just be the way it is.
Iâm having a few problems with AndroidTV (in my case a TV-Stick from german provider Telekom) for a few months now, but since a few days ago, I have one more error message, that annoys me very much, as it comes up a lot (meaning yesterday within 15 hours around 6000 messages in the logâŚ).
So here we go, I got a few error messages:
This is the ânew oneâ
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 272, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 463, in async_device_update
await self.async_update() # type: ignore
File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 357, in _adb_exception_catcher
return await func(self, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 658, in async_update
) = await self.aftv.update(self._get_sources)
File "/usr/local/lib/python3.8/site-packages/androidtv/androidtv/androidtv_async.py", line 73, in update
screen_on, awake, audio_state, wake_lock_size, current_app, media_session_state, audio_output_device, is_volume_muted, volume, running_apps = await self.get_properties(get_running_apps=get_running_apps, lazy=lazy)
File "/usr/local/lib/python3.8/site-packages/androidtv/androidtv/androidtv_async.py", line 125, in get_properties
output = await self._adb.shell(constants.CMD_ANDROIDTV_PROPERTIES_LAZY_RUNNING_APPS)
File "/usr/local/lib/python3.8/site-packages/androidtv/adb_manager/adb_manager_async.py", line 498, in shell
return await self._adb_device.shell(cmd)
File "/usr/local/lib/python3.8/site-packages/androidtv/adb_manager/adb_manager_async.py", line 43, in shell
return await asyncio.get_running_loop().run_in_executor(None, self._device.shell, cmd)
AttributeError: 'NoneType' object has no attribute 'shell'
These are âold onesâ
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 418, in start
resp = await task
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 458, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 882, in get
data, content_type = await player.async_get_media_image()
File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 357, in _adb_exception_catcher
return await func(self, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 500, in async_get_media_image
media_data = await self.aftv.adb_screencap()
File "/usr/local/lib/python3.8/site-packages/androidtv/basetv/basetv_async.py", line 149, in adb_screencap
return await self._adb.screencap()
File "/usr/local/lib/python3.8/site-packages/androidtv/adb_manager/adb_manager_async.py", line 476, in screencap
return await self._adb_device.screencap()
File "/usr/local/lib/python3.8/site-packages/androidtv/adb_manager/adb_manager_async.py", line 39, in screencap
return await asyncio.get_running_loop().run_in_executor(None, self._device.screencap)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.8/site-packages/ppadb/command/transport/__init__.py", line 48, in screencap
if result[5] == 0x0d:
IndexError: bytearray index out of range
and
Updating androidtv media_player took longer than the scheduled update interval 0:00:10
and
Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: ERROR: 'FAIL' 0006closed
All things seem to work as expected, beside the possibility to turn on/off the Magenta-TV-Stick. I can circumvent this by turning on/off the TV itself (another AndroidTV-SonyBravia) and CEC does the rest. Correction, since the ânewâ error message I canât control the MagentaTV-Stick in any way, it simply doesnât work (what Iâd have expected after the shell error).
Updating androidtv media_player took longer than the scheduled update interval 0:00:10
I suspect that is due to the fact that you have the screencap option enabled.
Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: ERROR: âFAILâ 0006closed
Iâm not sure about that one, but it could be a bug with pure-python-adb
Just a guess, but the last two issues could be related: the device could be unresponsive, causing the update command to hang forever, causing the next update command to fail. I use the Python ADB implementation, so maybe this doesnât apply, but every few weeks or so my Fire TV stick stops responding to ADB commands sent by HA and I have to restart the Fire TV, after which HA successfully reconnects.
You are a genius! Thanks a lot, my total respect, you know your code base!
I disabled the screencapture (must have overlooked that setting), and all errors are gone. Itâs now running for a good 45 minutes without any error message, even the ânew oneâ seems to be gone. All is responsible and working as expected. I can switch, play, pause, turn on or off, all goodâŚ
Thanks a lot and have a nice weekend!
EDIT: After around one and a half hours the error that you already have fixed is back, but thatâs not a problem, Iâll wait for 0.113.1 and report back.
Having used Apple TVâs in the past and recently switched to Android TV I do miss one thing. On the ATV (and the HA component) it was able to determine whether the device was playing or paused. I find that with the SHIELD TV and the Xiaomi MiBox S they both show a playing state when browsing apps like Disney+ or Netflix, the state would simply change to playing after a few seconds even if you were just browsing these apps. This makes automating anything based on play/paused states quite difficult which was not the case for my ATVâs. Also updating the state takes over 5 seconds which makes the automations feel kinda clunky. I wonder there is a way to change the polling speed or something so that at least the states update in realtime.
For my movies I use the Plex integration to automate on (which surprisingly does update the state in real-time. Even more surprisingly, my ATV had correct states and real-time play/pause state changes, but the Plex integration had that same 5-8 seconds delay which my Android TV has on all other apps XD).
I wonder if this is a limitation of the ADB implementation and if there is a way to work around it (which I am thinking it isnât possible). Too bad if it canât get better than this, I actually like the Android TV experience in conjunction with other Google services as opposed to the Apple TV. Though currently I think the ATV HA component works slightly better in this regard.
I am fairly new to the Android ecosystem and thus also fairly new to this component. If there is anything I should know or something I have missed please correct me XD.
This should give you some reading time and a better understanding, what is going on with androidTV. In my understanding, there are two ways to communicate with your TV (or whatever androidTV device you are running). One is to send a command through the adb shell directly via a service or you use the custom state detection rules. I would start with the later, and if these donât work or something isnât supported, Iâd take a look if there is a shell command, you can use. At least that is my understanding how it works, but Iâm in no way an expert.
@JeffLIrion I have an existing shield 2017 that has been working great with the python implementation of the androidtv integration. I recently bought a second 2019 shield and enabled network debugging then added it to my configuration. This time I let HA generate the adb key but the old one is still using the one I generated a while back. I get the popup asking to allow the adb connection and tick the box saying to always allow. For whatever reason, every time I restart home assistant, the box âallow connectionâ box pops up on the shield even if I have that âalways allowâ box ticked.
So I copied those files into custom_components named the dir androidtv_test, and changed my config section for the 2019 shield to reference the androidtv_test platform (left the old one on androidtv). Restarted HA a few times and the popup keeps coming up.
I may have done the custom component thing wrong, would it pull the new versions of adb_shell and python-androidtv?
I also tried building a new docker image with just your commit cherry-picked but it appears I need to wait for the new versions of your libraries to appear in the HA base image?
Just call the custom component androidtv. I think there are multiple places where you would need to rename it. Also, the requirements are different for the native vs. custom component, so I think that could create issues. Speaking of whichâŚ
Iâm not sure how HA handles custom component requirements that conflict with native component requirements. Itâs possible that itâs not updating those packages. Unfortunately, I think itâs difficult to tell.
It might be necessary to delete the androidtv_adbkey and androidtv_adbkey.pub files in the .storage folder, restart HA, and re-approve the connection. WARNING: in general, deleting files in the .storage folder is a bad idea! (But deleting these two files wonât mess up anything.)
That pull request should be in release 0.113.3, if/when that gets released. So youâll be able to try it then without needing to fuss with a custom component.
0.113.3 has been released. Let me know if you still experience the issue. I expect that when you restart, youâll need to approve it again. But after that, you shouldnât need to.
If you do still need to approve it every time, delete the key files that I mentioned previously and see if itâs fixed after that.
Just updated. Popup still came up after restarts so I deleted the key pair from .storage. Unfortunately, the popup is still coming up. One thing I did notice is the RSA key fingerprint is the same in the popup even after deleting the key pairs from .storage. I did double check the new key pair is different. Shouldnât the âRSA key fingerprintâ be different each time the key is generated?
Did you first connect to this device from HA version 0.113 (not an earlier release)?
What is your Android device and which version of Android are you running? (@kylehendricks can you also let me know what version of Android youâre running)
So I think this has something to do with my â2017 Shieldâ androidtv entry that has the adbkey field set. I just got the RSA fingerprint of my existing key and it has the same fingerprint that keeps showing up on my new Shield. Here is my config for reference (Basement Shield TV is the shield with the issue):