-
-
Notifications
You must be signed in to change notification settings - Fork 32k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump androidtv to 0.0.21; add 'state_detection_rules' config parameter #25647
Bump androidtv to 0.0.21; add 'state_detection_rules' config parameter #25647
Conversation
@@ -99,6 +103,9 @@ | |||
vol.Optional(CONF_APPS, default=dict()): vol.Schema({cv.string: cv.string}), | |||
vol.Optional(CONF_TURN_ON_COMMAND): cv.string, | |||
vol.Optional(CONF_TURN_OFF_COMMAND): cv.string, | |||
vol.Optional(CONF_STATE_DETECTION_RULES, default=dict()): vol.Schema( | |||
{cv.string: ha_state_detection_rules_validator(vol.Invalid)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validator would be more general purpose if it accepted a function instead of an exception. But it's ok like this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn’t 100% clear on what you meant by your previous post, but I thought this would fit the bill. It's basically the same function as before. I tested it out and it worked as expected, reporting error messages in the "Check config" box when something wasn't right.
I'd like to leave it as is, since I already tested it and published it on Pypi. But I'm also curious what you meant by your previous post.
Even better would be if we moved the whole validator to the library. We can do that by wrapping it in a factory function, that accepts a callback to be called when the validation fails. The callback should accept the message for the failed validation.
Then the user of the library can create a validator by calling the factory passing the callback. In our case the callback will raise
vol.Invalid
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have the validator factory accept a function as callback. We can do this:
def handle_invalid_rule(msg):
raise vol.Invalid(msg)
...
vol.Optional(CONF_STATE_DETECTION_RULES, default={}): vol.Schema(
{cv.string: ha_state_detection_rules_validator(handle_invalid_rule)}
...
A function is more flexible since another user of the library might want to do something else than raise an error.
We can keep it like it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
A couple of comments that could improve it.
Co-Authored-By: Martin Hjelmare <[email protected]>
Thanks for the review @MartinHjelmare! |
Description:
Bump
androidtv
to 0.0.20 and add thestate_detection_rules
config parameter.I have tested this code and it works. A tester on the forum also reported that it works. In addition, I added unit tests to the
androidtv
package to make sure that these user-specified state detection rules work as expected (JeffLIrion/python-androidtv#55).I'd really like to get this merged in because there are plenty of posts on the forum about "Android TV reports the wrong state for xyz app," but only a few users have submitted pull requests to the
androidtv
repo to help address this. The logic for determining the state differs from app to app and from one device to the next, so a universal solution is unrealistic. This will allow users to fine tune the state detection logic on their own, without the need for an update to theandroidtv
package followed by a version bump in the HA integration.Related issue (if applicable): #23346
It fixes this issue by allowing the user to specify their own rules for determining the state.
Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#10036
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest
.requirements_all.txt
by runningpython3 -m script.gen_requirements_all
.