Fix PEEP257 issues

This commit is contained in:
Fabian Affolter 2016-03-08 17:55:57 +01:00
parent d784610c52
commit b534244e40
42 changed files with 335 additions and 308 deletions

View file

@ -1,4 +1,6 @@
"""
Support for scripts.
Scripts are a sequence of actions that can be triggered manually
by the user or automatically based upon automation events, etc.
@ -43,7 +45,7 @@ _LOGGER = logging.getLogger(__name__)
def is_on(hass, entity_id):
"""Returns if the switch is on based on the statemachine."""
"""Return if the switch is on based on the statemachine."""
return hass.states.is_state(entity_id, STATE_ON)
@ -60,7 +62,7 @@ def turn_off(hass, entity_id):
def toggle(hass, entity_id):
"""Toggles script."""
"""Toggle the script."""
hass.services.call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id})
@ -69,7 +71,7 @@ def setup(hass, config):
component = EntityComponent(_LOGGER, DOMAIN, hass)
def service_handler(service):
""" Execute a service call to script.<script name>. """
"""Execute a service call to script.<script name>."""
entity_id = ENTITY_ID_FORMAT.format(service.service)
script = component.entities.get(entity_id)
if not script:
@ -94,19 +96,19 @@ def setup(hass, config):
hass.services.register(DOMAIN, object_id, service_handler)
def turn_on_service(service):
"""Calls a service to turn script on."""
"""Call a service to turn script on."""
# We could turn on script directly here, but we only want to offer
# one way to do it. Otherwise no easy way to call invocations.
for script in component.extract_from_service(service):
turn_on(hass, script.entity_id)
def turn_off_service(service):
"""Cancels a script."""
"""Cancel a script."""
for script in component.extract_from_service(service):
script.turn_off()
def toggle_service(service):
"""Toggles a script."""
"""Toggle a script."""
for script in component.extract_from_service(service):
script.toggle()
@ -118,9 +120,11 @@ def setup(hass, config):
class Script(ToggleEntity):
"""Represents a script."""
"""Representation of a script."""
# pylint: disable=too-many-instance-attributes
def __init__(self, object_id, name, sequence):
"""Initialize the script."""
self.entity_id = ENTITY_ID_FORMAT.format(object_id)
self._name = name
self.sequence = sequence
@ -153,7 +157,7 @@ class Script(ToggleEntity):
@property
def is_on(self):
"""True if entity is on."""
"""Return true if script is on."""
return self._cur != -1
def turn_on(self, **kwargs):
@ -179,7 +183,7 @@ class Script(ToggleEntity):
elif CONF_DELAY in action:
# Call ourselves in the future to continue work
def script_delay(now):
""" Called after delay is done. """
"""Called after delay is done."""
self._listener = None
self.turn_on()
@ -206,7 +210,7 @@ class Script(ToggleEntity):
self._remove_listener()
def _call_service(self, action):
"""Calls the service specified in the action."""
"""Call the service specified in the action."""
# Backwards compatibility
if CONF_SERVICE not in action and CONF_SERVICE_OLD in action:
action[CONF_SERVICE] = action[CONF_SERVICE_OLD]
@ -220,7 +224,7 @@ class Script(ToggleEntity):
call_from_config(self.hass, action, True)
def _fire_event(self, action):
"""Fires an event."""
"""Fire an event."""
self._last_action = action.get(CONF_ALIAS, action[CONF_EVENT])
_LOGGER.info("Executing script %s step %s", self._name,
self._last_action)