Do not expose search on ESPHome media players (#183396)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Paulus Schoutsen
2026-09-28 05:06:40 -04:00
committed by GitHub
co-authored by Claude
parent b9588e57de
commit dd0881aba1
2 changed files with 51 additions and 3 deletions
@@ -59,7 +59,8 @@ _STATES: EsphomeEnumMapper[EspMediaPlayerState, MediaPlayerState] = EsphomeEnumM
}
)
# The native API has no commands for these flags
# The native API has no commands for these flags, and the entity does not
# implement search
_UNSUPPORTED_FEATURES = (
EspMediaPlayerEntityFeature.SEEK
| EspMediaPlayerEntityFeature.PREVIOUS_TRACK
@@ -68,6 +69,7 @@ _UNSUPPORTED_FEATURES = (
| EspMediaPlayerEntityFeature.SELECT_SOUND_MODE
| EspMediaPlayerEntityFeature.SHUFFLE_SET
| EspMediaPlayerEntityFeature.GROUPING
| EspMediaPlayerEntityFeature.SEARCH_MEDIA
)
_FEATURES = {
@@ -85,7 +87,6 @@ _FEATURES = {
EspMediaPlayerEntityFeature.REPEAT_SET: MediaPlayerEntityFeature.REPEAT_SET,
EspMediaPlayerEntityFeature.MEDIA_ANNOUNCE: MediaPlayerEntityFeature.MEDIA_ANNOUNCE,
EspMediaPlayerEntityFeature.MEDIA_ENQUEUE: MediaPlayerEntityFeature.MEDIA_ENQUEUE,
EspMediaPlayerEntityFeature.SEARCH_MEDIA: MediaPlayerEntityFeature.SEARCH_MEDIA,
}
ATTR_BYPASS_PROXY = "bypass_proxy"
+48 -1
View File
@@ -24,6 +24,7 @@ from homeassistant.components.media_player import (
ATTR_MEDIA_ENQUEUE,
ATTR_MEDIA_EXTRA,
ATTR_MEDIA_REPEAT,
ATTR_MEDIA_SEARCH_QUERY,
ATTR_MEDIA_VOLUME_LEVEL,
ATTR_MEDIA_VOLUME_MUTED,
DOMAIN as MEDIA_PLAYER_DOMAIN,
@@ -33,6 +34,7 @@ from homeassistant.components.media_player import (
SERVICE_MEDIA_STOP,
SERVICE_PLAY_MEDIA,
SERVICE_REPEAT_SET,
SERVICE_SEARCH_MEDIA,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
SERVICE_VOLUME_DOWN,
@@ -49,7 +51,7 @@ from homeassistant.components.media_player import (
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.exceptions import ServiceNotSupported, ServiceValidationError
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.setup import async_setup_component
@@ -290,6 +292,51 @@ async def test_media_player_entity_with_undefined_flags(
)
async def test_media_player_entity_ignores_search_media_flag(
hass: HomeAssistant,
mock_client: APIClient,
mock_generic_device_entry: MockGenericDeviceEntryType,
) -> None:
"""Test that the SEARCH_MEDIA flag from the device is not exposed."""
entity_info = [
MediaPlayerInfo(
object_id="mymedia_player",
key=1,
name="my media_player",
supports_pause=True,
# PAUSE,PLAY,SEARCH_MEDIA
feature_flags=4210689,
)
]
states = [
MediaPlayerEntityState(
key=1, volume=50, muted=False, state=MediaPlayerState.PLAYING
)
]
await mock_generic_device_entry(
mock_client=mock_client,
entity_info=entity_info,
states=states,
)
state = hass.states.get("media_player.test_my_media_player")
assert state is not None
assert state.attributes["supported_features"] == (
MediaPlayerEntityFeature.PAUSE | MediaPlayerEntityFeature.PLAY
)
with pytest.raises(ServiceNotSupported):
await hass.services.async_call(
MEDIA_PLAYER_DOMAIN,
SERVICE_SEARCH_MEDIA,
{
ATTR_ENTITY_ID: "media_player.test_my_media_player",
ATTR_MEDIA_SEARCH_QUERY: "music",
},
blocking=True,
return_response=True,
)
async def test_media_player_entity_ignores_flags_without_command(
hass: HomeAssistant,
mock_client: APIClient,