mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Update yolink "play on speaker hub" action to allow optional values (to match YoLink API) (#133099)
This commit is contained in:
parent
44b577cadb
commit
2a514ebc3f
@ -19,6 +19,11 @@ from .const import (
|
||||
|
||||
SERVICE_PLAY_ON_SPEAKER_HUB = "play_on_speaker_hub"
|
||||
|
||||
_SPEAKER_HUB_PLAY_CALL_OPTIONAL_ATTRS = (
|
||||
(ATTR_VOLUME, lambda x: x),
|
||||
(ATTR_TONE, lambda x: x.capitalize()),
|
||||
)
|
||||
|
||||
|
||||
def async_register_services(hass: HomeAssistant) -> None:
|
||||
"""Register services for YoLink integration."""
|
||||
@ -46,16 +51,16 @@ def async_register_services(hass: HomeAssistant) -> None:
|
||||
identifier[1]
|
||||
)
|
||||
) is not None:
|
||||
tone_param = service_data[ATTR_TONE].capitalize()
|
||||
play_request = ClientRequest(
|
||||
"playAudio",
|
||||
{
|
||||
ATTR_TONE: tone_param,
|
||||
ATTR_TEXT_MESSAGE: service_data[ATTR_TEXT_MESSAGE],
|
||||
ATTR_VOLUME: service_data[ATTR_VOLUME],
|
||||
ATTR_REPEAT: service_data[ATTR_REPEAT],
|
||||
},
|
||||
)
|
||||
params = {
|
||||
ATTR_TEXT_MESSAGE: service_data[ATTR_TEXT_MESSAGE],
|
||||
ATTR_REPEAT: service_data[ATTR_REPEAT],
|
||||
}
|
||||
|
||||
for attr, transform in _SPEAKER_HUB_PLAY_CALL_OPTIONAL_ATTRS:
|
||||
if attr in service_data:
|
||||
params[attr] = transform(service_data[attr])
|
||||
|
||||
play_request = ClientRequest("playAudio", params)
|
||||
await device_coordinator.device.call_device(play_request)
|
||||
|
||||
hass.services.async_register(
|
||||
@ -64,9 +69,9 @@ def async_register_services(hass: HomeAssistant) -> None:
|
||||
schema=vol.Schema(
|
||||
{
|
||||
vol.Required(ATTR_TARGET_DEVICE): cv.string,
|
||||
vol.Required(ATTR_TONE): cv.string,
|
||||
vol.Optional(ATTR_TONE): cv.string,
|
||||
vol.Required(ATTR_TEXT_MESSAGE): cv.string,
|
||||
vol.Required(ATTR_VOLUME): vol.All(
|
||||
vol.Optional(ATTR_VOLUME): vol.All(
|
||||
vol.Coerce(int), vol.Range(min=0, max=15)
|
||||
),
|
||||
vol.Optional(ATTR_REPEAT, default=0): vol.All(
|
||||
|
@ -14,7 +14,6 @@ play_on_speaker_hub:
|
||||
selector:
|
||||
text:
|
||||
tone:
|
||||
required: true
|
||||
default: "tip"
|
||||
selector:
|
||||
select:
|
||||
@ -25,7 +24,6 @@ play_on_speaker_hub:
|
||||
- "tip"
|
||||
translation_key: speaker_tone
|
||||
volume:
|
||||
required: true
|
||||
default: 8
|
||||
selector:
|
||||
number:
|
||||
@ -33,7 +31,6 @@ play_on_speaker_hub:
|
||||
max: 15
|
||||
step: 1
|
||||
repeat:
|
||||
required: true
|
||||
default: 0
|
||||
selector:
|
||||
number:
|
||||
|
@ -115,7 +115,7 @@
|
||||
},
|
||||
"volume": {
|
||||
"name": "Volume",
|
||||
"description": "Speaker volume during playback."
|
||||
"description": "Override the speaker volume during playback of this message only."
|
||||
},
|
||||
"repeat": {
|
||||
"name": "Repeat",
|
||||
|
Loading…
x
Reference in New Issue
Block a user