JeffLIrion / python-androidtv

Communicate with an Android TV or Fire TV device via ADB over a network.
MIT License
160 stars 57 forks source link

Android TV 12 devices not working properly #323

Open Dillton opened 1 year ago

Dillton commented 1 year ago

Hello.

After my Chromecast with Google TV received an update from Android 10 to Android 12 the state of the device is always only "off". ADB commands seems to be working at least for me however the key states like idle, playing, paused, etc. does not. Automations depends on those.

This is common issue for Android 12 devices, other users already reported this in different threads for example: https://github.com/home-assistant/core/issues/80555 https://github.com/home-assistant/core/issues/79154

@ollo69 recommends the issue should be opened here instead of HA/core as this problem is inside AndroidTV library.

@JeffLIrion Could you please check this issue? If you need logs or something let me know I can collect and provide them once I am home.

snp88 commented 1 year ago

Hi @Dillton

In readme of this repo owner said that he have no time to work on this project. I would not expect any fix soon. Someone from community need to check this. I think if HA officially use this repo should be take care by HA ;) but this is only my dream for perfect world

ollo69 commented 1 year ago

In readme of this repo owner said that he have no time to work on this project.

@JeffLIrion clear explain that he will not have time to work on fix, but PR are welcome. Anyone with some programming competence and a valid device for test can create PR on this repo, and I think that @JeffLIrion will found the time to review them. HA architecture is base on the fact that communication with devices are based on external and open source python library. This can be strength and weakness at the same time of this architecture, but that's it. I think that HA team will never work on external library, but this doesn't means that fix will not be implemented, this is just based on goodwill of the community.

breakthestatic commented 1 year ago

I think I might have found a fix for this already, but haven't had time to fully test & open a PR yet. It seems that the CMD_SCREEN_ON checks aren't sufficient for Android 12 on the Chromecast with Google TV. Adding a check for mScreenState=ON in the display output of dumpsys looks to correctly report the screen state, e.g.

CMD_SCREEN_ON = (
    "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true' || dumpsys display | grep -q 'mScreenState=ON')"
)

From there, since the screen is on, the rest of the logic seems to work so far. But once again, I haven't tested everything yet, and also haven't regression tested other devices (e.g. my Nvidia Shield).

I recall reading up a bit on a major architectural shift for this project during the last major Android version bump, but am not sure specifically what changed to make it easier to add more device-specific commands (perhaps something to do with custom commands???)

In the long-run, it would seem better to have device profiles (something like ZWaveJS does I think) instead of a lot of if android version == TARGET_VERSION then command x, else command y". E.g. have a base profile with the most common/standard adb commands that each device profile entry would inherit from and override any specific commands necessary for that device/version combo. I'm not a Python dev though, so an undertaking like that might be a bit more for me to attempt.

snp88 commented 1 year ago

I can help test this ;) I have valid device ;)

breakthestatic commented 1 year ago

I can help test this ;) I have valid device ;)

What type of install do you have? I'm running docker, so I had to shell into the container and manually make the edit to /usr/local/lib/python3.10/site-packages/androidtv/constants.py and restart the container afterwards. I'm not sure how different that would be for a supervised install (which I think also runs in a docker container?)

In any event, if you can get to that file in your install and change https://github.com/JeffLIrion/python-androidtv/blob/b1425b1b0d1d826e25948fad15ca3650433e3d5d/androidtv/constants.py#L179-L182 to the code snippet in my prior comment (here it is again):

CMD_SCREEN_ON = (
    "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true' || dumpsys display | grep -q 'mScreenState=ON')"
)

That should be the extent of the fix. At that point, once the state is being correctly derived, it will be much easier to test other parts of the AndroidTV integration to see if further Android 12 changes are needed in addition to the device state.

ollo69 commented 1 year ago

What type of install do you have? I'm running docker, so I had to shell into the container and manually make the edit to /usr/local/lib/python3.10/site-packages/androidtv/constants.py and restart the container afterwards

@breakthestatic, I suggest you to setup a HA dev environment as explained here. It's quite simple (it works with windows, linux or mac), will simplify your tests and will avoid to hack your default HA installation.

breakthestatic commented 1 year ago

What type of install do you have? I'm running docker, so I had to shell into the container and manually make the edit to /usr/local/lib/python3.10/site-packages/androidtv/constants.py and restart the container afterwards

@breakthestatic, I suggest you to setup a HA dev environment as explained here. It's quite simple (it works with windows, linux or mac), will simplify your tests and will avoid to hack your default HA installation.

I already have that set up but am not sure how to make the needed change since it's in this library, not HA core. To test the fix, I was already using the dev env, but still manually changing the python-androidtv file in site-packages.

Dillton commented 1 year ago

I can help test this ;) I have valid device ;)

What type of install do you have? I'm running docker, so I had to shell into the container and manually make the edit to /usr/local/lib/python3.10/site-packages/androidtv/constants.py and restart the container afterwards. I'm not sure how different that would be for a supervised install (which I think also runs in a docker container?)

In any event, if you can get to that file in your install and change

https://github.com/JeffLIrion/python-androidtv/blob/b1425b1b0d1d826e25948fad15ca3650433e3d5d/androidtv/constants.py#L179-L182

to the code snippet in my prior comment (here it is again):

CMD_SCREEN_ON = (
    "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true' || dumpsys display | grep -q 'mScreenState=ON')"
)

That should be the extent of the fix. At that point, once the state is being correctly derived, it will be much easier to test other parts of the AndroidTV integration to see if further Android 12 changes are needed in addition to the device state.

Evening. I can also help with testing with my Chromecast and so far I can say this seems to be the trick, thank you. Modifyed my container and did some real life usage: image image image

I will keep it modifyed like that and see. @breakthestatic Do you need some specific testing?

ihrapsa commented 1 year ago

I can confirm that this fixes the issue for me too (CCwGTV Android TV 12). Thanks!

snp88 commented 1 year ago

Hi All

i looking this path on my instance /usr/local/lib/python3.10/site-packages/androidtv/constants.py

But i cannot find it

first of all i don't have python 3.10 folder i have only 3.9 also don't have folder site-packages i have only dist-packages

My installation is on virtual machine and up to date

ihrapsa commented 1 year ago

Hi All

i looking this path on my instance /usr/local/lib/python3.10/site-packages/androidtv/constants.py

But i cannot find it

first of all i don't have python 3.10 folder i have only 3.9 also don't have folder site-packages i have only dist-packages

My installation is on virtual machine and up to date

If it's Hass os in a VM you need to access home assistant core docker container shell. docker exec -it $(docker ps -f name=homeassistant -q) bash

Dillton commented 1 year ago

@breakthestatic Found an additional problem so there might be needed additional modification of the code. The device goes off for 10 seconds sometimes as you can see on screen below: image

breakthestatic commented 1 year ago

@breakthestatic Found an additional problem so there might be needed additional modification of the code. The device goes off for 10 seconds sometimes as you can see on screen below: image

Not saying you are definitely wrong about needing some additional fixes, but I recall seeing behavior like this with the Nvidia Shield recently as well. I believe the integration polls the device every 10 seconds, so perhaps there is some logic that defaults the playing state to off if an individual poll result fails?

So far I haven't seen this myself on the Chromecast, but I have also not done much testing. I'll see if I can reproduce it if/when I have some spare time over the next few days. Also, if you are somewhat familiar w/ ADB as well, you could manually set up an ADB session on another computer and see if mScreenState actually changes its value during the time periods that HA is reporting it to be off.

breakthestatic commented 1 year ago

Just a quick follow-up regarding the intermittent off state... I ran through several states over the past ~ 45minutes (idle to standby, then playing through a full episode in Plex, back to idle after the episode ended & back to playing once the next episode started): Screen Shot 2022-10-24 at 12 46 53 PM

Once again, I'm not really familiar with the actual functionality of this library beyond the basic ADB commands used to determine state, but it seems like the off state is only set in a single place: https://github.com/JeffLIrion/python-androidtv/blob/b1425b1b0d1d826e25948fad15ca3650433e3d5d/androidtv/androidtv/base_androidtv.py#L112-L114 Looking at this piece of code, it seems that only two things can trigger it, either an incorrect screen_on value or when the current_app is set to off. I'm still not 100% sure if a failed poll could return what is eventually interpreted as an incorrect screen_on state. I tried faking it by pulling my ethernet cable for ~20 seconds, but HA correctly interpreted that as "unavailable" in that case (not off as is seen in your screenshot), so it seems unlikely that a dropped poll can cause it. That leaves either a truly incorrect reading of screen state (i.e if, for some reason your mScreenState isn't ON for that particular poll response), or an invalid current_app.

There's a bit more logic surrounding the state of current_app that I wasn't able to fully step through, but it seems like you could get a bad state via the custom state detection logic. Do you know what app was running when you saw this (and do you possibly have any custom state detection rules configured)? Without being able to reproduce this myself, & not having deep-enough knowledge of this library (or language for that matter 😆), I'm not sure how much further I could get with this.

ihrapsa commented 1 year ago

I was about to report this intermittent off state as well. For context I was watching HotD on hbomax 😅 and got some automations triggered based on the off state a couple of times. I'll try to reproduce it again although it seemed to be rather random. Screenshot_2022-10-25-00-18-20

Dillton commented 1 year ago

@breakthestatic Really does not matter which application I think. I was watching youtube and netflix yesterday and with both the same behaviour. Sometimes also state changed to standby even when it should be playing.

breakthestatic commented 1 year ago

Not really sure what's going on there :( My two Chromecasts have been very consistent with their state reporting since putting in the fix.

In Twitch, I noticed that whenever the stream goes from actively playing to buffering (doesn't happen often, but still), the state switches from playing to idle, so perhaps some of the logic I noted in my prior comment (the stuff concerning the app-specific state & fallback detection rules) is the cause. I believe at the bottom of base_androidtv.py, there's a single extra location where state is not explicitly set to pre-determined values (besides a couple app-specific rules for Bell Fibe & VRV, whatever those are): https://github.com/JeffLIrion/python-androidtv/blob/b1425b1b0d1d826e25948fad15ca3650433e3d5d/androidtv/androidtv/base_androidtv.py#L208-L210 It seems that condition is rather open-ended, in that as long as none of the app-specific rules above it trigger, and there is no media_session_state, it will try to get the overall state from the current audio state (as long as it isn't idle). If audio_state is off, that could also seemingly lead to what you guys are seeing.

Maybe you could try adding extra logging at the bottom to see what all the various state variables look like at the time the problem occurs (i.e. put it right before line 228 in base_androidtv.py):

_LOGGER.debug("screen_on: %s", screen_on)
_LOGGER.debug("current_app: %s", current_app)
_LOGGER.debug("media_session_state: %s", media_session_state)
_LOGGER.debug("audio_state: %s", audio_state)
pejotigrek commented 1 year ago

Screen Shot 2022-10-24 at 12 46 53 PM

a side-question @breakthestatic : did you reinstall/re-add your CCwGTV in HomeAssistant? I can see that the firmware shows "12" - mine CCwGTV upgraded itself over the night [probably - yesterday it was Android 10, today it's 12, and I didn't do anything ;)] but it still shows "10" in the firmware info in HA. of course all my automations stopped working [and I was using different ones according to which app is running with what state], but I'm too afraid to fiddle "with system" or try your hot fixes. I'll just wait patiently :)

also I've noticed that service androidtv.adb_command with command GET_PROPERTIES - doesn't give any new response, it just shows something old, not changed according to current state. it probably won't help you, but I didn't wanted to come here only with questions :)

breakthestatic commented 1 year ago

Hey @pejotigrek, I didn't reinstall my Chromecast, but I have both reloaded the integration, as well as completely restarted HA. I'm not sure which (or both) of those might have updated the firmware version, but I would definitely be sure that you are seeing the updated version before doing further debugging. When my Chromecast was updated to 12 (already said fw12 in HA), doing the GET_PROPERTIES call correctly populated the adb_response (just with the incorrect screen_on state).

pejotigrek commented 1 year ago

Hey @pejotigrek, I didn't reinstall my Chromecast, but I have both reloaded the integration, as well as completely restarted HA. I'm not sure which (or both) of those might have updated the firmware version, but I would definitely be sure that you are seeing the updated version before doing further debugging. When my Chromecast was updated to 12 (already said fw12 in HA), doing the GET_PROPERTIES call correctly populated the adb_response (just with the incorrect screen_on state).

ok checked now, reloading did the trick! thanks! :) also looks like GET_PROPERTIES was populated with updated info, but as I am away from home [which is empty right now] - I'll check the whole feedback little bit later [I assume that wakelocks etc. should work good]. thank you!

pejotigrek commented 1 year ago

ok, tested, my adb_response isn't correctly populated. from the whole feedback line: {'screen_on': False, 'awake': True, 'audio_state': None, 'wake_lock_size': 2, 'current_app': None, 'media_session_state': None, 'audio_output_device': None, 'is_volume_muted': None, 'volume': None, 'running_apps': None, 'hdmi_input': None} only the _wake_locksize changes with different integers [1-4] depending on what streaming app is used and what state it is. I suppose it's because I didn't made any changes to the python files.

breakthestatic commented 1 year ago

Yeah, I believe that most of the values are dependent on screen_on being correctly populated. Regrettably, without others contributing to debugging their specific issues, not sure when this will get fixed. I can definitely open a PR for the change, but I'm not sure it will get merged with several people still reporting abnormal state.

chatziko commented 1 year ago

I'm also affected by this. I applied the CMD_SCREEN_ON fix and restarted HA, everything seems to be working fine (thanks @breakthestatic). The state is reported correctly, and a few automations I have the rely on the app_id attribute and androidtv/adb_command look good (although I didn't do any extensive testing).

Let me know if you want me to test anything specific.

If the change works for some people and is unlikely to break anything, maybe it's worth releasing it so that others can test more easily without having to manually to edit code inside containers.

pejotigrek commented 1 year ago

If the change works for some people and is unlikely to break anything, maybe it's worth releasing it so that others can test more easily without having to manually to edit code inside containers.

maybe I'm too naive, but I guess that it won't be worse than "not working" as it is without fixes, so yeah, release would be cool :)

but maybe there's an relatively easy way to put it as custom integration - just for testing? so it could be checked without fiddling within dockers?

Dillton commented 1 year ago

Not really sure what's going on there :( My two Chromecasts have been very consistent with their state reporting since putting in the fix.

In Twitch, I noticed that whenever the stream goes from actively playing to buffering (doesn't happen often, but still), the state switches from playing to idle, so perhaps some of the logic I noted in my prior comment (the stuff concerning the app-specific state & fallback detection rules) is the cause. I believe at the bottom of base_androidtv.py, there's a single extra location where state is not explicitly set to pre-determined values (besides a couple app-specific rules for Bell Fibe & VRV, whatever those are):

https://github.com/JeffLIrion/python-androidtv/blob/b1425b1b0d1d826e25948fad15ca3650433e3d5d/androidtv/androidtv/base_androidtv.py#L208-L210

It seems that condition is rather open-ended, in that as long as none of the app-specific rules above it trigger, and there is no media_session_state, it will try to get the overall state from the current audio state (as long as it isn't idle). If audio_state is off, that could also seemingly lead to what you guys are seeing. Maybe you could try adding extra logging at the bottom to see what all the various state variables look like at the time the problem occurs (i.e. put it right before line 228 in base_androidtv.py):

_LOGGER.debug("screen_on: %s", screen_on)
_LOGGER.debug("current_app: %s", current_app)
_LOGGER.debug("media_session_state: %s", media_session_state)
_LOGGER.debug("audio_state: %s", audio_state)

Hi @breakthestatic I just added extra logging and will watch some movie today so hopefully we will learn something more about the states.

EDIT1: So far HA is not able to load the integration with added logging. EDIT2: Solved, cant use tabs only spaces in editor, oh my...

Dillton commented 1 year ago

Not really sure what's going on there :( My two Chromecasts have been very consistent with their state reporting since putting in the fix. In Twitch, I noticed that whenever the stream goes from actively playing to buffering (doesn't happen often, but still), the state switches from playing to idle, so perhaps some of the logic I noted in my prior comment (the stuff concerning the app-specific state & fallback detection rules) is the cause. I believe at the bottom of base_androidtv.py, there's a single extra location where state is not explicitly set to pre-determined values (besides a couple app-specific rules for Bell Fibe & VRV, whatever those are): https://github.com/JeffLIrion/python-androidtv/blob/b1425b1b0d1d826e25948fad15ca3650433e3d5d/androidtv/androidtv/base_androidtv.py#L208-L210

It seems that condition is rather open-ended, in that as long as none of the app-specific rules above it trigger, and there is no media_session_state, it will try to get the overall state from the current audio state (as long as it isn't idle). If audio_state is off, that could also seemingly lead to what you guys are seeing. Maybe you could try adding extra logging at the bottom to see what all the various state variables look like at the time the problem occurs (i.e. put it right before line 228 in base_androidtv.py):

_LOGGER.debug("screen_on: %s", screen_on)
_LOGGER.debug("current_app: %s", current_app)
_LOGGER.debug("media_session_state: %s", media_session_state)
_LOGGER.debug("audio_state: %s", audio_state)

Hi @breakthestatic I just added extra logging and will watch some movie today so hopefully we will learn something more about the states.

EDIT1: So far HA is not able to load the integration with added logging. EDIT2: Solved, cant use tabs only spaces in editor, oh my...

@breakthestatic Ok got some logs, you can check below. When state changes to off: 2022-10-28 21:09:19.164 DEBUG (MainThread) [androidtv.androidtv.base_androidtv] screen_on: False 2022-10-28 21:09:19.165 DEBUG (MainThread) [androidtv.androidtv.base_androidtv] current_app: None 2022-10-28 21:09:19.165 DEBUG (MainThread) [androidtv.androidtv.base_androidtv] media_session_state: None 2022-10-28 21:09:19.165 DEBUG (MainThread) [androidtv.androidtv.base_androidtv] audio_state: None

When state changes to standby: 2022-10-28 21:07:09.204 DEBUG (MainThread) [androidtv.androidtv.base_androidtv] screen_on: True 2022-10-28 21:07:09.204 DEBUG (MainThread) [androidtv.androidtv.base_androidtv] current_app: None 2022-10-28 21:07:09.204 DEBUG (MainThread) [androidtv.androidtv.base_androidtv] media_session_state: None 2022-10-28 21:07:09.204 DEBUG (MainThread) [androidtv.androidtv.base_androidtv] audio_state: None

image

Seems like no data available at that time?

breakthestatic commented 1 year ago

Hmm, so it seems likely the actual dumpsys response is incorrect when the problem occurs. The only extra logic that is performed before it gets to the state logic is an inversion. The actual ADB command performs a silent grep for the commands, which returns a 0 exit code when found (meaning it found one of the screen on strings), and an exit code of 1 when the grep fails. Since normal boolean logic treats 0 as false and 1 as true, there's a bit of code that flips the adb command response and returns 1 if the screen is on and 0 if it's off: https://github.com/JeffLIrion/python-androidtv/blob/b1425b1b0d1d826e25948fad15ca3650433e3d5d/androidtv/constants.py#L72-L73

Are you familiar with ADB at all? If so, perhaps you could set up an ADB connection to your Chromecast, and then either set up an automation to alert you when the media player's state changes to off and immediately issue the following command in your ADB shell (using whatever filename/location you want to output to):

adb shell dumpsys display > debug.log

or run a small loop that automatically saves the output every N seconds, e.g. (sorry for my likely poor shell scripting abilities):

while sleep 5; do date >> debug.log && adb shell dumpsys display >> debug.log; done

From there you can open the file and inspect all the various display state info at the time HA saw the errant state to see if maybe mScreenState isn't ON, and if that's the case, if there's another parameter that could be targeted instead.

Dillton commented 1 year ago

@breakthestatic Got the logs when HA sees OFF however mScreenState is ON in logs. You can check if you find something else. debug.log debug2.log

breakthestatic commented 1 year ago

Were these just manual dumps after noticing the player status switching to off? If that's the case (and even with the logging loop) there is a chance that the single call was different than one that occurred just before it.

@ollo69 or @JeffLIrion, are you familiar with the flow of data from the ADB commands in constants.py through to the HA state? I'm trying to see if we can get the raw data that ADB returns to determine if the ADB state is incorrect, or if it's something further downstream. I believe that it's something later on, or perhaps some different (but related) ADB call that is failing, but I'm not very well-versed in this and without being able to reproduce it myself, am having a hard time trying to get any data to help debug.

Dillton commented 1 year ago

Were these just manual dumps after noticing the player status switching to off? If that's the case (and even with the logging loop) there is a chance that the single call was different than one that occurred just before it.

Yes manual right after state changed. I didn't managed to get the loop work and had very little time this weekend so at least I got the manual log however I will take a look at the loop in the following days.

benrjunk commented 1 year ago

Confirming the fix below works for me as well (CCWGTV updated to Android 12 last night), with the same issue of "off status" being reported every several minutes. I have an automation set to update status of my CCWGTV every 3 seconds and that is the duration of the off status

Screenshot 2022-11-12 10 42 46

It appears this problem only occurs when the playstate is "Playing" or "Paused". Not an issue when device is standby or idle.

I am happy to help with debugging. Let me know what I can do.

I think I might have found a fix for this already, but haven't had time to fully test & open a PR yet. It seems that the CMD_SCREEN_ON checks aren't sufficient for Android 12 on the Chromecast with Google TV. Adding a check for mScreenState=ON in the display output of dumpsys looks to correctly report the screen state, e.g.

CMD_SCREEN_ON = (
    "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true' || dumpsys display | grep -q 'mScreenState=ON')"
)

From there, since the screen is on, the rest of the logic seems to work so far. But once again, I haven't tested everything yet, and also haven't regression tested other devices (e.g. my Nvidia Shield).

I recall reading up a bit on a major architectural shift for this project during the last major Android version bump, but am not sure specifically what changed to make it easier to add more device-specific commands (perhaps something to do with custom commands???)

In the long-run, it would seem better to have device profiles (something like ZWaveJS does I think) instead of a lot of if android version == TARGET_VERSION then command x, else command y". E.g. have a base profile with the most common/standard adb commands that each device profile entry would inherit from and override any specific commands necessary for that device/version combo. I'm not a Python dev though, so an undertaking like that might be a bit more for me to attempt.

Dillton commented 1 year ago

Hello @breakthestatic. Finally had time to loop the logging but unfortunatelly as you mentioned before there is no difference as with manual log. Below you can find collected logs so you can double check if I missed something. Log while state was playing starts on line 6556 changed to off line 6901. debug.log image

mattb112 commented 1 year ago

How Can I attempt this fix on Hassio?

meierthomas commented 1 year ago

Is anyone successfully using Android's sendevent command with the latest Android 12 based CCwGTV? sendevent replaces the default input command for those with a remote on Home Assistant and stopped working Android 10. My device is in another room so I can't use the Google remote

Redwid commented 1 year ago

I can help test this ;) I have valid device ;)

What type of install do you have? I'm running docker, so I had to shell into the container and manually make the edit to /usr/local/lib/python3.10/site-packages/androidtv/constants.py and restart the container afterwards. I'm not sure how different that would be for a supervised install (which I think also runs in a docker container?)

In any event, if you can get to that file in your install and change

https://github.com/JeffLIrion/python-androidtv/blob/b1425b1b0d1d826e25948fad15ca3650433e3d5d/androidtv/constants.py#L179-L182

to the code snippet in my prior comment (here it is again):

CMD_SCREEN_ON = (
    "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true' || dumpsys display | grep -q 'mScreenState=ON')"
)

That should be the extent of the fix. At that point, once the state is being correctly derived, it will be much easier to test other parts of the AndroidTV integration to see if further Android 12 changes are needed in addition to the device state.

I could confirm that helped me to recover my Google TV with android 12 as well on home-assistant integration.

ScottG489 commented 1 year ago

Are we aware of any official release notes or documentation from Google mentioning this change to dumpsys or the underlying system it queries in Android TV 12? This might give us more confidence in the change we're making. Here are some docs that might be valuable to review:

https://developer.android.com/about/versions/12/behavior-changes-12 https://developer.android.com/about/versions/12/behavior-changes-all

shadshack commented 1 year ago

I can also confirm that the CMD_SCREEN_ON fix corrects the hassio integration.

VoyteckPL commented 1 year ago

Hello, when this can be implemented into HA?

Victor4X commented 1 year ago

Hello, when this can be implemented into HA?

I'll make a PR with the mentioned CMD_SCREEN_ON change.

I have confirmed that this works to regain get_properties() functionality, but there are probably still changes that need to be made to address the dropout issues people are having: https://github.com/JeffLIrion/python-androidtv/issues/323#issuecomment-1312511072

I am not running this in HASS, as I wanted to have a good development environment, so I cannot confirm whether or not I see the dropout-issue. I will do some more testing on this today, however.

partymike commented 1 year ago

Is anyone able to provide a method to update the [python-androidtv/androidtv/constants.py] on hassio.core, the home assistant command line ext doesn't provide access and I don't think ha docker bash command works here?

Victor4X commented 1 year ago

Is anyone able to provide a method to update the [python-androidtv/androidtv/constants.py] on hassio.core, the home assistant command line ext doesn't provide access and I don't think ha docker bash command works here?

This specifically refers to Home Assistant OS setups, which might not be what you want

https://developers.home-assistant.io/docs/operating-system/debugging has instructions for ssh'ing into the supervisor, but they require physically inserting a USB drive into the host. Afterwards you can probably exec into the homeassistant docker container as mentioned here: https://community.home-assistant.io/t/editing-component-files-in-hassio/24273/6 (I think this might reset after a reboot though?)

There might be a way of doing it with custom components, but I haven't looked into it.

Tamas-Toth-ebola commented 1 year ago

Is anyone able to provide a method to update the [python-androidtv/androidtv/constants.py] on hassio.core, the home assistant command line ext doesn't provide access and I don't think ha docker bash command works here?

Sorry but I'm a bit confused. Do you refer HASSIO or HA - Core installation (throught Docker)? With the latter you can outsource the whole androidtv folder to a Docker volume, and therefore you can modify everything in it with permanens results. If you use HASSIO as an integrated solution that could be a 'bit' different.

Victor4X commented 1 year ago

Regarding the dropping out issue, I've been running a script that just calls the same update() method as HA every 5 seconds, and logging the returned properties. In a little over three hours of running with various different applications running on an Android TV 12 Chromecast, it didn't report the screen to be off a single time, nor did anything else look out of place.
This indicates that the problem might have something to do with what HA does with the data once it receives it, and not so much with what the component is actually getting from the Android TV.

I'll have to dig a little deeper to figure out what might be going on, but if anyone else experiencing the dropout issue could post some more information of how often it happens, and during what kind of operation, then that would be great.

edit: a lot more is going on when polling than I initially realized, so an actual HA connection might actually be easier.

gxgani commented 1 year ago

I've also noticed that you cannot control volume from the UI Slider/Automation for CCwGTV w/ Android 12. I use a home assistant docker based and androidtv volume is mapped to repo's latest code. Although controlling volume from Vol- Vol+ UI button works!

TRusselo commented 1 year ago

android 12 /google TV still broken on my home assistant core install Nov 30 update. always shows OFF state.
power button does control device, but state never changes state in home assistant.

TRusselo commented 1 year ago

looks like we are waiting for home-assistant to bump python-androidtv

chatziko commented 1 year ago

Most likely @JeffLIrion needs to publish a new pypi release before HA can bump it. The last one is still 0.0.69:

https://pypi.org/project/androidtv/#history

Afterwards a simple PR needs to be opened in home-assistant/core, like this one:

https://github.com/home-assistant/core/pull/80407/files

rs443 commented 1 year ago

Most likely @JeffLIrion needs to publish a new pypi release before HA can bump it. The last one is still 0.0.69:

androidtv 0.0.70 seems to be released just a few hours ago: https://pypi.org/project/androidtv/0.0.70/

chatziko commented 1 year ago

Just made a PR: https://github.com/home-assistant/core/pull/83707

VoyteckPL commented 1 year ago

Hi when can we expect this fix in HA officially?