Modify docstrings to match PEP257

This commit is contained in:
Fabian Affolter 2016-03-07 17:14:55 +01:00
parent 5222c19b4c
commit 6ac9210919
9 changed files with 48 additions and 68 deletions

View File

@ -1,6 +1,5 @@
""" """
homeassistant.components.automation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to setup simple automation rules via the config file. Allows to setup simple automation rules via the config file.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
@ -35,7 +34,7 @@ _LOGGER = logging.getLogger(__name__)
def setup(hass, config): def setup(hass, config):
""" Sets up automation. """ """Setup the automation."""
config_key = DOMAIN config_key = DOMAIN
found = 1 found = 1
@ -64,8 +63,7 @@ def setup(hass, config):
def _setup_automation(hass, config_block, name, config): def _setup_automation(hass, config_block, name, config):
""" Setup one instance of automation """ """Setup one instance of automation."""
action = _get_action(hass, config_block.get(CONF_ACTION, {}), name) action = _get_action(hass, config_block.get(CONF_ACTION, {}), name)
if action is None: if action is None:
@ -83,14 +81,13 @@ def _setup_automation(hass, config_block, name, config):
def _get_action(hass, config, name): def _get_action(hass, config, name):
""" Return an action based on a config. """ """Return an action based on a configuration."""
if CONF_SERVICE not in config: if CONF_SERVICE not in config:
_LOGGER.error('Error setting up %s, no action specified.', name) _LOGGER.error('Error setting up %s, no action specified.', name)
return None return None
def action(): def action():
""" Action to be executed. """ """Action to be executed."""
_LOGGER.info('Executing %s', name) _LOGGER.info('Executing %s', name)
logbook.log_entry(hass, name, 'has been triggered', DOMAIN) logbook.log_entry(hass, name, 'has been triggered', DOMAIN)
@ -100,7 +97,7 @@ def _get_action(hass, config, name):
def _migrate_old_config(config): def _migrate_old_config(config):
""" Migrate old config to new. """ """Migrate old configuration to new."""
if CONF_PLATFORM not in config: if CONF_PLATFORM not in config:
return config return config
@ -134,8 +131,7 @@ def _migrate_old_config(config):
def _process_if(hass, config, p_config, action): def _process_if(hass, config, p_config, action):
""" Processes if checks. """ """Processes if checks."""
cond_type = p_config.get(CONF_CONDITION_TYPE, cond_type = p_config.get(CONF_CONDITION_TYPE,
DEFAULT_CONDITION_TYPE).lower() DEFAULT_CONDITION_TYPE).lower()
@ -165,12 +161,12 @@ def _process_if(hass, config, p_config, action):
if cond_type == CONDITION_TYPE_AND: if cond_type == CONDITION_TYPE_AND:
def if_action(): def if_action():
""" AND all conditions. """ """AND all conditions."""
if all(check() for check in checks): if all(check() for check in checks):
action() action()
else: else:
def if_action(): def if_action():
""" OR all conditions. """ """OR all conditions."""
if any(check() for check in checks): if any(check() for check in checks):
action() action()
@ -178,7 +174,7 @@ def _process_if(hass, config, p_config, action):
def _process_trigger(hass, config, trigger_configs, name, action): def _process_trigger(hass, config, trigger_configs, name, action):
""" Setup triggers. """ """Setup the triggers."""
if isinstance(trigger_configs, dict): if isinstance(trigger_configs, dict):
trigger_configs = [trigger_configs] trigger_configs = [trigger_configs]
@ -195,7 +191,7 @@ def _process_trigger(hass, config, trigger_configs, name, action):
def _resolve_platform(method, hass, config, platform): def _resolve_platform(method, hass, config, platform):
""" Find automation platform. """ """Find the automation platform."""
if platform is None: if platform is None:
return None return None
platform = prepare_setup_platform(hass, config, DOMAIN, platform) platform = prepare_setup_platform(hass, config, DOMAIN, platform)

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.automation.event
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Offers event listening automation rules. Offers event listening automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
@ -15,7 +13,7 @@ _LOGGER = logging.getLogger(__name__)
def trigger(hass, config, action): def trigger(hass, config, action):
""" Listen for events based on config. """ """Listen for events based on configuration."""
event_type = config.get(CONF_EVENT_TYPE) event_type = config.get(CONF_EVENT_TYPE)
if event_type is None: if event_type is None:
@ -25,7 +23,7 @@ def trigger(hass, config, action):
event_data = config.get(CONF_EVENT_DATA) event_data = config.get(CONF_EVENT_DATA)
def handle_event(event): def handle_event(event):
""" Listens for events and calls the action when data matches. """ """Listens for events and calls the action when data matches."""
if not event_data or all(val == event.data.get(key) for key, val if not event_data or all(val == event.data.get(key) for key, val
in event_data.items()): in event_data.items()):
action() action()

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.automation.mqtt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Offers MQTT listening automation rules. Offers MQTT listening automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
@ -17,7 +15,7 @@ CONF_PAYLOAD = 'payload'
def trigger(hass, config, action): def trigger(hass, config, action):
""" Listen for state changes based on `config`. """ """Listen for state changes based on configuration."""
topic = config.get(CONF_TOPIC) topic = config.get(CONF_TOPIC)
payload = config.get(CONF_PAYLOAD) payload = config.get(CONF_PAYLOAD)
@ -27,7 +25,7 @@ def trigger(hass, config, action):
return False return False
def mqtt_automation_listener(msg_topic, msg_payload, qos): def mqtt_automation_listener(msg_topic, msg_payload, qos):
""" Listens for MQTT messages. """ """Listens for MQTT messages."""
if payload is None or payload == msg_payload: if payload is None or payload == msg_payload:
action() action()

View File

@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
def _renderer(hass, value_template, state): def _renderer(hass, value_template, state):
"""Render state value.""" """Render the state value."""
if value_template is None: if value_template is None:
return state.state return state.state
@ -29,7 +29,7 @@ def _renderer(hass, value_template, state):
def trigger(hass, config, action): def trigger(hass, config, action):
""" Listen for state changes based on `config`. """ """Listen for state changes based on configuration."""
entity_id = config.get(CONF_ENTITY_ID) entity_id = config.get(CONF_ENTITY_ID)
if entity_id is None: if entity_id is None:
@ -50,8 +50,7 @@ def trigger(hass, config, action):
# pylint: disable=unused-argument # pylint: disable=unused-argument
def state_automation_listener(entity, from_s, to_s): def state_automation_listener(entity, from_s, to_s):
""" Listens for state changes and calls action. """ """Listens for state changes and calls action."""
# Fire action if we go from outside range into range # Fire action if we go from outside range into range
if _in_range(above, below, renderer(to_s)) and \ if _in_range(above, below, renderer(to_s)) and \
(from_s is None or not _in_range(above, below, renderer(from_s))): (from_s is None or not _in_range(above, below, renderer(from_s))):
@ -64,8 +63,7 @@ def trigger(hass, config, action):
def if_action(hass, config): def if_action(hass, config):
""" Wraps action method with state based condition. """ """Wraps action method with state based condition."""
entity_id = config.get(CONF_ENTITY_ID) entity_id = config.get(CONF_ENTITY_ID)
if entity_id is None: if entity_id is None:
@ -85,7 +83,7 @@ def if_action(hass, config):
renderer = partial(_renderer, hass, value_template) renderer = partial(_renderer, hass, value_template)
def if_numeric_state(): def if_numeric_state():
""" Test numeric state condition. """ """Test numeric state condition."""
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
return state is not None and _in_range(above, below, renderer(state)) return state is not None and _in_range(above, below, renderer(state))
@ -93,7 +91,7 @@ def if_action(hass, config):
def _in_range(range_start, range_end, value): def _in_range(range_start, range_end, value):
""" Checks if value is inside the range """ """Checks if value is inside the range."""
try: try:
value = float(value) value = float(value)
except ValueError: except ValueError:

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.automation.state
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Offers state listening automation rules. Offers state listening automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
@ -25,7 +23,7 @@ CONF_FOR = "for"
def get_time_config(config): def get_time_config(config):
""" Helper function to extract the time specified in the config """ """Helper function to extract the time specified in the configuration."""
if CONF_FOR not in config: if CONF_FOR not in config:
return None return None
@ -51,7 +49,7 @@ def get_time_config(config):
def trigger(hass, config, action): def trigger(hass, config, action):
""" Listen for state changes based on `config`. """ """Listen for state changes based on configuration."""
entity_id = config.get(CONF_ENTITY_ID) entity_id = config.get(CONF_ENTITY_ID)
if entity_id is None: if entity_id is None:
@ -72,17 +70,18 @@ def trigger(hass, config, action):
return None return None
def state_automation_listener(entity, from_s, to_s): def state_automation_listener(entity, from_s, to_s):
""" Listens for state changes and calls action. """ """Listens for state changes and calls action."""
def state_for_listener(now): def state_for_listener(now):
""" Fires on state changes after a delay and calls action. """ """Fires on state changes after a delay and calls action."""
hass.bus.remove_listener( hass.bus.remove_listener(
EVENT_STATE_CHANGED, for_state_listener) EVENT_STATE_CHANGED, for_state_listener)
action() action()
def state_for_cancel_listener(entity, inner_from_s, inner_to_s): def state_for_cancel_listener(entity, inner_from_s, inner_to_s):
""" Fires on state changes and cancels """
for listener if state changed. """ Fires on state changes and cancels for listener if state changed.
"""
if inner_to_s == to_s: if inner_to_s == to_s:
return return
hass.bus.remove_listener(EVENT_TIME_CHANGED, for_time_listener) hass.bus.remove_listener(EVENT_TIME_CHANGED, for_time_listener)
@ -106,7 +105,7 @@ def trigger(hass, config, action):
def if_action(hass, config): def if_action(hass, config):
""" Wraps action method with state based condition. """ """Wraps action method with state based condition."""
entity_id = config.get(CONF_ENTITY_ID) entity_id = config.get(CONF_ENTITY_ID)
state = config.get(CONF_STATE) state = config.get(CONF_STATE)
@ -123,7 +122,7 @@ def if_action(hass, config):
state = str(state) state = str(state)
def if_state(): def if_state():
""" Test if condition. """ """Test if condition."""
is_state = hass.states.is_state(entity_id, state) is_state = hass.states.is_state(entity_id, state)
return (time_delta is None and is_state or return (time_delta is None and is_state or
time_delta is not None and time_delta is not None and

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.automation.sun
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Offers sun based automation rules. Offers sun based automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
@ -29,7 +27,7 @@ _LOGGER = logging.getLogger(__name__)
def trigger(hass, config, action): def trigger(hass, config, action):
""" Listen for events based on config. """ """Listen for events based on configuration."""
event = config.get(CONF_EVENT) event = config.get(CONF_EVENT)
if event is None: if event is None:
@ -55,7 +53,7 @@ def trigger(hass, config, action):
def if_action(hass, config): def if_action(hass, config):
""" Wraps action method with sun based condition. """ """Wraps action method with sun based condition."""
before = config.get(CONF_BEFORE) before = config.get(CONF_BEFORE)
after = config.get(CONF_AFTER) after = config.get(CONF_AFTER)
@ -106,8 +104,7 @@ def if_action(hass, config):
return sun.next_setting(hass) + after_offset return sun.next_setting(hass) + after_offset
def time_if(): def time_if():
""" Validate time based if-condition """ """Validate time based if-condition."""
now = dt_util.now() now = dt_util.now()
before = before_func() before = before_func()
after = after_func() after = after_func()
@ -126,6 +123,7 @@ def if_action(hass, config):
def _parse_offset(raw_offset): def _parse_offset(raw_offset):
"""Parse the offset."""
if raw_offset is None: if raw_offset is None:
return timedelta(0) return timedelta(0)

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.automation.template
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Offers template automation rules. Offers template automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
@ -16,7 +14,7 @@ _LOGGER = logging.getLogger(__name__)
def trigger(hass, config, action): def trigger(hass, config, action):
""" Listen for state changes based on `config`. """ """Listen for state changes based on configuration."""
value_template = config.get(CONF_VALUE_TEMPLATE) value_template = config.get(CONF_VALUE_TEMPLATE)
if value_template is None: if value_template is None:
@ -27,7 +25,7 @@ def trigger(hass, config, action):
already_triggered = False already_triggered = False
def event_listener(event): def event_listener(event):
""" Listens for state changes and calls action. """ """Listens for state changes and calls action."""
nonlocal already_triggered nonlocal already_triggered
template_result = _check_template(hass, value_template) template_result = _check_template(hass, value_template)
@ -43,8 +41,7 @@ def trigger(hass, config, action):
def if_action(hass, config): def if_action(hass, config):
""" Wraps action method with state based condition. """ """Wraps action method with state based condition."""
value_template = config.get(CONF_VALUE_TEMPLATE) value_template = config.get(CONF_VALUE_TEMPLATE)
if value_template is None: if value_template is None:
@ -55,7 +52,7 @@ def if_action(hass, config):
def _check_template(hass, value_template): def _check_template(hass, value_template):
""" Checks if result of template is true """ """Checks if result of template is true."""
try: try:
value = template.render(hass, value_template, {}) value = template.render(hass, value_template, {})
except TemplateError: except TemplateError:

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.automation.time
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Offers time listening automation rules. Offers time listening automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
@ -24,7 +22,7 @@ _LOGGER = logging.getLogger(__name__)
def trigger(hass, config, action): def trigger(hass, config, action):
""" Listen for state changes based on `config`. """ """Listen for state changes based on configuration."""
if CONF_AFTER in config: if CONF_AFTER in config:
after = dt_util.parse_time_str(config[CONF_AFTER]) after = dt_util.parse_time_str(config[CONF_AFTER])
if after is None: if after is None:
@ -42,7 +40,7 @@ def trigger(hass, config, action):
return False return False
def time_automation_listener(now): def time_automation_listener(now):
""" Listens for time changes and calls action. """ """Listens for time changes and calls action."""
action() action()
track_time_change(hass, time_automation_listener, track_time_change(hass, time_automation_listener,
@ -52,7 +50,7 @@ def trigger(hass, config, action):
def if_action(hass, config): def if_action(hass, config):
""" Wraps action method with time based condition. """ """Wraps action method with time based condition."""
before = config.get(CONF_BEFORE) before = config.get(CONF_BEFORE)
after = config.get(CONF_AFTER) after = config.get(CONF_AFTER)
weekday = config.get(CONF_WEEKDAY) weekday = config.get(CONF_WEEKDAY)
@ -76,7 +74,7 @@ def if_action(hass, config):
return None return None
def time_if(): def time_if():
""" Validate time based if-condition """ """Validate time based if-condition."""
now = dt_util.now() now = dt_util.now()
if before is not None and now > now.replace(hour=before.hour, if before is not None and now > now.replace(hour=before.hour,
minute=before.minute): minute=before.minute):
@ -99,7 +97,7 @@ def if_action(hass, config):
def _error_time(value, key): def _error_time(value, key):
""" Helper method to print error. """ """Helper method to print error."""
_LOGGER.error( _LOGGER.error(
"Received invalid value for '%s': %s", key, value) "Received invalid value for '%s': %s", key, value)
if isinstance(value, int): if isinstance(value, int):

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.automation.zone
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Offers zone automation rules. Offers zone automation rules.
For more details about this automation rule, please refer to the documentation For more details about this automation rule, please refer to the documentation
@ -22,7 +20,7 @@ DEFAULT_EVENT = EVENT_ENTER
def trigger(hass, config, action): def trigger(hass, config, action):
""" Listen for state changes based on `config`. """ """Listen for state changes based on configuration."""
entity_id = config.get(CONF_ENTITY_ID) entity_id = config.get(CONF_ENTITY_ID)
zone_entity_id = config.get(CONF_ZONE) zone_entity_id = config.get(CONF_ZONE)
@ -35,7 +33,7 @@ def trigger(hass, config, action):
event = config.get(CONF_EVENT, DEFAULT_EVENT) event = config.get(CONF_EVENT, DEFAULT_EVENT)
def zone_automation_listener(entity, from_s, to_s): def zone_automation_listener(entity, from_s, to_s):
""" Listens for state changes and calls action. """ """Listens for state changes and calls action."""
if from_s and None in (from_s.attributes.get(ATTR_LATITUDE), if from_s and None in (from_s.attributes.get(ATTR_LATITUDE),
from_s.attributes.get(ATTR_LONGITUDE)) or \ from_s.attributes.get(ATTR_LONGITUDE)) or \
None in (to_s.attributes.get(ATTR_LATITUDE), None in (to_s.attributes.get(ATTR_LATITUDE),
@ -57,7 +55,7 @@ def trigger(hass, config, action):
def if_action(hass, config): def if_action(hass, config):
""" Wraps action method with zone based condition. """ """Wraps action method with zone based condition."""
entity_id = config.get(CONF_ENTITY_ID) entity_id = config.get(CONF_ENTITY_ID)
zone_entity_id = config.get(CONF_ZONE) zone_entity_id = config.get(CONF_ZONE)
@ -68,14 +66,14 @@ def if_action(hass, config):
return False return False
def if_in_zone(): def if_in_zone():
""" Test if condition. """ """Test if condition."""
return _in_zone(hass, zone_entity_id, hass.states.get(entity_id)) return _in_zone(hass, zone_entity_id, hass.states.get(entity_id))
return if_in_zone return if_in_zone
def _in_zone(hass, zone_entity_id, state): def _in_zone(hass, zone_entity_id, state):
""" Check if state is in zone. """ """Check if state is in zone."""
if not state or None in (state.attributes.get(ATTR_LATITUDE), if not state or None in (state.attributes.get(ATTR_LATITUDE),
state.attributes.get(ATTR_LONGITUDE)): state.attributes.get(ATTR_LONGITUDE)):
return False return False