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 commitpull/13190/head81c08bb732
. * Revert "actually keep it" This reverts commit0d92d3afb2
. * Revert "remove unused import" This reverts commit8a166208e4
. * Revert "already in the default schema" This reverts commit9173de4fd3
. * we're already ensuring defaults with the platform schema
parent
71baa6532e
commit
24a9da85c0
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue