mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 21:29:58 -04:00
Move kef service registration to services module (#184830)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3c580cc572
commit
c2c52b2aaa
@@ -1 +1,16 @@
|
||||
"""The KEF Wireless Speakers component."""
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.platform_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the KEF Wireless Speakers component."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
"""Constants for the KEF Wireless Speakers integration."""
|
||||
|
||||
DOMAIN = "kef"
|
||||
@@ -7,7 +7,6 @@ import logging
|
||||
from typing import Any, override
|
||||
|
||||
from aiokef import AsyncKefSpeaker
|
||||
from aiokef.aiokef import DSP_OPTION_MAPPING
|
||||
from getmac import get_mac_address
|
||||
import probatio
|
||||
|
||||
@@ -20,11 +19,13 @@ from homeassistant.components.media_player import (
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_TYPE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_NAME = "KEF"
|
||||
@@ -34,8 +35,6 @@ DEFAULT_VOLUME_STEP = 0.05
|
||||
DEFAULT_INVERSE_SPEAKER_MODE = False
|
||||
DEFAULT_SUPPORTS_ON = True
|
||||
|
||||
DOMAIN = "kef"
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=30)
|
||||
|
||||
SOURCES = {"LSX": ["Wifi", "Bluetooth", "Aux", "Opt"]}
|
||||
@@ -47,15 +46,6 @@ CONF_INVERSE_SPEAKER_MODE = "inverse_speaker_mode"
|
||||
CONF_SUPPORTS_ON = "supports_on"
|
||||
CONF_STANDBY_TIME = "standby_time"
|
||||
|
||||
SERVICE_MODE = "set_mode"
|
||||
SERVICE_DESK_DB = "set_desk_db"
|
||||
SERVICE_WALL_DB = "set_wall_db"
|
||||
SERVICE_TREBLE_DB = "set_treble_db"
|
||||
SERVICE_HIGH_HZ = "set_high_hz"
|
||||
SERVICE_LOW_HZ = "set_low_hz"
|
||||
SERVICE_SUB_DB = "set_sub_db"
|
||||
SERVICE_UPDATE_DSP = "update_dsp"
|
||||
|
||||
DSP_SCAN_INTERVAL = timedelta(seconds=3600)
|
||||
|
||||
PLATFORM_SCHEMA = MEDIA_PLAYER_PLATFORM_SCHEMA.extend(
|
||||
@@ -148,44 +138,6 @@ async def async_setup_platform(
|
||||
hass.data[DOMAIN][host] = media_player
|
||||
async_add_entities([media_player], update_before_add=True)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_MODE,
|
||||
{
|
||||
probatio.Optional("desk_mode"): cv.boolean,
|
||||
probatio.Optional("wall_mode"): cv.boolean,
|
||||
probatio.Optional("phase_correction"): cv.boolean,
|
||||
probatio.Optional("high_pass"): cv.boolean,
|
||||
probatio.Optional("sub_polarity"): probatio.In(["-", "+"]),
|
||||
probatio.Optional("bass_extension"): probatio.In(
|
||||
["Less", "Standard", "Extra"]
|
||||
),
|
||||
},
|
||||
"set_mode",
|
||||
)
|
||||
platform.async_register_entity_service(SERVICE_UPDATE_DSP, None, "update_dsp")
|
||||
|
||||
def add_service(name, which, option):
|
||||
options = DSP_OPTION_MAPPING[which]
|
||||
dtype = type(options[0]) # int or float
|
||||
platform.async_register_entity_service(
|
||||
name,
|
||||
{
|
||||
probatio.Required(option): probatio.All(
|
||||
probatio.Coerce(float), probatio.Coerce(dtype), probatio.In(options)
|
||||
)
|
||||
},
|
||||
f"set_{which}",
|
||||
)
|
||||
|
||||
add_service(SERVICE_DESK_DB, "desk_db", "db_value")
|
||||
add_service(SERVICE_WALL_DB, "wall_db", "db_value")
|
||||
add_service(SERVICE_TREBLE_DB, "treble_db", "db_value")
|
||||
add_service(SERVICE_HIGH_HZ, "high_hz", "hz_value")
|
||||
add_service(SERVICE_LOW_HZ, "low_hz", "hz_value")
|
||||
add_service(SERVICE_SUB_DB, "sub_db", "db_value")
|
||||
|
||||
|
||||
class KefMediaPlayer(MediaPlayerEntity):
|
||||
"""Kef Player Object."""
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
"""Services for the KEF Wireless Speakers integration."""
|
||||
|
||||
from aiokef.aiokef import DSP_OPTION_MAPPING
|
||||
import probatio
|
||||
|
||||
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
|
||||
|
||||
SERVICE_MODE = "set_mode"
|
||||
SERVICE_DESK_DB = "set_desk_db"
|
||||
SERVICE_WALL_DB = "set_wall_db"
|
||||
SERVICE_TREBLE_DB = "set_treble_db"
|
||||
SERVICE_HIGH_HZ = "set_high_hz"
|
||||
SERVICE_LOW_HZ = "set_low_hz"
|
||||
SERVICE_SUB_DB = "set_sub_db"
|
||||
SERVICE_UPDATE_DSP = "update_dsp"
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the KEF Wireless Speakers integration."""
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_MODE,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema={
|
||||
probatio.Optional("desk_mode"): cv.boolean,
|
||||
probatio.Optional("wall_mode"): cv.boolean,
|
||||
probatio.Optional("phase_correction"): cv.boolean,
|
||||
probatio.Optional("high_pass"): cv.boolean,
|
||||
probatio.Optional("sub_polarity"): probatio.In(["-", "+"]),
|
||||
probatio.Optional("bass_extension"): probatio.In(
|
||||
["Less", "Standard", "Extra"]
|
||||
),
|
||||
},
|
||||
func="set_mode",
|
||||
)
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_UPDATE_DSP,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema=None,
|
||||
func="update_dsp",
|
||||
)
|
||||
|
||||
for name, which, option in (
|
||||
(SERVICE_DESK_DB, "desk_db", "db_value"),
|
||||
(SERVICE_WALL_DB, "wall_db", "db_value"),
|
||||
(SERVICE_TREBLE_DB, "treble_db", "db_value"),
|
||||
(SERVICE_HIGH_HZ, "high_hz", "hz_value"),
|
||||
(SERVICE_LOW_HZ, "low_hz", "hz_value"),
|
||||
(SERVICE_SUB_DB, "sub_db", "db_value"),
|
||||
):
|
||||
options = DSP_OPTION_MAPPING[which]
|
||||
dtype = type(options[0]) # int or float
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
name,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema={
|
||||
probatio.Required(option): probatio.All(
|
||||
probatio.Coerce(float), probatio.Coerce(dtype), probatio.In(options)
|
||||
)
|
||||
},
|
||||
func=f"set_{which}",
|
||||
)
|
||||
Reference in New Issue
Block a user