[Deprecated] Native support for Fire TV

You need to set the adb_server_ip configuration variable; '127.0.0.1' should work.

It shouldn’t break that functionality – if the component works then you should be able to send ADB commands. I did rename the service from media_player.firetv_adb_shell to media_player.firetv_adb_cmd, though.

Admittedly, I’ve made a bit of a mess of my custom component repo. But here’s all you need to pay attention to.

  • The master branch firetv.py file is what I intend for the next version of the HA component (it’s just waiting on a new release of the firetv package).
  • The set_states branch firetv.py file is basically the same, except that it will set the state of your device when you issue turn_on/turn_off/select_source commands. I find this useful, but I don’t think it’s allowed in official components.
  • Don’t worry about any of the other branches, they’re outdated.
  • There are two ways of sending ADB commands:
    1. To use the Python adb package for sending commands, you’ll need to use a pre-authenticated key. Instructions can be found in the docs for the official component. You’ll need to provide the path to this key in the adbkey configuration entry.
    2. To use the ADB addon or an ADB server instance that you have setup, you’ll need to provide the IP address of the ADB server in the adb_server_ip configuration entry; the value '127.0.0.1' should work fine for the addon users.

If you receive any errors regarding the firetv package:

  • If you already have version 1.0.8 installed in your <configuration>/deps/python3.6/site-packages folder, you can probably upgrade it to the latest version by running these commands:
# use the correct path for your setup
cd /config/deps/python3.6/site-packages/firetv
mv __init__.py BACKUP.py
wget https://raw.githubusercontent.com/JeffLIrion/python-firetv/next-release/firetv/__init__.py
  • If you don’t already have firetv 1.0.8 installed, or if you deleted it, then hopefully HA will install it for you. However, this wasn’t working for me yesterday. Instead, I had to install it into a local folder on a different machine and then copy the folders over (e.g., using the Samba addon). To install firetv into the current folder, use the command:
# you might need to use pip3 instead of pip
pip install --target . https://github.com/JeffLIrion/python-firetv/zipball/next-release

I had previously used the ADB server, but that was throwing errors. In the end I started over again with the instructions you had posted yesterday. This is looking stable today, nice work thanks for the help.

This is my config:

- platform: firetv
  name: Amazon Fire TV
  host: 192.168.2.8
  adb_server_ip: 127.0.0.1

Should be right, I guess? Still getting the Error

In your previous error message, the component is using the Python adb package. If you’re still getting the same error message, I think HA is failing to setup the custom component (possibly due to dependencies) and so it’s using the built-in component. Check for an error message at startup. Also, make sure that you’re using the latest firetv.py custom component. You might need to follow some of the steps in this post in order to install the correct dependencies.

I also posted some detailed instructions here.

That’s probably it, because this error is on startup:

Error loading custom_components.media_player.firetv. Make sure all dependencies are installed

Traceback (most recent call last): 
File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 117, in _load_file module = importlib.import_module(path) 
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) 
File "&lt;frozen importlib._bootstrap&gt;", line 994, in _gcd_import File "&lt;frozen importlib._bootstrap&gt;", line 971, in _find_and_load 
File "&lt;frozen importlib._bootstrap&gt;", line 955, in _find_and_load_unlocked 
File "&lt;frozen importlib._bootstrap&gt;", line 665, in _load_unlocked File "&lt;frozen importlib._bootstrap_external&gt;", line 678, in exec_module 
File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed 
File "/config/custom_components/media_player/firetv.py", line 174, in &lt;module&gt; class FireTVDevice(MediaPlayerDevice): 
File "/config/custom_components/media_player/firetv.py", line 177, in FireTVDevice from firetv import KEYS 
ImportError: cannot import name 'KEYS'

I’ll research how to get the pip install with another machine.

A quick question, I notice many video apps do not report play / pause status. They stay as paused regardless whether they are playing or not. Is there a simple fix for this to pick up the status properly.

That’s a limitation of the component. It’s difficult to accurately determine state using ADB commands.

Understood. Thanks for your guidance. The component works pretty well and will certainly provide relatively easy access to many Fire TV functions via Home Assistant. Good work. Ynot.

Got it working but have a question… I have a Toshiba with firetv built in… should I be able to set the input with this? HDMI1,2,3 etc?

You can try using the media_player.firetv_adb_cmd service with the cmd parameter as input keyevent 243 (or some other key event code; see here).

I only see shell and streaming shell services

—-
Could I just do it with the command line instead?

You’re using an older version of the component, but it’s probably fine. Use the shell service.

I updated to the new beta of 0.88 (also moved from custom_component/media_player/firetv.py to custom_component/firetv/media_player.py as requested by the docs) and I get this error there:

2019-02-16 21:25:02 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform firetv
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/adb/adb_protocol.py", line 226, in Unpack
    cls.format, message)
struct.error: unpack requires a buffer of 24 bytes

During handling of the above exception, another exception occurred:

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/media_player/firetv.py", line 73, in setup_platform
    ftv = FireTV(host)
  File "/usr/local/lib/python3.7/site-packages/firetv/__init__.py", line 106, in __init__
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/firetv/__init__.py", line 119, in connect
    self._adb = adb_commands.AdbCommands().ConnectDevice(**kwargs)
  File "/usr/local/lib/python3.7/site-packages/adb/adb_commands.py", line 142, in ConnectDevice
    self._Connect(**kwargs)
  File "/usr/local/lib/python3.7/site-packages/adb/adb_commands.py", line 173, in _Connect
    conn_str = self.protocol_handler.Connect(self._handle, banner=banner, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/adb/adb_protocol.py", line 314, in Connect
    cmd, arg0, arg1, banner = cls.Read(usb, [b'CNXN', b'AUTH'])
  File "/usr/local/lib/python3.7/site-packages/adb/adb_protocol.py", line 243, in Read
    cmd, arg0, arg1, data_length, data_checksum = cls.Unpack(msg)
  File "/usr/local/lib/python3.7/site-packages/adb/adb_protocol.py", line 228, in Unpack
    raise ValueError('Unable to unpack ADB command.', cls.format, message, e)
ValueError: ('Unable to unpack ADB command.', b'<6I', b'', error('unpack requires a buffer of 24 bytes'))

Please see the README. You probably need to setup an ADB server, such as the Hass.io addon.

The adb server is setup and with 0.87 everything worked fine. The update to 0.88.0b1 broke it

I know they changed some stuff regarding custom components, but I don’t know the specifics. What I can see from your log is that it’s using the Python ADB implementation, not the ADB server.

If you see an error about setting up the custom component, this might have a solution for you.

As soon as the updated firetv package is released, I’m gonna submit a pull request to Home Assistant. That should solve the issues that people have had with dependencies and with the custom component not being loaded.

I’m not sure what I did now… I had it working but now I keep getting cannot import ‘KEYS’ again, but they are still there correct path, and that’s all I did to fix first time was setup adb and connect. I wonder if maybe I grabbed the wrong version/branch. Any guidance on which version most people should be using at this point or should we just wait until another update?

Use the master branch: firetv.py. firetv 1.0.8 is on pypi now, so it might install automatically. I created a pull request for Home Assistant and I’ve got two more to follow, hopefully it will be in the next release!

In the meantime, you can try the steps here to resolve the issue: https://github.com/JeffLIrion/homeassistant_native_firetv/issues/25