[Deprecated] Native support for Fire TV

I switched to using sign_pythonrsa.py for authentication and it’s working! My Fire TV stick with authentication is back in Home Assistant!

1 Like

I’ll try the suggestion above later tonight. Is there an updated py file on github for sign_pythonrsa.py?

Nope, I just switched from using the signer in sign_pycryptodome.py to that in sign_pythonrsa.py.

BTW, if others are able to get it to work then I’ll submit pull requests to python-firetv and python-adb so that the component will work without requiring additional files to be bundled along with it.

Still no go. Don’t know what’s happening but same errors.

When I get a chance, I’ll fork python-firetv and python-adb and specify those forked versions in the REQUIREMENTS variable. That should make it so that only the firetv.py file is needed.

For my own reference: https://developers.home-assistant.io/docs/en/creating_component_deps_and_reqs.html

REQUIREMENTS = ['https://github.com/jabesq/pybotvac/archive/v0.0.5.zip#pybotvac==0.0.5']

Just had enough time to download and copy the latest versions of the files onto my system.

After the 1st restart of HAss I quickly lost access to the FireTV - took only about 30 seconds or so until the card went from ‘playing’ to ‘idle’ while the FireTV was still playing. I could still pause and rewind, though, from the main card. Remote control options from the detailed card had disappeared. Could not get back the full functionality even with a reboot of the FireTV itself.

After I restarted a 2nd time it showed a status ‘playing’ much longer. And I had full control in the main and the detailed card.
Actually, even after turning the FireTV off about 5min ago, it still shows as ‘playing’ on the UI.

Update

I added forked versions of python-adb and python-firetv to the REQUIREMENTS list, so now all you have to do to use the component is copy the media_player/firetv.py file to custom_components/media_player/firetv.py. @Jer78, I hope this works for you!

Hi everybody,
I felt encouraged to try it out myself I copied the firetiv.py from the git to custom_components/media_player/firetv.py in my config directory and changed my conifg:

- platform: firetv
  host: "192.168.178.26:5555"
  name: Fire TV

Using the IP of my fire tv stick. However I get the following errors:

Tue Aug 21 2018 10:00:23 GMT+0200 (CEST)

Error while setting up platform firetv

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 129, 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 "/config/custom_components/media_player/firetv.py", line 52, in setup_platform
    device = FireTVDevice(host, name, adbkey)
  File "/config/custom_components/media_player/firetv.py", line 65, in __init__
    from firetv import FireTV
ModuleNotFoundError: No module named 'firetv'

Thanks a lot and Cheers

It looks like you’re using the most current version of the code, but just to be sure, please check that the REQUIREMENTS list looks like this:

REQUIREMENTS = ['libusb1==1.6.6', 'rsa==3.4.2',
                'https://github.com/JeffLIrion/python-firetv/zipball/master#firetv==1.0.5.dev',
                'https://github.com/JeffLIrion/python-adb/zipball/master#adb==1.3.0.dev']

Aside from that, I think installing required packages from GitHub is not as reliable as installing them from pypi, so I suggest restarting and seeing if it’s able to successfully install the required packages and setup the platform. If you do that a few times and it still doesn’t work, please let me know.

I tested the latest. I can verify my firetv.py has the following:

REQUIREMENTS = ['libusb1==1.6.6', 'rsa==3.4.2',
                'https://github.com/JeffLIrion/python-firetv/zipball/master#firetv==1.0.5.dev',
                'https://github.com/JeffLIrion/python-adb/zipball/master#adb==1.3.0.dev']

Here’s the error I get

2018-08-21 10:18:44 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform firetv
  File "/Users/mediacenter/.homeassistant/custom_components/media_player/firetv.py", line 52, in setup_platform
    device = FireTVDevice(host, name, adbkey)
  File "/Users/mediacenter/.homeassistant/custom_components/media_player/firetv.py", line 65, in __init__
    from firetv import FireTV
  File "/Users/mediacenter/.homeassistant/deps/lib/python/site-packages/firetv/__init__.py", line 13, in <module>
2018-08-21 10:18:45 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform firetv
  File "/Users/mediacenter/.homeassistant/custom_components/media_player/firetv.py", line 52, in setup_platform
    device = FireTVDevice(host, name, adbkey)
  File "/Users/mediacenter/.homeassistant/custom_components/media_player/firetv.py", line 65, in __init__
    from firetv import FireTV
  File "/Users/mediacenter/.homeassistant/deps/lib/python/site-packages/firetv/__init__.py", line 13, in <module>

Here’s my config:

media_player:
  - platform: firetv
    host: "192.168.1.211:5555"
    name: Fire TV Basement
    #adbkey: "/config/android/adbkey"
  - platform: firetv
    host: "192.168.1.210:5555"
    name: Fire TV Living Room
    adbkey: "/config/android/adbkey"

Could it be due to different versions of Home Assistant? or the Fire TV itself? I’m running the latest 0.76.1 and my 2 FireTV’s are the 2015 Gen 2. One is the stick the other is the box. I’ve tried adbkey on both in the config with same results.

I don’t think it’s due to your Fire TV devices, I think I have the same. I don’t think it’s due to your Home Assistant version, although it could be due to the underlying OS / environment. BTW, in order to use the adbkey you need to have an adbkey file. I created mine by downloading adb on my laptop and connecting to my Fire TV, then copying the files ~/.android/adbkey and ~/.android/adbkey.pub to my Home Assistant configuration folder. But I don’t think that’s your issue, since you’re failing at an import step.

Here are some ideas to try.

Add pyasn1 to the REQUIREMENTS

REQUIREMENTS = ['libusb1==1.6.6', 'rsa==3.4.2', 'pyasn1',
                'https://github.com/JeffLIrion/python-firetv/zipball/master#firetv==1.0.5.dev',
                'https://github.com/JeffLIrion/python-adb/zipball/master#adb==1.3.0.dev']

Add these logging statements to firetv.py (after the _LOGGER line)

_LOGGER = logging.getLogger(__name__)

try:
    import libusb1
except:
    _LOGGER.error('Failed to import libusb1')

try:
    import rsa
except:
    _LOGGER.error('Failed to import rsa')

try:
    import firetv
except:
    _LOGGER.error('Failed to import firetv')

try:
    import adb
except:
    _LOGGER.error('Failed to import adb')

try:
    import pyasn1
except:
    _LOGGER.error('Failed to import pyasn1')

Manually install the requirements

If you’re able to, manually install the requirements and try to import them.

Made the changes as above. I had to manually install libusb and rsa. Still getting this error in the logs. What command do I use to import them into homeassistant manually. I’m using MacOS as my platform.

2018-08-21 12:23:26 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform firetv
  File "/Users/mediacenter/.homeassistant/custom_components/media_player/firetv.py", line 77, in setup_platform
    device = FireTVDevice(host, name, adbkey)
  File "/Users/mediacenter/.homeassistant/custom_components/media_player/firetv.py", line 90, in __init__
    from firetv import FireTV
  File "/Users/mediacenter/.homeassistant/deps/lib/python/site-packages/firetv/__init__.py", line 13, in <module>
2018-08-21 12:23:26 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform firetv
  File "/Users/mediacenter/.homeassistant/custom_components/media_player/firetv.py", line 77, in setup_platform
    device = FireTVDevice(host, name, adbkey)
  File "/Users/mediacenter/.homeassistant/custom_components/media_player/firetv.py", line 90, in __init__
    from firetv import FireTV
  File "/Users/mediacenter/.homeassistant/deps/lib/python/site-packages/firetv/__init__.py", line 13, in <module>

What I meant was, in the Python interpreter try commands like import adb and from firetv import FireTV and see what error message(s) you get. I’m not sure if you can do this if you’ve installed HA using Docker, but you can certainly do this if you installed it in a Python virtual environment.

I’m by no means an expert when it comes to HA. I don’t understand why you had to install libusb and rsa manually, and I don’t know why your HA is having so much trouble with installing the packages listed in the REQUIREMENTS. My guess is that adb or one of its requirements doesn’t list all its dependencies in its setup.py file.

OK I will try to figure this out. Thanks for your help thus far. I’ll do a little research and see what’s wrong with my setup and why its not importing.

I do see these in the log

2018-08-21 12:52:20 ERROR (MainThread) [custom_components.media_player.firetv] Failed to import libusb1
2018-08-21 12:52:20 ERROR (MainThread) [custom_components.media_player.firetv] Failed to import firetv
2018-08-21 12:52:20 ERROR (MainThread) [custom_components.media_player.firetv] Failed to import adb

You said that you manually installed libusb and rsa, so why is it failing to import them?

Also, I think if you make your logging more verbose you might get more info about what exactly the error is.

@Jer78 and @Rudertier, are you by any chance running Home Assistant using your host system’s Python and not in a virtual environment? I could see that creating issues when it comes to HA installing required packages.

Correct, I am not using a virtual environment. It also created too many issues for me in the past.

When I look in the .homeassistant/deps/lib/python/site-packages/ directory, all the requirements are there. I may wipe the entire directory and restart HA.

Make a backup first! :grinning:

You could try deleting any __pycache__ folders and .pyc files in that directory before you try wiping it completely.

If that doesn’t work and wiping the directory doesn’t work, then I think it will work to install those packages on your system (as in, not just for Home Assistant).

So I took the extreme action of deleting that folder and restarted. Everything loads except firetv. Ugh!

(and yes, I always make backups :sweat_smile:)

So lets try your next suggestion. When I install packages, I use this command… pip3 install libusb1

Should I be using sudo instead?

I think using sudo is necessary. I think that’s why even after you installed those packages without sudo, HA failed to import them.

I tried all of them using

sudo -H pip3 install <packagename>

and they all say requirement already met and they are installed. Some reason HA isn’t importing them properly. I’m using Python 3.6, does that make a difference?