Multiroom support for snapcast (#24061)
* Multiroom support for snapcast * Moving services to the snapcast domain * Passing asyncio event via dispatcher instead of hass.data * Fixing lint
This commit is contained in:
1 parent
290d32267e
commit
caa7a3a3d6
6 files changed
+138
-34
No files matched your search
@@ -1 +1,48 @@
|
||||
"""The snapcast component."""
|
||||
|
||||
import asyncio
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
DOMAIN = 'snapcast'
|
||||
|
||||
SERVICE_SNAPSHOT = 'snapshot'
|
||||
SERVICE_RESTORE = 'restore'
|
||||
SERVICE_JOIN = 'join'
|
||||
SERVICE_UNJOIN = 'unjoin'
|
||||
|
||||
ATTR_MASTER = 'master'
|
||||
|
||||
SERVICE_SCHEMA = vol.Schema({
|
||||
vol.Required(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
})
|
||||
|
||||
JOIN_SERVICE_SCHEMA = SERVICE_SCHEMA.extend({
|
||||
vol.Required(ATTR_MASTER): cv.entity_id,
|
||||
})
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Handle service configuration."""
|
||||
service_event = asyncio.Event()
|
||||
|
||||
async def service_handle(service):
|
||||
"""Dispatch a service call."""
|
||||
service_event.clear()
|
||||
async_dispatcher_send(hass, DOMAIN, service_event, service.service,
|
||||
service.data)
|
||||
await service_event.wait()
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_SNAPSHOT, service_handle, schema=SERVICE_SCHEMA)
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_RESTORE, service_handle, schema=SERVICE_SCHEMA)
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_JOIN, service_handle, schema=JOIN_SERVICE_SCHEMA)
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_UNJOIN, service_handle, schema=SERVICE_SCHEMA)
|
||||
|
||||
return True
|
||||
Reference in new issue
Block a user