Move songpal service registration (#162131)

This commit is contained in:
epenet
2026-02-03 11:15:05 +01:00
committed by GitHub
parent a715ec318c
commit d18630020f
5 changed files with 39 additions and 19 deletions

View File

@@ -9,6 +9,7 @@ from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
from .const import CONF_ENDPOINT, DOMAIN
from .services import async_setup_services
SONGPAL_CONFIG_SCHEMA = vol.Schema(
{vol.Optional(CONF_NAME): cv.string, vol.Required(CONF_ENDPOINT): cv.string}
@@ -24,6 +25,8 @@ PLATFORMS = [Platform.MEDIA_PLAYER]
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up songpal environment."""
async_setup_services(hass)
if (conf := config.get(DOMAIN)) is None:
return True
for config_entry in conf:

View File

@@ -1,7 +1,6 @@
"""Constants for the Songpal component."""
DOMAIN = "songpal"
SET_SOUND_SETTING = "set_sound_setting"
CONF_ENDPOINT = "endpoint"

View File

@@ -16,7 +16,6 @@ from songpal import (
VolumeChange,
)
from songpal.containers import Setting
import voluptuous as vol
from homeassistant.components.media_player import (
MediaPlayerDeviceClass,
@@ -28,11 +27,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers import (
config_validation as cv,
device_registry as dr,
entity_platform,
)
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import (
AddConfigEntryEntitiesCallback,
@@ -40,7 +35,7 @@ from homeassistant.helpers.entity_platform import (
)
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import CONF_ENDPOINT, DOMAIN, ERROR_REQUEST_RETRY, SET_SOUND_SETTING
from .const import CONF_ENDPOINT, DOMAIN, ERROR_REQUEST_RETRY
_LOGGER = logging.getLogger(__name__)
@@ -86,13 +81,6 @@ async def async_setup_entry(
songpal_entity = SongpalEntity(name, device)
async_add_entities([songpal_entity], True)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SET_SOUND_SETTING,
{vol.Required(PARAM_NAME): cv.string, vol.Required(PARAM_VALUE): cv.string},
"async_set_sound_setting",
)
class SongpalEntity(MediaPlayerEntity):
"""Class representing a Songpal device."""

View File

@@ -0,0 +1,32 @@
"""Support for Songpal-enabled (Sony) media devices."""
from __future__ import annotations
import voluptuous as vol
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
from homeassistant.core import HomeAssistant, callback
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"
@callback
def async_setup_services(hass: HomeAssistant) -> None:
"""Set up services."""
service.async_register_platform_entity_service(
hass,
DOMAIN,
SET_SOUND_SETTING,
entity_domain=MEDIA_PLAYER_DOMAIN,
schema={
vol.Required(PARAM_NAME): cv.string,
vol.Required(PARAM_VALUE): cv.string,
},
func="async_set_sound_setting",
)

View File

@@ -17,10 +17,8 @@ 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,
SET_SOUND_SETTING,
)
from homeassistant.components.songpal.const import ERROR_REQUEST_RETRY
from homeassistant.components.songpal.services import SET_SOUND_SETTING
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er