Add sonos.play_queue service (#24974)
* Add sonos.play_queue service * Add SERVICE_PLAY_QUEUE import in alphabetical order * Add queue_position parameter for sonos.play_queue service * Move queue_position default to schema definition
This commit is contained in:
parent
31f569ada9
commit
412910ca65
3 changed files with 32 additions and 4 deletions
|
@ -32,6 +32,7 @@ SERVICE_SET_TIMER = 'set_sleep_timer'
|
|||
SERVICE_CLEAR_TIMER = 'clear_sleep_timer'
|
||||
SERVICE_UPDATE_ALARM = 'update_alarm'
|
||||
SERVICE_SET_OPTION = 'set_option'
|
||||
SERVICE_PLAY_QUEUE = 'play_queue'
|
||||
|
||||
ATTR_SLEEP_TIME = 'sleep_time'
|
||||
ATTR_ALARM_ID = 'alarm_id'
|
||||
|
@ -42,6 +43,7 @@ ATTR_MASTER = 'master'
|
|||
ATTR_WITH_GROUP = 'with_group'
|
||||
ATTR_NIGHT_SOUND = 'night_sound'
|
||||
ATTR_SPEECH_ENHANCE = 'speech_enhance'
|
||||
ATTR_QUEUE_POSITION = 'queue_position'
|
||||
|
||||
SONOS_JOIN_SCHEMA = vol.Schema({
|
||||
vol.Required(ATTR_MASTER): cv.entity_id,
|
||||
|
@ -82,6 +84,11 @@ SONOS_SET_OPTION_SCHEMA = vol.Schema({
|
|||
vol.Optional(ATTR_SPEECH_ENHANCE): cv.boolean,
|
||||
})
|
||||
|
||||
SONOS_PLAY_QUEUE_SCHEMA = vol.Schema({
|
||||
vol.Required(ATTR_ENTITY_ID): cv.comp_entity_ids,
|
||||
vol.Optional(ATTR_QUEUE_POSITION, default=0): cv.positive_int,
|
||||
})
|
||||
|
||||
DATA_SERVICE_EVENT = 'sonos_service_idle'
|
||||
|
||||
|
||||
|
@ -134,6 +141,10 @@ async def async_setup(hass, config):
|
|||
DOMAIN, SERVICE_SET_OPTION, service_handle,
|
||||
schema=SONOS_SET_OPTION_SCHEMA)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_PLAY_QUEUE, service_handle,
|
||||
schema=SONOS_PLAY_QUEUE_SCHEMA)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
@ -27,10 +27,11 @@ from . import (
|
|||
CONF_ADVERTISE_ADDR, CONF_HOSTS, CONF_INTERFACE_ADDR,
|
||||
DATA_SERVICE_EVENT, DOMAIN as SONOS_DOMAIN,
|
||||
ATTR_ALARM_ID, ATTR_ENABLED, ATTR_INCLUDE_LINKED_ZONES, ATTR_MASTER,
|
||||
ATTR_NIGHT_SOUND, ATTR_SLEEP_TIME, ATTR_SPEECH_ENHANCE, ATTR_TIME,
|
||||
ATTR_VOLUME, ATTR_WITH_GROUP,
|
||||
SERVICE_CLEAR_TIMER, SERVICE_JOIN, SERVICE_RESTORE, SERVICE_SET_OPTION,
|
||||
SERVICE_SET_TIMER, SERVICE_SNAPSHOT, SERVICE_UNJOIN, SERVICE_UPDATE_ALARM)
|
||||
ATTR_NIGHT_SOUND, ATTR_QUEUE_POSITION, ATTR_SLEEP_TIME,
|
||||
ATTR_SPEECH_ENHANCE, ATTR_TIME, ATTR_VOLUME, ATTR_WITH_GROUP,
|
||||
SERVICE_CLEAR_TIMER, SERVICE_JOIN, SERVICE_PLAY_QUEUE, SERVICE_RESTORE,
|
||||
SERVICE_SET_OPTION, SERVICE_SET_TIMER, SERVICE_SNAPSHOT, SERVICE_UNJOIN,
|
||||
SERVICE_UPDATE_ALARM)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -149,6 +150,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
call = entity.set_alarm
|
||||
elif service == SERVICE_SET_OPTION:
|
||||
call = entity.set_option
|
||||
elif service == SERVICE_PLAY_QUEUE:
|
||||
call = entity.play_queue
|
||||
|
||||
hass.async_add_executor_job(call, data)
|
||||
|
||||
|
@ -1075,6 +1078,11 @@ class SonosEntity(MediaPlayerDevice):
|
|||
if ATTR_SPEECH_ENHANCE in data and self._speech_enhance is not None:
|
||||
self.soco.dialog_mode = data[ATTR_SPEECH_ENHANCE]
|
||||
|
||||
@soco_error()
|
||||
def play_queue(self, data):
|
||||
"""Start playing the queue."""
|
||||
self.soco.play_from_queue(data[ATTR_QUEUE_POSITION])
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return entity specific state attributes."""
|
||||
|
|
|
@ -65,3 +65,12 @@ set_option:
|
|||
description: Enable Speech Enhancement mode
|
||||
example: 'true'
|
||||
|
||||
play_queue:
|
||||
description: Starts playing the queue from the first item.
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name(s) of entities that will start playing.
|
||||
example: 'media_player.living_room_sonos'
|
||||
queue_position:
|
||||
description: Position of the song in the queue to start playing from.
|
||||
example: '0'
|
||||
|
|
Loading…
Add table
Reference in a new issue