From cbe50cd2ca7353f68bd71214915d90a62e002698 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 12 Nov 2026 10:55:31 +0100 Subject: [PATCH] Add action enums to songpal (#192199) --- .../components/songpal/media_player.py | 3 --- homeassistant/components/songpal/services.py | 22 ++++++++++++++----- tests/components/songpal/test_media_player.py | 8 +++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/songpal/media_player.py b/homeassistant/components/songpal/media_player.py index 841a3b3e1541..47d4cce81432 100644 --- a/homeassistant/components/songpal/media_player.py +++ b/homeassistant/components/songpal/media_player.py @@ -34,9 +34,6 @@ from .const import CONF_ENDPOINT, DOMAIN, ERROR_REQUEST_RETRY _LOGGER = logging.getLogger(__name__) -PARAM_NAME = "name" -PARAM_VALUE = "value" - INITIAL_RETRY_DELAY = 10 diff --git a/homeassistant/components/songpal/services.py b/homeassistant/components/songpal/services.py index fea5f1e5e0da..690eaa653950 100644 --- a/homeassistant/components/songpal/services.py +++ b/homeassistant/components/songpal/services.py @@ -1,5 +1,7 @@ """Support for Songpal-enabled (Sony) media devices.""" +from enum import StrEnum + import probatio from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN @@ -8,10 +10,18 @@ from homeassistant.helpers import config_validation as cv, service from .const import DOMAIN -PARAM_NAME = "name" -PARAM_VALUE = "value" -SET_SOUND_SETTING = "set_sound_setting" +class SongpalService(StrEnum): + """Store keys for Songpal services.""" + + SET_SOUND_SETTING = "set_sound_setting" + + +class SongpalServiceArgument(StrEnum): + """Store keys for Songpal service arguments.""" + + NAME = "name" + VALUE = "value" @callback @@ -20,11 +30,11 @@ def async_setup_services(hass: HomeAssistant) -> None: service.async_register_platform_entity_service( hass, DOMAIN, - SET_SOUND_SETTING, + SongpalService.SET_SOUND_SETTING, entity_domain=MEDIA_PLAYER_DOMAIN, schema={ - probatio.Required(PARAM_NAME): cv.string, - probatio.Required(PARAM_VALUE): cv.string, + probatio.Required(SongpalServiceArgument.NAME): cv.string, + probatio.Required(SongpalServiceArgument.VALUE): cv.string, }, func="async_set_sound_setting", ) diff --git a/tests/components/songpal/test_media_player.py b/tests/components/songpal/test_media_player.py index 86dced064cb5..4df26a78518a 100644 --- a/tests/components/songpal/test_media_player.py +++ b/tests/components/songpal/test_media_player.py @@ -19,7 +19,7 @@ from songpal.notification import SettingChange from homeassistant.components import media_player, songpal from homeassistant.components.media_player import MediaPlayerEntityFeature from homeassistant.components.songpal.const import ERROR_REQUEST_RETRY -from homeassistant.components.songpal.services import SET_SOUND_SETTING +from homeassistant.components.songpal.services import SongpalService from homeassistant.const import ( EVENT_HOMEASSISTANT_STOP, STATE_OFF, @@ -317,7 +317,7 @@ async def test_services(hass: HomeAssistant) -> None: await hass.services.async_call( songpal.DOMAIN, - SET_SOUND_SETTING, + SongpalService.SET_SOUND_SETTING, {"entity_id": ENTITY_ID, "name": "name", "value": "value"}, blocking=True, ) @@ -335,7 +335,7 @@ async def test_services(hass: HomeAssistant) -> None: await hass.services.async_call( songpal.DOMAIN, - SET_SOUND_SETTING, + SongpalService.SET_SOUND_SETTING, {"entity_id": "all", "name": "name", "value": "value"}, blocking=True, ) @@ -355,7 +355,7 @@ async def test_services(hass: HomeAssistant) -> None: await hass.services.async_call( songpal.DOMAIN, - SET_SOUND_SETTING, + SongpalService.SET_SOUND_SETTING, {"entity_id": "all", "name": "name", "value": "value"}, blocking=True, )