Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Sonos services to sonos domain #23670

Merged
merged 1 commit into from May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 0 additions & 67 deletions homeassistant/components/media_player/services.yaml
Expand Up @@ -185,73 +185,6 @@ snapcast_restore:
description: Name(s) of entities that will be restored. Platform dependent.
example: 'media_player.living_room'

sonos_join:
description: Group player together.
fields:
master:
description: Entity ID of the player that should become the coordinator of the group.
example: 'media_player.living_room_sonos'
entity_id:
description: Name(s) of entities that will coordinate the grouping. Platform dependent.
example: 'media_player.living_room_sonos'

sonos_unjoin:
description: Unjoin the player from a group.
fields:
entity_id:
description: Name(s) of entities that will be unjoined from their group. Platform dependent.
example: 'media_player.living_room_sonos'

sonos_snapshot:
description: Take a snapshot of the media player.
fields:
entity_id:
description: Name(s) of entities that will be snapshot. Platform dependent.
example: 'media_player.living_room_sonos'
with_group:
description: True (default) or False. Snapshot with all group attributes.
example: 'true'

sonos_restore:
description: Restore a snapshot of the media player.
fields:
entity_id:
description: Name(s) of entities that will be restored. Platform dependent.
example: 'media_player.living_room_sonos'
with_group:
description: True (default) or False. Restore with all group attributes.
example: 'true'

sonos_set_sleep_timer:
description: Set a Sonos timer.
fields:
entity_id:
description: Name(s) of entities that will have a timer set.
example: 'media_player.living_room_sonos'
sleep_time:
description: Number of seconds to set the timer.
example: '900'

sonos_clear_sleep_timer:
description: Clear a Sonos timer.
fields:
entity_id:
description: Name(s) of entities that will have the timer cleared.
example: 'media_player.living_room_sonos'

sonos_set_option:
description: Set Sonos sound options.
fields:
entity_id:
description: Name(s) of entities that will have options set.
example: 'media_player.living_room_sonos'
night_sound:
description: Enable Night Sound mode
example: 'true'
speech_enhance:
description: Enable Speech Enhancement mode
example: 'true'

channels_seek_forward:
description: Seek forward by a set number of seconds.
fields:
Expand Down
97 changes: 96 additions & 1 deletion homeassistant/components/sonos/__init__.py
Expand Up @@ -3,8 +3,9 @@

from homeassistant import config_entries
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
from homeassistant.const import CONF_HOSTS
from homeassistant.const import CONF_HOSTS, ATTR_ENTITY_ID, ATTR_TIME
from homeassistant.helpers import config_entry_flow, config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send

DOMAIN = 'sonos'

Expand All @@ -21,6 +22,64 @@
}),
}, extra=vol.ALLOW_EXTRA)

SERVICE_JOIN = 'join'
SERVICE_UNJOIN = 'unjoin'
SERVICE_SNAPSHOT = 'snapshot'
SERVICE_RESTORE = 'restore'
SERVICE_SET_TIMER = 'set_sleep_timer'
SERVICE_CLEAR_TIMER = 'clear_sleep_timer'
SERVICE_UPDATE_ALARM = 'update_alarm'
SERVICE_SET_OPTION = 'set_option'

ATTR_SLEEP_TIME = 'sleep_time'
ATTR_ALARM_ID = 'alarm_id'
ATTR_VOLUME = 'volume'
ATTR_ENABLED = 'enabled'
ATTR_INCLUDE_LINKED_ZONES = 'include_linked_zones'
ATTR_MASTER = 'master'
ATTR_WITH_GROUP = 'with_group'
ATTR_NIGHT_SOUND = 'night_sound'
ATTR_SPEECH_ENHANCE = 'speech_enhance'

SONOS_JOIN_SCHEMA = vol.Schema({
vol.Required(ATTR_MASTER): cv.entity_id,
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
})

SONOS_UNJOIN_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
})

SONOS_STATES_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Optional(ATTR_WITH_GROUP, default=True): cv.boolean,
})

SONOS_SET_TIMER_SCHEMA = vol.Schema({
vol.Required(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Required(ATTR_SLEEP_TIME):
vol.All(vol.Coerce(int), vol.Range(min=0, max=86399))
})

SONOS_CLEAR_TIMER_SCHEMA = vol.Schema({
vol.Required(ATTR_ENTITY_ID): cv.comp_entity_ids,
})

SONOS_UPDATE_ALARM_SCHEMA = vol.Schema({
vol.Required(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Required(ATTR_ALARM_ID): cv.positive_int,
vol.Optional(ATTR_TIME): cv.time,
vol.Optional(ATTR_VOLUME): cv.small_float,
vol.Optional(ATTR_ENABLED): cv.boolean,
vol.Optional(ATTR_INCLUDE_LINKED_ZONES): cv.boolean,
})

SONOS_SET_OPTION_SCHEMA = vol.Schema({
vol.Required(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Optional(ATTR_NIGHT_SOUND): cv.boolean,
vol.Optional(ATTR_SPEECH_ENHANCE): cv.boolean,
})


async def async_setup(hass, config):
"""Set up the Sonos component."""
Expand All @@ -32,6 +91,42 @@ async def async_setup(hass, config):
hass.async_create_task(hass.config_entries.flow.async_init(
DOMAIN, context={'source': config_entries.SOURCE_IMPORT}))

async def service_handle(service):
"""Dispatch a service call."""
async_dispatcher_send(hass, DOMAIN, service.service, service.data)

hass.services.async_register(
DOMAIN, SERVICE_JOIN, service_handle,
schema=SONOS_JOIN_SCHEMA)

hass.services.async_register(
DOMAIN, SERVICE_UNJOIN, service_handle,
schema=SONOS_UNJOIN_SCHEMA)

hass.services.async_register(
DOMAIN, SERVICE_SNAPSHOT, service_handle,
schema=SONOS_STATES_SCHEMA)

hass.services.async_register(
DOMAIN, SERVICE_RESTORE, service_handle,
schema=SONOS_STATES_SCHEMA)

hass.services.async_register(
DOMAIN, SERVICE_SET_TIMER, service_handle,
schema=SONOS_SET_TIMER_SCHEMA)

hass.services.async_register(
DOMAIN, SERVICE_CLEAR_TIMER, service_handle,
schema=SONOS_CLEAR_TIMER_SCHEMA)

hass.services.async_register(
DOMAIN, SERVICE_UPDATE_ALARM, service_handle,
schema=SONOS_UPDATE_ALARM_SCHEMA)

hass.services.async_register(
DOMAIN, SERVICE_SET_OPTION, service_handle,
schema=SONOS_SET_OPTION_SCHEMA)

return True


Expand Down