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'
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,