Skip to content

Conversation

@JeffLIrion
Copy link
Collaborator

@JeffLIrion JeffLIrion commented Aug 24, 2018

Now that ADB authentication is implemented, pycryptodome and rsa are required. I've submitted a pull request for adb that will bump the version up to 1.3.0.1, but for now I'll put the requirement as 1.3.0 (although this version may lead to some errors when using an ADB key).

Along with the previous pull request (#61), this should close #49, #57, and #60.

@happyleavesaoc
Copy link
Owner

1.0.6 if you don't mind. Will cut a release & push to pypi after merge.

@JeffLIrion
Copy link
Collaborator Author

Sounds good! Should I change the version now or wait until my pull request to adb has been merged?

@chilicheech
Copy link

Any updates on this? This will be very useful to me 😄

@JeffLIrion
Copy link
Collaborator Author

I can change the version in my pull request at any time, but I'm just waiting on this pull request for python-adb to go through...
google/python-adb#119 (@chilicheech as you already know)

@tuxuser
Copy link
Contributor

tuxuser commented Oct 4, 2018

Modifications for python-adb were upstreamed, new release for it is pending tho.

@happyleavesaoc
Copy link
Owner

We'll merge this once the upstream release is completed.

@JeffLIrion JeffLIrion changed the title Bump version to 1.0.5.1 and fix requirements Bump version to 1.0.6 and fix requirements Oct 27, 2018
@JeffLIrion
Copy link
Collaborator Author

I published a slightly modified version of adb as adb-homeassistant on pypi. Running pip install adb-homeassistant will install adb version 1.3.1, which satisfies the requirement 'adb>1.3.0' for this package. So it should be all good to go!

NOTE

  1. Until https://github.com/google/python-adb gets updated on pypi, users will need to run pip install adb-homeassistant prior to running pip install firetv so that the requirements are satisfied.
  2. Home Assistant was having some trouble running pip install adb due to the M2Crypto dependency, so I modified that in adb-homeassistant.

@happyleavesaoc
Copy link
Owner

@JeffLIrion I think it would be better to explicitly set adb-homeassistant as a requirement for firetv. That way there's no extra steps for the average user who may not read github issues. Once adb does their official release, we can update firetv accordingly.

This will also expedite getting the Home Assistant PR merged.

@JeffLIrion
Copy link
Collaborator Author

No problem, I changed the requirement.

@happyleavesaoc happyleavesaoc merged commit dae0f5a into happyleavesaoc:master Oct 28, 2018
@happyleavesaoc
Copy link
Owner

1.0.6 pushed to pypi.

@JeffLIrion
Copy link
Collaborator Author

Awesome, thank you!

@joachimpr
Copy link

How do I install the required packages for this? I followed all instructions in the readme to install and received Couldn't connect to host. I played around with adb versions and downgraded to a previous version. now it's just giving me python errors. y ultimate goal is to run some command line scripts from home assistant to control my FireTV stick 4k. I am attemting the install of adb-homeassistant now. any help to get this running will be buch appreciated.

@JeffLIrion
Copy link
Collaborator Author

This is already integrated into Home Assistant. It will install the dependencies for you. If it fails to setup the device, it's almost certainly due to a configuration error or an issue with youradbkey and adbkey.pub files.

https://www.home-assistant.io/components/media_player.firetv

@joachimpr
Copy link

joachimpr commented Jan 13, 2019

Thanks @JeffLIrion, I managed to get it running through command line which is good for me. I don't need the physical implementation in home assistant. I only in command line so on that front It is all good now. I do have another question. Yesterday, everything was working flawlessly. Upon starting to write my scripts this morning, I noticed the apps wont launch anymore. when accessing the endpoint http://192.168.88.169:5556/devices/lounge/apps/com.cbsnews.ott/start, I get a json response with the following message:
{
"success": {
"output": "",
"retcode": "** SYS_KEYS has no physical keys but with factor 2.0%.\n251"
}
}

As stated, this worked yesterday where I left off yet this morning, it does not. Any idea what might be causing this. When attempting to access the same url as above again after this message, I just get an Internal Server Error with the following python output:

INFO:werkzeug:192.168.88.169 - - [13/Jan/2019 06:54:15] "GET /devices/lounge/apps/com.cbsnews.ott/start HTTP/1.1" 200 -
[2019-01-13 07:02:10,122] ERROR in app: Exception on /devices/lounge/apps/com.cbsnews.ott/start [GET]
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functionsrule.endpoint
File "/usr/local/lib/python2.7/dist-packages/firetv/main.py", line 191, in app_start
success = devices[device_id].launch_app(app_id)
File "/usr/local/lib/python2.7/dist-packages/firetv/init.py", line 135, in launch_app
return self._send_intent(app, INTENT_LAUNCH)
File "/usr/local/lib/python2.7/dist-packages/firetv/init.py", line 295, in _send_intent
res = self._adb.Shell(cmd).strip().split("\r\n")
File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 366, in Shell
timeout_ms=timeout_ms)
File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 406, in Command
return ''.join(cls.StreamingCommand(usb, service, command, timeout_ms))
File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 434, in StreamingCommand
for data in connection.ReadUntilClose():
AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'
192.168.88.169 - - [13/Jan/2019 07:02:10] "GET /devices/lounge/apps/com.cbsnews.ott/start HTTP/1.1" 500 -
INFO:werkzeug:192.168.88.169 - - [13/Jan/2019 07:02:10] "GET /devices/lounge/apps/com.cbsnews.ott/start HTTP/1.1" 500 -

Another thing that I also don't understand is where does the IP werkzeug:192.168.88.169 in the above error come from? my IP of my firestick is 192.168.88.159, and the box which I am running the firetv-server on is at 192.168.88.237. I know the 159 IP is correct as I can execute other commands such as http://192.168.88.237:5556/devices/action/lounge/turn_on which works flawlessly. It's only lawnching the apps this morning which seems to be a problem.

Any ideas for the "retcode": "** SYS_KEYS has no physical keys but with factor 2.0%.\n251" error and the resulting python errors.

Thanks a bunch for your help. This is the first time that I finally feel that there is some light and hope of me achieving what I set out to do with this home automation stuff. :-)

UPDATE: I know now where the 169 IP comes from. It is the local machine from which I issued the get request. Restarted the FireStick 4k, still experiencing the same error as above.

Thanks
J

@JeffLIrion
Copy link
Collaborator Author

You're making this soooo much harder than it needs to be... You don't need to run the firetv server anymore.

import firetv

ftv = firetv.FireTV('192.168.88.159:5555', 'path to the adbkey file')
ftv.turn_on()
ftv.launch_app('com.cbsnews.ott')

@joachimpr
Copy link

joachimpr commented Jan 13, 2019

I apologize for that. I'm also just learning about this now so I need to jump through the hoops. All the info I have is what I got online. I am also pretty much following the read me. I did not know about this python code above. What I gather is that I do not have to do run sudo firetv-server -d X.X.X.X:5555 as per the read me anymore correct? So with python fire TV installed (as per the readme), then I can just run the above code and it should work without creating linux services etc? correct? Is there any documentation outlining all the functions available in python anywhere?

Does this constitute anything else that I require to do? anything special? The app is still not launching. I run the python code and nothing happens. No errors are being output either. I put the code in a py file and then execute it with sudo python turn_on.py

Thanks for the help. and sorry for making things difficult.

@JeffLIrion
Copy link
Collaborator Author

There's no real need for documentation of the firetv package, just look at __init__.py. The function names are self-explanatory. No Linux service necessary. If methods such as turn_on and turn_off work but launching an app doesn't, my guess is that the app name is probably incorrect. Also, only one ADB connection is allowed at a time, so you may need to close the connection from your other computer and restart the Fire TV.

There are issues with the ADB connection breaking. These are due to the adb Python package and they're difficult to fix. I tried to handle these exceptions gracefully in the Home Assistant component.

If you're doing any sort of home automation / smart home stuff, I would highly, HIGHLY recommend using an existing open source solution. I use Home Assistant; I know there are others but I don't have experience with them. Everything you've mentioned (and a whole lot more) can easily be done using the Fire TV component for Home Assistant. You can turn the device on/off, pause/play, launch apps, etc. with the click of a button from a simple UI in your browser. When possible, it's always better to leverage existing solutions than to build your own from scratch.

@joachimpr
Copy link

I think the best approach here would be to uninstall everything (fire-tv[firetv-server], adb, and firetv-python) and reinstall according to the readme of your project but leaving out the firetv server bit, I will then try the python code again. I messed around with the adb versions as well so need to reinstall with the git version as per your suggestion.

I do have home assistant so I will do that as well. The thing is, I have been trying to avoid an upgrade at all cost. Never had fun with those and a lot of work has gone into my current implementation. Alas, I suppose it is then time for an upgrade from version 0.72.1 to whatever the latest is.

I will let you know how it goes. Thanks!

@joachimpr
Copy link

Hi @JeffLIrion,

Ok, I'm at breaking point. I uninstalled everything. I upgraded my home assistant to 0.85.1 which according to https://github.com/home-assistant/home-assistant/releases is the latest version.

I reinstalled according to the readme the following:

sudo apt-get install swig libssl-dev python-dev libusb-1.0-0
sudo pip install firetv
pip install git+git://github.com/google/python-adb.git@master

(Note I did not do sudo pip install firetv[firetv-server] as it is not necessary as per a previous post.

After installing all of this, I could not use sudo adb connect 192.168.88.159. The error stated that the command adb does not exist.

I proceeded to install sudo apt-get install android-tools-adb

sudo adb connect 192.168.88.159 now works!!!

Now I added the fireTV component to my HA as:

- platform: firetv
    name: Lounge Fire TV
    host: 192.168.88.159
    adbkey: "/home/pi/adbkey"

When I restart HA, I get the following error:
Invalid config for [media_player.firetv]: file not readable for dictionary value @ data['adbkey']. Got '/home/pi/adbkey'

The python code above also does not work with an error that it cannot connect to the host 192.168.88.159 yet I can connect with adb.

Is there anything that I am missing in this installation? I restarted the FireTV stick, I use the built in FireTV component as suggested, but for some reason I cannot get it working. It cannot be this difficult. I am at my whits end.

Any suggestions will be greatly appreciated. Apart from attempting to install firetv[firetv-server] (which I believe is not necessary, I have no idea what to try next.

Thanks
J

@JeffLIrion
Copy link
Collaborator Author

https://www.home-assistant.io/components/media_player.firetv/

I don't know what README you're referencing, but it's not necessary. There's no need to install any Python packages. It looks like maybe your adbkey path is wrong or the permissions of that file are wrong. Everything you need to know is in the documentation.

@joachimpr
Copy link

I followed that component link to a t... The README I am referring too is the one of this project (https://github.com/happyleavesaoc/python-firetv).

I will attempt a CHMOD on the file to give it permission to everyone and everything to see if that solves the problem. I did try both files in /home/pi/adbkey as well as /home/homeassistant/.homeassistant/adbkey (which according to my knowledge, the home assistant user should have access to. I will give it a bash anyway and provide feedback.

Thanks

@joachimpr
Copy link

Hi @JeffLIrion,

Ok, there seems to be some light at the end of the tunnel. I changed the permissions on the adbkey file and the above errors went away with a restart.

I was able to turn on the fire tv stick 4k using home assistant. Immediately after, it went into an unavailable state. an no changes on that since.

I tried:

  • Restatring the FireTV 4k Stick
  • adding get_source and get_sources = false as per another post (I remember reading about it somewhere but for the life of me cannot find the article.

It remains in an unavailable state in Home Assistant. I then removed the component from home assistant, restarted again and attempted the python code suggested above with the new permission set adbkey file. I still get the could not connect to host error as previously mentioned.

Any other tips / suggestions?

My home assistant is hassbian I believe and not hassio. If this helps at all.

Thanks
J

@JeffLIrion
Copy link
Collaborator Author

Try this custom component:
https://github.com/JeffLIrion/homeassistant_native_firetv/blob/pure-python-adb/media_player/firetv.py

Installation instructions (from the README:

Copy the media_player/firetv.py to your custom_components folder (custom_components/media_player/firetv.py) in your configuration directory. If you do not have a custom_components folder, then you will need to create it.

Use get_sources: false in your configuration.

This should be a bit more stable than the current component. Let me know how it works out.

@joachimpr
Copy link

Thanks @JeffLIrion. This seems to be a bit more stable... considering only a couple of minutes worth of testing. the confusing thing is that with this as my config:

  • platform: firetv
    name: Lounge Fire TV
    host: 192.168.88.159
    adbkey: "/home/homeassistant/.homeassistant/adbkey"
    get_source: false
    get_sources: false

it still shows the source of the current app? is this suppose to happen? Other question is, how do I tell it now to launch an app? Should I set the source in home assistant to the package name somehow in an automation? The documentation does not mention this feature.

Thanks for all your help so far. I really appreciate it.

@joachimpr
Copy link

joachimpr commented Jan 15, 2019

@JeffLIrion, at second glance, it does not really seem stable in the sense of displaying the states. it keeps jumping between Unavailable, idle, and now and then, paused... which is strange. So it is connecting but it seems like its dropping?

I don't really need to display the states on the dashboard or depend on them. I only have to turn it on and launch two apps... So this might still just work. I have managed to launch the app from home assistant by calling the select source service so I will add this to an automation and watch it for a couple of days. I will provide feedback around how it goes. Holding thumbs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Device authentication required, no keys available

5 participants