JeffLIrion / homeassistant_native_firetv

43 stars 16 forks source link

Crashing on startup under HA 0.79, no firetv's present in the UI #9

Closed mmotley999 closed 6 years ago

mmotley999 commented 6 years ago

Just upgraded to HA 0.79, and seems firetv is now crashing on startup:

 #033[31m2018-09-30 01:21:26 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform firetv#033[0m
 Traceback (most recent call last):
   File "/srv/homeassistant/homeassistant_venv/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 "/home/homeassistant/.homeassistant/custom_components/media_player/firetv.py", line 55, in setup_platform
     device = FireTVDevice(host, name, adbkey)
   File "/home/homeassistant/.homeassistant/custom_components/media_player/firetv.py", line 93, in __init__
     self._firetv = FireTV(host, adbkey)
   File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/firetv/__init__.py", line 105, in __init__
     self.connect()
   File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/firetv/__init__.py", line 118, in connect
     self._adb = adb_commands.AdbCommands().ConnectDevice(serial=self.host, rsa_keys=[signer])
   File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/adb/adb_commands.py", line 142, in ConnectDevice
     self._Connect(**kwargs)
   File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/adb/adb_commands.py", line 173, in _Connect
     conn_str = self.protocol_handler.Connect(self._handle, banner=banner, **kwargs)
   File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/adb/adb_protocol.py", line 336, in Connect
     data=rsa_keys[0].GetPublicKey() + b'\0')
 TypeError: must be str, not bytes#033[0m

It was working just fine under 0.76. Also, I can do an 'adb connect ' and it connects fine. Here's my config:

  - platform: firetv
    host: <ip addr redacted>
    name: 'FireTV - Living Room'
    adbkey: "/home/homeassistant/.homeassistant/adbkeys/adbkey"

Both 'adbkey' and 'adbkey.pub' are present in that directory.

EDIT: Oh, and I did pull your most recent copy down and replaced my old firetv.py custom_component with your most recent one.

lociii commented 6 years ago

Same over here after updating the docker container to 0.79.0

JeffLIrion commented 6 years ago

Does your host (IP address) contain the port? It should not. I changed this a few weeks ago, so if you went from an old version of the component to a new one and didn't update your configuration, that could be the cause.

Aside from that, you're receiving this error because your adbkey didn't work. Please make sure that your key is pre-authenticated, meaning that you told the Fire TV to always allow it. Also, you said you can connect with the command adb connect, so you could try re-copying the key used by the ADB binary from your ~/.android directory to your HA configuration directory.

photinus commented 6 years ago

Just for reference, works on 0.79 with the debugging versions JeffLlrion has been helping me with.

mmotley999 commented 6 years ago

Ok, I finally got the "authorize this device" popup. Thanks for the hint on the adbkey in the "~/.android" directory. I copied those over and now it is no longer crashing (yay!) but still getting a "Cannot connect" message:

Sep 30 15:41:31 hass1 hass[16028]: #033[32m2018-09-30 15:41:31 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.firetv#033[0m
Sep 30 15:41:33 hass1 hass[16028]: #033[33m2018-09-30 15:41:33 WARNING (SyncWorker_13) [custom_components.media_player.firetv] Could not connect to Fire TV at 10.10.20.36:5555#033[0m

I have no port defined in my media_player config, just the IP address.

I'm rebooting the firetv now.

mmotley999 commented 6 years ago

Ok... I'm an idiot. :)

Last night, I connected via ADB as root, and of course just copied over the ~./android/adbkey* files as root... had to chown them to the homeassistant user. Doh.

It's all working great now!!

Here's what seemed to have fixed it, for other's benefit:

  1. 'adb connect '. Creates an adbkey/adbkey.pub in ~/.android. I did this as root on my RPi ('sudo su').

  2. I finally was able to authorize the ADB connection on the FireTV. It's odd that it seems to just popped up kinda randomly, as I connected ADB last night and, literally, just got the notification 10 minutes ago.

  3. Copy the newer adbkey/adbkey.pub from ~/.android to /home/homeassistant/.homeassistant/adbkey directory, which is where my config points.

  4. chown homeassistant.homeassistant adbkey* (can't forget this).

  5. Restart HA.

Thanks so much for your support on this module. It really works well, once you figure out the adbkey thing (which I still don't fully understand, honestly).

JeffLIrion commented 6 years ago

Thanks for figuring that out! I created a "Troubleshooting" section in the README and mentioned this issue and its solution. (https://github.com/JeffLIrion/homeassistant_native_firetv/commit/606c23b0f1a722c1b0e3e01dd571508b9052e5f8)