Core: Error while setting up platform androidtv

Created on 23 Mar 2019  路  35Comments  路  Source: home-assistant/core

Operating environment (Hass.io/Docker/Windows/etc.):
Hass.io 90.0

Component/platform:

https://www.home-assistant.io/components/androidtv/

Description of problem:
i connected my sony bravia android tv to HA everything works fines, yet after a reboot it doesn't show up and i have the below error in the logs
my nvidia doesn't have this issue stay connected without any errors

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

  - platform: androidtv
    host: 192.168.1.159
    name: "Sony Bravia"
    adb_server_ip: 127.0.0.1
    adb_server_port: 5037

Traceback (if applicable):

2019-03-23 08:39:22 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform androidtv
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/androidtv/media_player.py", line 115, in setup_platform
    device_class=config[CONF_DEVICE_CLASS])
  File "/config/deps/lib/python3.7/site-packages/androidtv/__init__.py", line 45, in setup
    if aftv.manufacturer == 'Amazon':
  File "/config/deps/lib/python3.7/site-packages/androidtv/basetv.py", line 294, in manufacturer
    output = self.adb_shell(constants.CMD_MANUFACTURER)
  File "/config/deps/lib/python3.7/site-packages/androidtv/basetv.py", line 122, in _adb_shell_pure_python_adb
    return self._adb_device.shell(cmd)
  File "/config/deps/lib/python3.7/site-packages/adb_messenger/command/transport/__init__.py", line 23, in shell
    conn.send(cmd)
  File "/config/deps/lib/python3.7/site-packages/adb_messenger/connection.py", line 77, in send
    return self._check_status()
  File "/config/deps/lib/python3.7/site-packages/adb_messenger/connection.py", line 83, in _check_status
    raise RuntimeError("ERROR: {} {}".format(repr(recv), error))
RuntimeError: ERROR: 'FAIL' 0006closed

Additional information:

androidtv

All 35 comments

Can you check if the TV is connected to adb server?

Using the adb add on its states connected

[16:02:02] INFO: Connecting to device: 192.168.1.184...
already connected to 192.168.1.184:5555
[16:02:02] INFO: Connecting to device: 192.168.1.159...
already connected to 192.168.1.159:5555

I did fix a couple issues with the androidtv integration. You could try using the latest version of androidtv/media_player.py, but I think this issue is different -- the ADB command failed for some reason. You said it worked once but didn't work when you restarted HA, so I'd say try restarting again.

Will your new version work as a custom component as I'm on hass.io

Rebooting hasn't fixed the issue TV on or off

Yes, it will work as a custom component as long as it successfully installs the androidtv package. You might need to restart it if it doesn't finish installing the package and its dependencies in time.

But I have no idea why that ADB command fails.

Cheers
I don't understand the nvidia shield never misses a beat.

Try disconnecting and reconnecting from the ADB server, or just restart the ADB server.

Okay I turned the USB adb on my TV and turned it back on again, then restarted HA and it reconnected.
Yet a day later for no reason it lost connection again

I've connected to my Kindle via ADB in the past and 1) I have to first connect over a USB cable before connecting over Wi-Fi and 2) when I turn off the device, I have to reconnect via USB again. This sounds like it might be similar. I don't know if there's a way to keep the connection to your TV alive, but it looks like the issue is with the ADB connection and not the Android TV component / Home Assistant.

Does it make any difference my TV is connected via ethernet

Does it make any difference my TV is connected via ethernet

I don't see why it would. Also, you should fix your TV's IP address, if you haven't already.

My guess is that your TV does some sort of reboot each night at, say, 3 am. If you never check some sort of box telling it to always allow connections from this device, then the ADB server won't be able to reconnect.

@JeffLIrion, I'm getting an error as well trying to connect to an Nvidia Shield.

I've authorized the hass box on the Shield, and 'adb connect' works just fine. I'm able to execute shell commands and the like. I've copied the 'adbkeys' into my homeassistant directory (I'm using Raspbian with venv setup, not Hassio).

2019-03-25 21:57:17 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform androidtv
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
     SLOW_SETUP_MAX_WAIT, loop=hass.loop)
   File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
     return fut.result()
   File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
     result = self.fn(*self.args, **self.kwargs)
   File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/androidtv/media_player.py", line 105, in setup_platform
     device_class=config[CONF_DEVICE_CLASS])
   File "/srv/homeassistant/lib/python3.6/site-packages/androidtv/__init__.py", line 53, in setup
     aftv.device_properties = aftv.get_device_properties()
   File "/srv/homeassistant/lib/python3.6/site-packages/androidtv/androidtv.py", line 151, in get_device_properties
     wifi_out = self.adb_shell('ip addr show wlan0')
   File "/srv/homeassistant/lib/python3.6/site-packages/androidtv/basetv.py", line 99, in _adb_shell_python_adb
     return self._adb.Shell(cmd)
   File "/srv/homeassistant/lib/python3.6/site-packages/adb/adb_commands.py", line 376, in Shell
     timeout_ms=timeout_ms)
   File "/srv/homeassistant/lib/python3.6/site-packages/adb/adb_protocol.py", line 411, in Command
     return ''.join(cls.StreamingCommand(usb, service, command, timeout_ms))
   File "/srv/homeassistant/lib/python3.6/site-packages/adb/adb_protocol.py", line 439, in StreamingCommand
     for data in connection.ReadUntilClose():
 AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'

My config, which is more or less the same as I was using on my Fire TV.

- platform: androidtv
    name: Nvidia Shield Living Room
    host: <ipaddr>
    adbkey: "/home/homeassistant/.homeassistant/adbkeys/shield/adbkey"

Oh, and I have both an adbkey and adbkey.pub file.

@mmotley999 you need to use the ADB server option.

https://www.home-assistant.io/components/androidtv/

The discussion in this issue about preventing the device from going completely offline may be relevant.

https://github.com/JeffLIrion/python-androidtv/issues/18#issuecomment-476615413

@JeffLIrion Ok, I fired up ADB server('adb start-server') and changed the config:

  - platform: androidtv
    name: Nvidia Shield Living Room
    host: <ipaddr>
#    adbkey: "/home/homeassistant/.homeassistant/adbkeys/shield/adbkey"
    adb_server_ip: 127.0.0.1
    device_class: androidtv

However, now getting this:

WARNING (SyncWorker_14) [homeassistant.components.androidtv.media_player] Could not connect to Nvidia Shield Living Room at <ipaddr>:5555 using ADB server at 127.0.0.1:5037

I verified that issuing a "adb connect " works just fine from the command line/shell, even as the 'homeassistant' user, right after seeing the message. I'm able to execute shell commands against the Shield, so it doesn't appear the Shield is offline or not responding to network traffic....

@mmotley999 and @aav7fl, your issue is different. Please re-post here: https://github.com/home-assistant/home-assistant/issues/22485.

Right... in my case, I'm not running Home Assistant or adb in a Docker container. Home Assistant is running on a RPi3+ in a Python venv, and I've fired up adb via "adb start-server" from the command line prior to restarting Home Assistant. Looking at 22485, it doesn't appear to apply to my situation.

Restart the Android device... That takes care of the error for me.

Error while trying to connect to my IPTV box:

Error while setting up platform androidtv
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/androidtv/media_player.py", line 137, in setup_platform
    config.get(CONF_TURN_OFF_COMMAND))
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/androidtv/media_player.py", line 334, in __init__
    name, self._device_properties['serialno'])
KeyError: 'serialno'

@stast1 your issue is different. Please create a new issue and I'll submit a fix.

IMO, this issue should be closed. The original poster was able to setup both of his devices, but the problem was that one of those devices would eventually disconnect and become unavailable. This is more of an issue with that device itself, and the problem is not with the Home Assistant component.

@stast1 let me know if this fixes it.

https://github.com/home-assistant/home-assistant/pull/22996

@JeffLIrion Thanks!

@JeffLIrion > let me know if this fixes it.
It works. Thank!

@JeffLIrion Could you explain why you answered this https://github.com/home-assistant/home-assistant/issues/22324#issuecomment-476477584 here?
I'm getting Error: 'NoneType' object has no attribute 'ReadUntilClose' errors too

@pattyland https://www.home-assistant.io/components/androidtv/#adb-troubleshooting

  1. If you are using the Python ADB implementation:

    • This method often does not work for newer devices. Use the ADB server approach instead.

@JeffLIrion Thanks for the explanation! This article also says "If you receive the error message Error while setting up platform androidtv in your log..." but I didn't get that. It seems like my initial connections is fine, but get buggy afterwards. I think I will open a new issue as is seems to differ from this one

@pattyland please read the full page.

https://www.home-assistant.io/components/androidtv#adb-setup

  1. PYTHON ADB IMPLEMENTATION

The second option is to connect to your device using the adb Python package.

If your device requires ADB authentication, you will need to follow the instructions in the ADB Authentication section below. Once you have an authenticated key, this approach does not require any additional setup or addons. However, users with newer devices may find that the ADB connection is unstable. For a Fire TV device, you can try setting the get_sources configuration option to false. If the problem cannot be resolved, you should use the ADB server option.

@JeffLIrion Ok ok, you convinced me ;) With get_sources=false the error does not occur anymore, but the display of the status play/paused in HA is almost always wrong. I will install the ADB server in the hope that this will get better.

A recent pull request for the python-adb package might fix the issues that the Python ADB implementation had with newer devices. If you'd like to test it, please use this as a custom component and report back!

https://github.com/JeffLIrion/home-assistant/tree/patch-19/homeassistant/components/androidtv

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 馃憤
This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Having issues since updating to 0.98.1. Rebooted host, rebooted ShieldTV. Restarted ADB server add on. Still doesn't connect. Worked fine up until 0.98.x Verified ADB is still turned on in ShieldTV settings.

Any other thoughts on this? Anything I could look into that I may have missed above?

2019-09-01 09:45:40 ERROR (MainThread) [homeassistant.config] Platform error: media_player
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config.py", line 767, in async_process_component_config
    platform = p_integration.get_platform(domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 235, in get_platform
    "{}.{}".format(self.pkg_path, platform_name)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 6, in <module>
    from androidtv import setup, ha_state_detection_rules_validator
ImportError: cannot import name 'ha_state_detection_rules_validator' from 'androidtv' (/config/deps/lib/python3.7/site-packages/androidtv/__init__.py)
2019-09-01 09:45:46 ERROR (MainThread) [homeassistant.config] Platform error: media_player
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config.py", line 767, in async_process_component_config
    platform = p_integration.get_platform(domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 235, in get_platform
    "{}.{}".format(self.pkg_path, platform_name)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 6, in <module>
    from androidtv import setup, ha_state_detection_rules_validator
ImportError: cannot import name 'ha_state_detection_rules_validator' from 'androidtv' (/config/deps/lib/python3.7/site-packages/androidtv/__init__.py)

@rpitera it looks like the required version of the androidtv package did not get installed. Are you running HA in Docker?

pip install androidtv==0.0.24 should fix it.

@JeffLIrion - Running hass.io in Virtualbox. I have dev access set up though so I'll try this and get back to you.

EDIT: Didn't even need dev access, just went to my deps folder and removed the old folders and rebooted - everything loaded fine - thanks very much for the pointer!

Closing this issue as it seems all have been resolved. If you experience this issue, please open a new one.

Was this page helpful?
0 / 5 - 0 ratings