Update docstrings to match PEP257

This commit is contained in:
Fabian Affolter committed 2016-03-07 18:50:30 +01:00
1 parent 7ff9aecd4e
commit b8a40457ee
40 files changed
+371 -483

No files matched your search

+18 -20
View File
@@ -1,6 +1,4 @@
"""
homeassistant.components.script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Scripts are a sequence of actions that can be triggered manually
by the user or automatically based upon automation events, etc.
@@ -45,30 +43,29 @@ _LOGGER = logging.getLogger(__name__)
def is_on(hass, entity_id):
""" Returns if the switch is on based on the statemachine. """
"""Returns if the switch is on based on the statemachine."""
return hass.states.is_state(entity_id, STATE_ON)
def turn_on(hass, entity_id):
""" Turn script on. """
"""Turn script on."""
_, object_id = split_entity_id(entity_id)
hass.services.call(DOMAIN, object_id)
def turn_off(hass, entity_id):
""" Turn script on. """
"""Turn script on."""
hass.services.call(DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id})
def toggle(hass, entity_id):
""" Toggles script. """
"""Toggles script."""
hass.services.call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id})
def setup(hass, config):
""" Load the scripts from the configuration. """
"""Load the scripts from the configuration."""
component = EntityComponent(_LOGGER, DOMAIN, hass)
def service_handler(service):
@@ -97,19 +94,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. """
"""Calls 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. """
"""Cancels a script."""
for script in component.extract_from_service(service):
script.turn_off()
def toggle_service(service):
""" Toggles a script. """
"""Toggles a script."""
for script in component.extract_from_service(service):
script.toggle()
@@ -121,7 +118,7 @@ def setup(hass, config):
class Script(ToggleEntity):
""" Represents a script. """
"""Represents a script."""
# pylint: disable=too-many-instance-attributes
def __init__(self, object_id, name, sequence):
self.entity_id = ENTITY_ID_FORMAT.format(object_id)
@@ -136,16 +133,17 @@ class Script(ToggleEntity):
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def name(self):
""" Returns the name of the entity. """
"""Return the name of the entity."""
return self._name
@property
def state_attributes(self):
""" Returns the state attributes. """
"""Return the state attributes."""
attrs = {}
if self._can_cancel:
attrs[ATTR_CAN_CANCEL] = self._can_cancel
@@ -155,11 +153,11 @@ class Script(ToggleEntity):
@property
def is_on(self):
""" True if entity is on. """
"""True if entity is on."""
return self._cur != -1
def turn_on(self, **kwargs):
""" Turn the entity on. """
"""Turn the entity on."""
_LOGGER.info("Executing script %s", self._name)
with self._lock:
if self._cur == -1:
@@ -197,7 +195,7 @@ class Script(ToggleEntity):
self.update_ha_state()
def turn_off(self, **kwargs):
""" Turn script off. """
"""Turn script off."""
_LOGGER.info("Cancelled script %s", self._name)
with self._lock:
if self._cur == -1:
@@ -208,7 +206,7 @@ class Script(ToggleEntity):
self._remove_listener()
def _call_service(self, action):
""" Calls the service specified in the action. """
"""Calls 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]
@@ -222,14 +220,14 @@ class Script(ToggleEntity):
call_from_config(self.hass, action, True)
def _fire_event(self, action):
""" Fires an event. """
"""Fires an event."""
self._last_action = action.get(CONF_ALIAS, action[CONF_EVENT])
_LOGGER.info("Executing script %s step %s", self._name,
self._last_action)
self.hass.bus.fire(action[CONF_EVENT], action.get(CONF_EVENT_DATA))
def _remove_listener(self):
""" Remove point in time listener, if any. """
"""Remove point in time listener, if any."""
if self._listener:
self.hass.bus.remove_listener(EVENT_TIME_CHANGED,
self._listener)