mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 03:03:17 +01:00
Move songpal service registration (#162131)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Constants for the Songpal component."""
|
||||
|
||||
DOMAIN = "songpal"
|
||||
SET_SOUND_SETTING = "set_sound_setting"
|
||||
|
||||
CONF_ENDPOINT = "endpoint"
|
||||
|
||||
|
||||
@@ -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."""
|
||||
|
||||
32
homeassistant/components/songpal/services.py
Normal file
32
homeassistant/components/songpal/services.py
Normal 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",
|
||||
)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user