Open blakadder opened 3 years ago
To be honest, I have very little time to work on this package, and so it's mostly up to the community to contribute features and fixes.
This is something that needs to be done to unblock further development: https://github.com/JeffLIrion/python-androidtv/issues/255
With that in place, it would be easier to tailor commands as needed for different devices.
I just updated my Sony Bravia TV to Android 10 and there is the same issue - the integration stopped working correctly.
I just updated my Sony Bravia TV to Android 10 and there is the same issue - the integration stopped working correctly.
Yes, me too. Wasn't expecting that Android 10 will not be compatible because only Android 11 had been mentioned in the issues / Home Assistant alert.
Hi @blakadder and others, I have started working on Android 11 (maybe 10 as well) support; for starters very basic support is introduced here https://github.com/barmazu/python-androidtv/commit/c7b0a403cd3745f1e671ad63ad005da13f494d5e just by swapping commands that are send to ADB shell. It seems to restored some basic functionality, surely not all, but (some) states and apps are now reported correctly. Please note changes are not backward compatible (Android 9) yet. This is just test flight and I'm doing it on TCL C82 (A11). Further testing on different devices is welcomed, especially Android 10. Thanks!
source_list:
- com.android.systemui
- com.google.android.ext.services
- com.google.android.tvrecommendations
- com.google.android.tv.remote.service
- Play Store
- com.android.providers.media.module
- com.google.android.katniss:interactor
- com.tcl.inputmethod.international
- Android TV Launcher
- Spotify
- com.android.providers.tv
- com.google.android.katniss:search
- Google Cast
- Netflix
- com.tcl.system.server
- com.dolby.android.audio.service
- com.google.android.apps.nbu.smartconnect.tv
- com.tcl.usercenter
- '[com.tcl.usercen]'
- com.google.android.partnersetup
- com.google.android.apps.mediashell:privileged_process0
- com.google.android.gms
- com.google.android.gms.persistent
- com.google.process.gservices
- com.android.vending:instant_app_installer
- com.android.vending:background
- com.google.android.permissioncontroller
- com.google.android.gms.unstable
volume_level: 0.1
is_volume_muted: false
app_id: com.netflix.ninja
app_name: Netflix
source: Netflix
adb_response: >-
{'screen_on': True, 'awake': True, 'audio_state': 'paused', 'wake_lock_size':
3, 'current_app': 'com.netflix.ninja', 'media_session_state': 3,
'audio_output_device': 'speaker', 'is_volume_muted': False, 'volume': 10,
'running_apps': ['com.android.systemui', 'com.google.android.ext.services',
'com.google.android.tvrecommendations',
'com.google.android.tv.remote.service', 'com.android.vending',
'com.android.providers.media.module', 'com.google.android.katniss:interactor',
'com.tcl.inputmethod.international', 'com.google.android.tvlauncher',
'com.spotify.tv.android', 'com.android.providers.tv',
'com.google.android.katniss:search', 'com.google.android.apps.mediashell',
'com.netflix.ninja', 'com.tcl.system.server',
'com.dolby.android.audio.service',
'com.google.android.apps.nbu.smartconnect.tv', 'com.tcl.usercenter',
'[com.tcl.usercen]', 'com.google.android.partnersetup',
'com.google.android.apps.mediashell:privileged_process0',
'com.google.android.gms', 'com.google.android.gms.persistent',
'com.google.process.gservices', 'com.android.vending:instant_app_installer',
'com.android.vending:background', 'com.google.android.permissioncontroller',
'com.google.android.gms.unstable'], 'hdmi_input': None}
hdmi_input: null
friendly_name: TCL Smart TV
supported_features: 23997
So I've updated constants.py file, it should work on both domains, ie Android 9 and 11, see here: https://github.com/JeffLIrion/python-androidtv/compare/master...barmazu:a11_support?expand=1 You may update this file in your HA installation ( /usr/local/lib/python3.9/site-packages/androidtv/constants.py), test it out, report any issues... A few caveats though
media volume
command support), service call
does not work on TCL. Volume up / down buttons work.I'll push PR here once I update the Unit Tests (HDMI Sony TV seems like a major break point now)
@barmazu my comments in this post still stand true: https://github.com/JeffLIrion/python-androidtv/issues/271#issuecomment-925505211
The get_properties
method needs to use multiple ADB commands, rather than one giant ADB command. This would enable using different commands for different devices, OS versions, etc.
IMO, that is the right approach to resolving this issue, whereas modifying the existing commands is merely a band-aid fix that could introduce new issues.
I really don't have time to work on this myself, so I need someone to take on this effort of
get_properties
method into multiple ADB shell commands, each of which is its own methodHi @JeffLIrion! Agreed, I'm willing to do it but this is not a one day task, and honestly I didn't have much time either (to work around A11 support). With current implementation its awful, does not scale up at all, you don't have to say anything, this is obvious it would be very hard to maintain it; with still growing Android TV base it will be impossible to keep up.
Dirty patch I made is just unblocks me, maybe some other will take advantage and by any means does not replace necessary code refactoring. This is also my first meet with ATV from this side of things so I'm just looking around. Mostly.
Hey,
I will take a look to this on next days, may be next w.e., to see if I can help to split get_properties
method into multiple ADB shell commands as suggested by @JeffLIrion. If you have some additional suggestion on expected implementation report it here, otherwise I will create a PR when I will have something ready to discuss on.
I would like to test this on my android TV 10. I just don't know how to get it into my HA. Can anyone advise step by step installation?
I would like to test this on my android TV 10. I just don't know how to get it into my HA. Can anyone advise step by step installation?
Replace the file /usr/local/lib/python3.9/site-packages/androidtv/constants.py with this one.
Beware, the mentioned file is inside the homeassistant docker container though. I haven't tried it, but it seems that the android11 update for the nvidia shield is right around the corner.
Can confirm fork from @barmazu is working on Nvidia Shield TV 2017 with Android 11
It shows active app and state
source_list:
- com.android.systemui
- com.google.android.ext.services
- com.nvidia.blakepairing
- com.nvidia.shieldtech.accessoryui
- com.nvidia.shield.remote.server
- com.nvidia.osc
- com.nvidia.app.messaging
- com.android.providers.media.module
- flar2.homebutton
- net.dinglisch.android.taskerm
- com.appgeneration.itunerfree
- Spotify
- com.nvidia.shield.ask
- com.android.providers.tv
- Google Cast
- com.plexapp.mediaserver.smb:sambaserver
- com.nvidia.tegrazone3:PersonalGridService
- Kodi
- com.google.android.gms.persistent
- com.google.android.tv.remote.service
- com.google.android.tvrecommendations
- Android TV Launcher
- Play Store
- com.google.android.inputmethod.latin
- com.google.android.gms
- com.google.android.katniss:interactor
- com.google.android.katniss:search
- Netflix
- com.plexapp.mediaserver.smb
- com.google.process.gservices
volume_level: 0
is_volume_muted: false
app_id: com.netflix.ninja
app_name: Netflix
source: Netflix
adb_response: null
hdmi_input: null
friendly_name: Android TV 1
entity_picture: >-
/api/media_player_proxy/media_player.android_tv_1?token=ac9bcf744cd043f64a3485120bd18537baad3e0b79fea408e726bc17f73a3ca8&cache=1642029753.262722
supported_features: 23997
I would like to test this on my android TV 10. I just don't know how to get it into my HA. Can anyone advise step by step installation?
Replace the file /usr/local/lib/python3.9/site-packages/androidtv/constants.py with this one.
Beware, the mentioned file is inside the homeassistant docker container though. I haven't tried it, but it seems that the android11 update for the nvidia shield is right around the corner.
Do you know where i have to put the file in HassOS? The path u send doesnt exist :(
run "docker exec -it homeassistant bash" to launch terminal in container. There you will find the path.
I've logged into hassio through SSH and unfortunately i don't have a folder Pyhton inside lib only perl5 is available :
Do i have to create it ? (i've already Android TV integration though)
I figured out I needed to use "docker cp" command from outside the container to copy the new file over from the OS to within the docker. I use HA Core.
This is 90% reliable for me with my Nvidia shield on Android 11. The only issue I'm encountering (for my needs) is that every so often the media player state will randomly change to standby resulting in my lighting increasing in brightness.
@tungmeister wake_lock_size
and/or media_session_state
change when this happens?
@tungmeister
wake_lock_size
and/ormedia_session_state
change when this happens?
next time it happens I'll try and get the details.
@barmazu here's the response when watching youtube, hopefully I timed this correctly.
Looks good, but how this is different when you see "playing" state? How often state shifts from "playing" to "standby"? Does it stay for long in incorrect state? Have you tried to use custom state detection? So far I haven't seen such case on my TCL TV but I'll try to update Shield and see how that goes. Maybe this is specific to Android 11 implementation by Nvidia, who knows.
@barmazu here's the response when watching youtube, hopefully I timed this correctly.
Looks good, but how this is different when you see "playing" state? How often state shifts from "playing" to "standby"? Does it stay for long in incorrect state? Have you tried to use custom state detection? So far I haven't seen such case on my TCL TV but I'll try to update Shield and see how that goes. Maybe this is specific to Android 11 implementation by Nvidia, who knows.
it lasts for about 10 seconds or so. The problem as as soon as I "GET_PROPERTIES" that returns the right wait lock and session state so the lights dim again. It's happened maybe 8 times this evening. (4-5 hours of playback)
OK, that quite often I'd say.
Would you be so kind and check updated audio_state
detection cmds? Maybe it help as it also takes part in state detection?
Comment out old CMD_AUDIO_STATE and paste below:
CMD_AUDIO_STATE_RAW = "CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*state:.*$/h; ${x;p;}') && "
CMD_AUDIO_STATE = CMD_AUDIO_STATE_RAW + r"echo $CURRENT_AUDIO_STATE | grep paused >/dev/null 2>&1 && echo -e '1\c' || { echo $CURRENT_AUDIO_STATE | grep started >/dev/null 2>&1 && echo '2\c' || echo '0\c' ; }"
It will evaluate the very last audio player state entry (as seen by logs) which should be most recent app playing audio... Regarding PROPERTIES catching problem, just add adb_command to your dim automation :D
Thanks!
Sorry to bother you guys but, could somebody explain me how to be able to see folder Pyhton inside lib ?
Sorry to bother you guys but, could somebody explain me how to be able to see folder Pyhton inside lib ?
Not sure if same for you, but I didn't have a "local" folder with the Core Docker install. I had to skip that directory.
Thx @Iceman248 indeed skipping local fix it !
@barmazu I've updated the constants file, I'll do some further testing after I finish work today.
root@cupboard-domotica:/srv/homeassistant/lib/python3.9/site-packages/androidtv# ls -l
total 112
-rw-r--r-- 1 homeassistant homeassistant 3979 Jul 9 2021 __init__.py
drwxr-xr-x 2 homeassistant homeassistant 4096 Jan 14 11:26 __pycache__
drwxr-xr-x 3 homeassistant homeassistant 4096 Jul 9 2021 adb_manager
drwxr-xr-x 3 homeassistant homeassistant 4096 Jul 9 2021 androidtv
drwxr-xr-x 3 homeassistant homeassistant 4096 Jul 9 2021 basetv
-rw-r--r-- 1 homeassistant homeassistant 25076 Jan 14 11:25 constants.py
-rw-r--r-- 1 homeassistant homeassistant 23103 Jan 14 11:25 constants.py.backup
-rw-r--r-- 1 homeassistant homeassistant 25076 Jan 14 11:16 constants.py.new
-rw-r--r-- 1 homeassistant homeassistant 139 Jul 9 2021 exceptions.py
drwxr-xr-x 3 homeassistant homeassistant 4096 Jul 9 2021 firetv
-rw-r--r-- 1 homeassistant homeassistant 3017 Jul 9 2021 setup_async.py
root@cupboard-domotica:/srv/homeassistant/lib/python3.9/site-packages/androidtv#
root@cupboard-domotica:/srv/homeassistant/lib/python3.9/site-packages/androidtv# service homeassistant stop
root@cupboard-domotica:/srv/homeassistant/lib/python3.9/site-packages/androidtv# service homeassistant start
This seems to be working for me, using Homeassistant Core (on Debian 10 in venv) with Nvidia Shield on AndroidTV 11. Thanks for the fix!
This is 90% reliable for me with my Nvidia shield on Android 11. The only issue I'm encountering (for my needs) is that every so often the media player state will randomly change to standby resulting in my lighting increasing in brightness.
Having this 'problem' also
@megaperl have you tried the different audio state queries above? I can't test until this evening (UK)
@megaperl have you tried the different media state queries above? I can't test until this evening (UK)
Not yet, I can test it when I'm finished working and back home. (NL)
Thx @Iceman248 indeed skipping local fix it !
How to skip it?
Thx @Iceman248 indeed skipping local fix it !
How to skip it?
I was able to browse to /usr/lib/python3.9/site-packages, then i've done mkdir androidtv and do nano constants.py where i paste content from post https://github.com/JeffLIrion/python-androidtv/issues/271#issuecomment-1011126402
Just replaced constants.py with the new one and it did not do the trick for my shield. It still is behaving the same as the native integration. However I just noticed that constants.py is 24475 Bytes instead of the 25076 Bytes reported above by other users so I suspect the latest modification to the file somehow killed something. Thanks very much for this support
Applied the fix now at line 27 of constants.py
#: Get the audio state
## Android < 10 CMD_AUDIO_STATE = r"dumpsys audio | grep paused | grep -v 'Buffer Queue' >/dev/null 2>&1 && echo -e '1\c' || (dumpsys audio | grep started | grep -v 'Buffer Queue' >/dev/null 2>&1 && echo '2\c' || echo '0\c')"
#CMD_AUDIO_STATE_RAW = "CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*state:.*$/h; ${x;p;}') && "
#CMD_AUDIO_STATE = CMD_AUDIO_STATE_RAW + r"echo $CURRENT_AUDIO_STATE | grep paused >/dev/null 2>&1 && echo -e '1\c' || { echo $CURRENT_AUDIO_STATE | grep started >/dev/null 2>&1 && echo '2\c' || echo '0\c' ; }"
CMD_AUDIO_STATE_RAW = "CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*state:.*$/h; ${x;p;}') && "
CMD_AUDIO_STATE = CMD_AUDIO_STATE_RAW + r"echo $CURRENT_AUDIO_STATE | grep paused >/dev/null 2>&1 && echo -e '1\c' || { echo $CURRENT_AUDIO_STATE | grep started >/dev/null 2>&1 && echo '2\c' || echo '0\c' ; }"
Testing now, will report back later.
EDIT: never mind, there is no difference in the lines from the file I downloaded and the code I pasted above.
@barmazu the new audio state commands don't seem to have made any difference, after about 10 mins of playback my lights brightened back up again for a few seconds. I'll amend the automation to call the adb command and see if that returns anything of help.
Thanks for testing guys. I'm seeing this as well - its seems Shield specific issue (not seeing this on my A11 TCL TV) Give me some time to troubleshoot this a bit better.
@tungmeister @megapearl Hopefully I traced and fixed the issue; please take a look at updated constans.py file here Test it, let me know how it goes this time. I think it should be fine... But we will see ;-)
@barmazu New file fixes the issue for me. I used the older constants file, and was seeing my shield drop from Playing to Standby every couple of minutes. The newest one has been going for 2 hours now without dropping out of Playing.
please advise.
I have Odroid N2 + and HA installed on it (https://github.com/home-assistant/operating-system/releases/download/7.1/haos_odroid-n2-7.1.img.xz)
procedure what i did: in ssh - 1) "docker exec -it homeassistant bash" 2) "pip install androidtv" 3) "cd .." 4) "cd /usr/local/lib/python3.9/site-packages/androidtv/" 5) "rm constants.py" 6) "wget https://github.com/barmazu/python-androidtv/blob/a11_support/androidtv/constants.py"
in configuration.yaml I have this:
android tv status does not work.
system crashed:
and now there is no restart - it reports an error
I do not know what I am doing wrong :-( any advice?
@jrousek check that wget is doing its job correctly, as it might be pulling html code instead of the actual constants.py file
@jrousek You're using the wrong link for wget. For direct download, try this one
https://raw.githubusercontent.com/barmazu/python-androidtv/a11_support/androidtv/constants.py
@jrousek check that wget is doing its job correctly, as it might be pulling html code instead of the actual constants.py file
@jrousek You're using the wrong link for wget. For direct download, try this one
https://raw.githubusercontent.com/barmazu/python-androidtv/a11_support/androidtv/constants.py
You're right. I'm going to test.
Is this fix going to be implemented in Home Assistant?
So I already have the file uploaded. correct file.
It still doesn't show list of apps and more.
I have Odroid N2 + and HA installed on it (https://github.com/home-assistant/operating-system/releases/download/7.1/haos_odroid-n2-7.1.img.xz)
Android TV SET-TOP Box (Android 10, SKYworth HY4403)
My Installation procedure: in ssh -
1) "docker exec -it homeassistant bash" 2) "pip install androidtv" 3) "cd .." 4) "cd /usr/local/lib/python3.9/site-packages/androidtv/" 5) "rm constants.py" 6) "wget https://raw.githubusercontent.com/barmazu/python-androidtv/a11_support/androidtv/constants.py"
I don't know what to do next to make it work. If anyone needs more information I will be happy to provide it.
I created a custom component for this workaround you can use until home assistant implements a fix for android 11.
https://github.com/deviant-aut/HA-androidtv11
please let me know if it works for you
Happy to report that latest constants.py from @barmazu repo works for me on my shield, including volume control. Kudos
I can raise PR here but I feel that owner of this repository is very reluctant for any changes in this direction rather to rewrite the whole module logic from the ground-up (see previous/early comments in the thread for details) Many thanks for people that tested updated constants.py!
I can raise PR here but I feel that owner of this repository is very reluctant for any changes in this direction rather to rewrite the whole module logic from the ground-up (see previous/early comments in the thread for details) Many thanks for people that tested updated constants.py!
Thank you so much for providing a quick fix!
I created a custom component for this workaround you can use until home assistant implements a fix for android 11.
https://github.com/deviant-aut/HA-androidtv11
please let me know if it works for you
Thx @deviant-aut i guess we are in the good way
But when i try to confiugure the integratrion there is no text appearing :
Despite a CTRL F5 to clean cache.
@Moustik2002 : change the theme to the default one, might be related to that.
i don't use any custom theme, i have tried bright and dark without any result.
In the other hand when i look at the entity i have a lot of sources showing up:
So i guess it works :D
I have a TCL TV with Android TV 11 installed running on latest release HA (2021.9.7) and I the only states HA receives are Off,Idle and Standby with adb response: null in Developer - States tab.
I ran the commands through adb shell and these are the results:
gives no response
this works
Here's full output of dumpsys window and dumpsys activity starter in a gist link