-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Add media player device actions #35679
Conversation
Hi there @chmielowiec,
🙈 I need coffee... Good morning! ☕ |
# Add actions for each entity that belongs to this integration | ||
for action in ACTION_TYPES: | ||
action_config = ACTION_TYPES[action] | ||
if supported_features & action_config[CONF_SUPPORTED_FEATURES]: |
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.
Unclear what you want to check here. Given the the supported_features can be a bitwise combination like "SUPPORT_TURN_ON | SUPPORT_TURN_OFF" this is somewhat unclear. The check now will allow TURN_ON or TURN_OFF. It's enough with one of the feature. Is this what is wanted, or are both required? I suggest changing this to:
if ((supported_features & action_config[CONF_SUPPORTED_FEATURES]) == action_config[CONF_SUPPORTED_FEATURES])
And if the OR condition is also required, allow a list of features for the conf:
if (any((x & supported_feature) == x for x in action_config[CONF_SUPPORTED_FEATURES]))
That way it becomes clearer what is expected.
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 tried to do it same way services are registered, see here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/media_player/__init__.py#L218
After digging a bit more I found that core helper is broken in the same way: https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/service.py#L434
# Skip entities that don't have the required feature.
if required_features is not None and not any(
entity.supported_features & feature_set for feature_set in required_features
):
continue
It accepts list of required features, currently there is no difference whether you pass
[SUPPORT_A | SUPPORT_B]
or [SUPPORT_A, SUPPORT_B]
.
Should I fix this too? Impact of that change could be huge. Created #35718
I will adjust my code to match service registration, changing volumes check to list.
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.
Small note added. I think this mostly looks nice, but need more core review.
057b543
to
da7ba72
Compare
The problem we have with media players is that it is the only integration that treats supported features as a dynamic attribute where it describes the current capabilities of the media and not what the player can do. That's why this feature will not work as intended, because the returned triggers will be based on what media is playing ! |
It's based on service registration code here: core/homeassistant/components/media_player/__init__.py Lines 212 to 327 in f841648
How is it dynamic? Or maybe it shouldn't be based on services? Or should I remove getting supported_features from state and base it only on entity?core/homeassistant/components/media_player/device_action.py Lines 128 to 131 in da7ba72
|
Services are checked against supported features at the moment they are called. So if an entity doesn't support pause because nothing is playing, it won't do anything, and that's fine. However, device automations can be configured at any time. So checking the supported features will not return the right set of capabilities. I also think that we should not just wrap all services, as uh, then people can just use services. I think that we should close this PR for now, and re-address this issue once we have figured out a way to split out current_media_features out of supported_features. |
Proposed change
Add media player actions without extra arguments
Type of change
Example entry for
configuration.yaml
:# Example configuration.yaml
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale: