From 24a9da85c01c1f19452af4e82fd92838954fd8d8 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Tue, 13 Mar 2018 17:14:02 -0400 Subject: [PATCH] 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 * :lipstick: * Revert ":lipstick:" This reverts commit 81c08bb7323ec1242ee733bea8421c42243f6f63. * Revert "actually keep it" This reverts commit 0d92d3afb235876bf0af3b46e09202451ebe88c8. * Revert "remove unused import" This reverts commit 8a166208e496883f71e42d65dd9fab5f7c3d418c. * Revert "already in the default schema" This reverts commit 9173de4fd3bc962ad9f57fc966b1f11da0abb69e. * we're already ensuring defaults with the platform schema --- .../components/media_player/channels.py | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/media_player/channels.py b/homeassistant/components/media_player/channels.py index eda47237b44..480e5152c8e 100644 --- a/homeassistant/components/media_player/channels.py +++ b/homeassistant/components/media_player/channels.py @@ -45,7 +45,7 @@ SERVICE_SEEK_BY = 'channels_seek_by' ATTR_SECONDS = 'seconds' 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({ @@ -55,14 +55,12 @@ CHANNELS_SEEK_BY_SCHEMA = CHANNELS_SCHEMA.extend({ 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): """Setup the Channels platform.""" device = ChannelsPlayer( - config.get('name', DEFAULT_NAME), + config.get('name'), config.get(CONF_HOST), - config.get(CONF_PORT, DEFAULT_PORT) + config.get(CONF_PORT) ) if DATA_CHANNELS not in hass.data: @@ -73,22 +71,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None): def service_handler(service): """Handler for services.""" - entity_ids = service.data.get(ATTR_ENTITY_ID) + entity_id = service.data.get(ATTR_ENTITY_ID) - if entity_ids: - devices = [device for device in hass.data[DATA_CHANNELS] - if device.entity_id in entity_ids] - else: - devices = hass.data[DATA_CHANNELS] + device = next((device for device in hass.data[DATA_CHANNELS] if + device.entity_id == entity_id), None) - for device in devices: - if service.service == SERVICE_SEEK_FORWARD: - device.seek_forward() - elif service.service == SERVICE_SEEK_BACKWARD: - device.seek_backward() - elif service.service == SERVICE_SEEK_BY: - seconds = service.data.get('seconds') - device.seek_by(seconds) + if device is None: + _LOGGER.warning("Unable to find Channels with entity_id: %s", + entity_id) + return + + if service.service == SERVICE_SEEK_FORWARD: + device.seek_forward() + 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( DOMAIN, SERVICE_SEEK_FORWARD, service_handler,