require a single entity id

This commit is contained in:
Jon Maddox
2018-03-07 10:06:27 -05:00
parent d3a1160ac4
commit 3e20874fd2

View File

@@ -43,7 +43,7 @@ SERVICE_SEEK_BY = 'channels_seek_by'
ATTR_SECONDS = 'seconds' ATTR_SECONDS = 'seconds'
CHANNELS_SCHEMA = vol.Schema({ CHANNELS_SCHEMA = vol.Schema({
vol.Required(ATTR_ENTITY_ID): cv.entity_ids, vol.Required(ATTR_ENTITY_ID): cv.entity_id,
}) })
CHANNELS_SEEK_BY_SCHEMA = CHANNELS_SCHEMA.extend({ CHANNELS_SEEK_BY_SCHEMA = CHANNELS_SCHEMA.extend({
@@ -69,22 +69,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
def service_handler(service): def service_handler(service):
"""Handler for services.""" """Handler for services."""
entity_ids = service.data.get(ATTR_ENTITY_ID) entity_id = service.data.get(ATTR_ENTITY_ID)
if entity_ids: device = next([device for device in hass.data[DATA_CHANNELS] if
devices = [device for device in hass.data[DATA_CHANNELS] device.entity_id == entity_id].__iter__(), None)
if device.entity_id in entity_ids]
else:
devices = hass.data[DATA_CHANNELS]
for device in devices: if device is None:
if service.service == SERVICE_SEEK_FORWARD: _LOGGER.warning("Unable to find Channels with entity_id: %s",
device.seek_forward() str(entity_id))
elif service.service == SERVICE_SEEK_BACKWARD: return
device.seek_backward()
elif service.service == SERVICE_SEEK_BY: if service.service == SERVICE_SEEK_FORWARD:
seconds = service.data.get('seconds') device.seek_forward()
device.seek_by(seconds) elif service.service == SERVICE_SEEK_BACKWARD:
device.seek_backward()
elif service.service == SERVICE_SEEK_BY:
seconds = service.data.get('seconds')
device.seek_by(seconds)
hass.services.register( hass.services.register(
DOMAIN, SERVICE_SEEK_FORWARD, service_handler, DOMAIN, SERVICE_SEEK_FORWARD, service_handler,