JeffLIrion / homeassistant_native_firetv

43 stars 16 forks source link

Connection lost handling #4

Closed Alexxander0 closed 6 years ago

Alexxander0 commented 6 years ago

In this case iam using a firetablet. But i think a firetv should behave the same, as its just the adb connection.

After a device is setup with a working adb connection and then looses the connection afterwards, it throws an error. For example if device is totally powered off and has no wifi connection. This error is annoying because its thrown in the scan intervall of the platform into the log. So every 15 seconds there is an error.

Couldn't connect to host: 192.168.178.26:5555, error: Connection refused

Further more, the attributes are not changed to unavailable or off or something. It stays at "playing" for me

JeffLIrion commented 6 years ago

Could you please post the log output for this issue, including when the issue first occurs.

JeffLIrion commented 6 years ago

OK, I reproduced this error as follows.

  1. Establish an ADB connection with a Fire HD tablet. (See Connect to Fire Tablet through ADB and Debug Your Web App)
    1. Plug the tablet into the computer.
    2. Download platform-tools, extract it, and cd to that folder
    3. ./adb start-server (and check the box to always allow connections from that device)
    4. ./adb devices (make sure the serial number is included in the output)
    5. ./adb tcpip 5555
    6. ./adb kill-server and unplug the tablet from the computer
  2. Add the Fire tablet to Home Assistant as a Fire TV media player, making sure to include the adbkey
  3. Start Home Assistant and verify that the tablet was successfully added
  4. Power off the Fire tablet
  5. Turn on the Fire tablet

My log looks like this:

2018-09-09 11:47:50 WARNING (MainThread) [homeassistant.helpers.entity] Update of media_player.kindle_fire is taking over 10 seconds
2018-09-09 11:50:09 WARNING (MainThread) [homeassistant.helpers.entity] Update of media_player.kindle_fire is taking over 10 seconds
2018-09-09 11:50:10 WARNING (MainThread) [homeassistant.components.media_player] Updating firetv media_player took longer than the scheduled update interval 0:00:10
2018-09-09 11:50:21 WARNING (MainThread) [homeassistant.components.media_player] Updating firetv media_player took longer than the scheduled update interval 0:00:10
...
2018-09-09 11:56:40 ERROR (Thread-20) [custom_components.media_player.firetv] Update encountered an exception; will attempt to re-establish the ADB connection in the next update
2018-09-09 11:56:52 WARNING (Thread-21) [root] Couldn't connect to host: 192.168.0.74:5555, error: Connection refused
2018-09-09 11:57:00 WARNING (Thread-3) [root] Couldn't connect to host: 192.168.0.74:5555, error: Connection refused
...
JeffLIrion commented 6 years ago

In this case iam using a firetablet. But i think a firetv should behave the same, as its just the adb connection.

After a device is setup with a working adb connection and then looses the connection afterwards, it throws an error. For example if device is totally powered off and has no wifi connection. This error is annoying because its thrown in the scan intervall of the platform into the log. So every 15 seconds there is an error.

Couldn't connect to host: 192.168.178.26:5555, error: Connection refused

Further more, the attributes are not changed to unavailable or off or something. It stays at "playing" for me

Here's what happens.

  1. You turn off the Fire tablet, or you unplug the Fire TV. Home Assistant tries to update its status. Of course, it doesn't work because the device is off. But it doesn't outright fail, either. Instead, it throws this warning:

    2018-09-09 11:50:10 WARNING (MainThread) [homeassistant.components.media_player] Updating firetv media_player took longer than the scheduled update interval 0:00:10

    Because the status didn't update, the state stays the same -- "Playing" (or whatever it was before the device was turned off).

  2. You turn the device back on. If it's a Fire TV, then my guess is that it will reconnect successfully and everything will be fine. If it's a Fire tablet, it won't reconnect because you need to plug it into a computer via a USB cable and repeat the ADB commands that I posted above in order to allow an ADB connection over WiFi. And until you do that, it will keep throwing that error about being unable to connect:

    2018-09-09 11:57:00 WARNING (Thread-3) [root] Couldn't connect to host: 192.168.0.74:5555, error: Connection refused

Home Assistant doesn't like when devices drop offline, and I just don't see a good way to handle the issue in this component. For that reason, I'm going to close the issue.