mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 05:47:10 +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"
|
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:
|
def async_register_services(hass: HomeAssistant) -> None:
|
||||||
"""Register services for YoLink integration."""
|
"""Register services for YoLink integration."""
|
||||||
@ -46,16 +51,16 @@ def async_register_services(hass: HomeAssistant) -> None:
|
|||||||
identifier[1]
|
identifier[1]
|
||||||
)
|
)
|
||||||
) is not None:
|
) is not None:
|
||||||
tone_param = service_data[ATTR_TONE].capitalize()
|
params = {
|
||||||
play_request = ClientRequest(
|
ATTR_TEXT_MESSAGE: service_data[ATTR_TEXT_MESSAGE],
|
||||||
"playAudio",
|
ATTR_REPEAT: service_data[ATTR_REPEAT],
|
||||||
{
|
}
|
||||||
ATTR_TONE: tone_param,
|
|
||||||
ATTR_TEXT_MESSAGE: service_data[ATTR_TEXT_MESSAGE],
|
for attr, transform in _SPEAKER_HUB_PLAY_CALL_OPTIONAL_ATTRS:
|
||||||
ATTR_VOLUME: service_data[ATTR_VOLUME],
|
if attr in service_data:
|
||||||
ATTR_REPEAT: service_data[ATTR_REPEAT],
|
params[attr] = transform(service_data[attr])
|
||||||
},
|
|
||||||
)
|
play_request = ClientRequest("playAudio", params)
|
||||||
await device_coordinator.device.call_device(play_request)
|
await device_coordinator.device.call_device(play_request)
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
@ -64,9 +69,9 @@ def async_register_services(hass: HomeAssistant) -> None:
|
|||||||
schema=vol.Schema(
|
schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(ATTR_TARGET_DEVICE): cv.string,
|
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_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.Coerce(int), vol.Range(min=0, max=15)
|
||||||
),
|
),
|
||||||
vol.Optional(ATTR_REPEAT, default=0): vol.All(
|
vol.Optional(ATTR_REPEAT, default=0): vol.All(
|
||||||
|
@ -14,7 +14,6 @@ play_on_speaker_hub:
|
|||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
tone:
|
tone:
|
||||||
required: true
|
|
||||||
default: "tip"
|
default: "tip"
|
||||||
selector:
|
selector:
|
||||||
select:
|
select:
|
||||||
@ -25,7 +24,6 @@ play_on_speaker_hub:
|
|||||||
- "tip"
|
- "tip"
|
||||||
translation_key: speaker_tone
|
translation_key: speaker_tone
|
||||||
volume:
|
volume:
|
||||||
required: true
|
|
||||||
default: 8
|
default: 8
|
||||||
selector:
|
selector:
|
||||||
number:
|
number:
|
||||||
@ -33,7 +31,6 @@ play_on_speaker_hub:
|
|||||||
max: 15
|
max: 15
|
||||||
step: 1
|
step: 1
|
||||||
repeat:
|
repeat:
|
||||||
required: true
|
|
||||||
default: 0
|
default: 0
|
||||||
selector:
|
selector:
|
||||||
number:
|
number:
|
||||||
|
@ -115,7 +115,7 @@
|
|||||||
},
|
},
|
||||||
"volume": {
|
"volume": {
|
||||||
"name": "Volume",
|
"name": "Volume",
|
||||||
"description": "Speaker volume during playback."
|
"description": "Override the speaker volume during playback of this message only."
|
||||||
},
|
},
|
||||||
"repeat": {
|
"repeat": {
|
||||||
"name": "Repeat",
|
"name": "Repeat",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user