Channels clean ups (#12967)

* already in the default schema

* these are already globally disabled

* require a single entity id

* remove unused import

* w h i t e s p a c e

* actually keep it

* it is a string

* use a generator expression

* 💄

* Revert "💄"

This reverts commit 81c08bb732.

* Revert "actually keep it"

This reverts commit 0d92d3afb2.

* Revert "remove unused import"

This reverts commit 8a166208e4.

* Revert "already in the default schema"

This reverts commit 9173de4fd3.

* we're already ensuring defaults with the platform schema
pull/13190/head
Jon Maddox 2018-03-13 17:14:02 -04:00 committed by Paulus Schoutsen
parent 71baa6532e
commit 24a9da85c0
1 changed files with 18 additions and 19 deletions

View File

@ -45,7 +45,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({
@ -55,14 +55,12 @@ CHANNELS_SEEK_BY_SCHEMA = CHANNELS_SCHEMA.extend({
REQUIREMENTS = ['pychannels==1.0.0'] REQUIREMENTS = ['pychannels==1.0.0']
# pylint: disable=unused-argument, abstract-method
# pylint: disable=too-many-instance-attributes
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Channels platform.""" """Setup the Channels platform."""
device = ChannelsPlayer( device = ChannelsPlayer(
config.get('name', DEFAULT_NAME), config.get('name'),
config.get(CONF_HOST), config.get(CONF_HOST),
config.get(CONF_PORT, DEFAULT_PORT) config.get(CONF_PORT)
) )
if DATA_CHANNELS not in hass.data: if DATA_CHANNELS not in hass.data:
@ -73,15 +71,16 @@ 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), None)
if device.entity_id in entity_ids]
else: if device is None:
devices = hass.data[DATA_CHANNELS] _LOGGER.warning("Unable to find Channels with entity_id: %s",
entity_id)
return
for device in devices:
if service.service == SERVICE_SEEK_FORWARD: if service.service == SERVICE_SEEK_FORWARD:
device.seek_forward() device.seek_forward()
elif service.service == SERVICE_SEEK_BACKWARD: elif service.service == SERVICE_SEEK_BACKWARD: