diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 9c464f6954e..cff61829f19 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -1,6 +1,5 @@ """ -homeassistant.components.automation -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Allows to setup simple automation rules via the config file. For more details about this component, please refer to the documentation at @@ -35,7 +34,7 @@ _LOGGER = logging.getLogger(__name__) def setup(hass, config): - """ Sets up automation. """ + """Setup the automation.""" config_key = DOMAIN found = 1 @@ -64,8 +63,7 @@ def setup(hass, 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) if action is None: @@ -83,14 +81,13 @@ def _setup_automation(hass, config_block, name, config): 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: _LOGGER.error('Error setting up %s, no action specified.', name) return None def action(): - """ Action to be executed. """ + """Action to be executed.""" _LOGGER.info('Executing %s', name) logbook.log_entry(hass, name, 'has been triggered', DOMAIN) @@ -100,7 +97,7 @@ def _get_action(hass, config, name): def _migrate_old_config(config): - """ Migrate old config to new. """ + """Migrate old configuration to new.""" if CONF_PLATFORM not in config: return config @@ -134,8 +131,7 @@ def _migrate_old_config(config): def _process_if(hass, config, p_config, action): - """ Processes if checks. """ - + """Processes if checks.""" cond_type = p_config.get(CONF_CONDITION_TYPE, DEFAULT_CONDITION_TYPE).lower() @@ -165,12 +161,12 @@ def _process_if(hass, config, p_config, action): if cond_type == CONDITION_TYPE_AND: def if_action(): - """ AND all conditions. """ + """AND all conditions.""" if all(check() for check in checks): action() else: def if_action(): - """ OR all conditions. """ + """OR all conditions.""" if any(check() for check in checks): action() @@ -178,7 +174,7 @@ def _process_if(hass, config, p_config, action): def _process_trigger(hass, config, trigger_configs, name, action): - """ Setup triggers. """ + """Setup the triggers.""" if isinstance(trigger_configs, dict): trigger_configs = [trigger_configs] @@ -195,7 +191,7 @@ def _process_trigger(hass, config, trigger_configs, name, action): def _resolve_platform(method, hass, config, platform): - """ Find automation platform. """ + """Find the automation platform.""" if platform is None: return None platform = prepare_setup_platform(hass, config, DOMAIN, platform) diff --git a/homeassistant/components/automation/event.py b/homeassistant/components/automation/event.py index 7fc33df0031..2f8f64151a6 100644 --- a/homeassistant/components/automation/event.py +++ b/homeassistant/components/automation/event.py @@ -1,6 +1,4 @@ """ -homeassistant.components.automation.event -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Offers event listening automation rules. 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): - """ Listen for events based on config. """ + """Listen for events based on configuration.""" event_type = config.get(CONF_EVENT_TYPE) if event_type is None: @@ -25,7 +23,7 @@ def trigger(hass, config, action): event_data = config.get(CONF_EVENT_DATA) 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 in event_data.items()): action() diff --git a/homeassistant/components/automation/mqtt.py b/homeassistant/components/automation/mqtt.py index 8ea5f1bc6e5..e0af679ad8a 100644 --- a/homeassistant/components/automation/mqtt.py +++ b/homeassistant/components/automation/mqtt.py @@ -1,6 +1,4 @@ """ -homeassistant.components.automation.mqtt -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Offers MQTT listening automation rules. For more details about this automation rule, please refer to the documentation @@ -17,7 +15,7 @@ CONF_PAYLOAD = 'payload' def trigger(hass, config, action): - """ Listen for state changes based on `config`. """ + """Listen for state changes based on configuration.""" topic = config.get(CONF_TOPIC) payload = config.get(CONF_PAYLOAD) @@ -27,7 +25,7 @@ def trigger(hass, config, action): return False 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: action() diff --git a/homeassistant/components/automation/numeric_state.py b/homeassistant/components/automation/numeric_state.py index 10c2402bb0e..4591a5c44cc 100644 --- a/homeassistant/components/automation/numeric_state.py +++ b/homeassistant/components/automation/numeric_state.py @@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__) def _renderer(hass, value_template, state): - """Render state value.""" + """Render the state value.""" if value_template is None: return state.state @@ -29,7 +29,7 @@ def _renderer(hass, value_template, state): 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) if entity_id is None: @@ -50,8 +50,7 @@ def trigger(hass, config, action): # pylint: disable=unused-argument 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 if _in_range(above, below, renderer(to_s)) and \ (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): - """ Wraps action method with state based condition. """ - + """Wraps action method with state based condition.""" entity_id = config.get(CONF_ENTITY_ID) if entity_id is None: @@ -85,7 +83,7 @@ def if_action(hass, config): renderer = partial(_renderer, hass, value_template) def if_numeric_state(): - """ Test numeric state condition. """ + """Test numeric state condition.""" state = hass.states.get(entity_id) 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): - """ Checks if value is inside the range """ + """Checks if value is inside the range.""" try: value = float(value) except ValueError: diff --git a/homeassistant/components/automation/state.py b/homeassistant/components/automation/state.py index b9c4164e584..75002e5a42f 100644 --- a/homeassistant/components/automation/state.py +++ b/homeassistant/components/automation/state.py @@ -1,6 +1,4 @@ """ -homeassistant.components.automation.state -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Offers state listening automation rules. For more details about this automation rule, please refer to the documentation @@ -25,7 +23,7 @@ CONF_FOR = "for" 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: return None @@ -51,7 +49,7 @@ def get_time_config(config): 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) if entity_id is None: @@ -72,17 +70,18 @@ def trigger(hass, config, action): return None 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): - """ Fires on state changes after a delay and calls action. """ + """Fires on state changes after a delay and calls action.""" hass.bus.remove_listener( EVENT_STATE_CHANGED, for_state_listener) action() 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: return hass.bus.remove_listener(EVENT_TIME_CHANGED, for_time_listener) @@ -106,7 +105,7 @@ def trigger(hass, config, action): 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) state = config.get(CONF_STATE) @@ -123,7 +122,7 @@ def if_action(hass, config): state = str(state) def if_state(): - """ Test if condition. """ + """Test if condition.""" is_state = hass.states.is_state(entity_id, state) return (time_delta is None and is_state or time_delta is not None and diff --git a/homeassistant/components/automation/sun.py b/homeassistant/components/automation/sun.py index 9cd50fedbd9..1c0afb5688e 100644 --- a/homeassistant/components/automation/sun.py +++ b/homeassistant/components/automation/sun.py @@ -1,6 +1,4 @@ """ -homeassistant.components.automation.sun -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Offers sun based automation rules. 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): - """ Listen for events based on config. """ + """Listen for events based on configuration.""" event = config.get(CONF_EVENT) if event is None: @@ -55,7 +53,7 @@ def trigger(hass, config, action): def if_action(hass, config): - """ Wraps action method with sun based condition. """ + """Wraps action method with sun based condition.""" before = config.get(CONF_BEFORE) after = config.get(CONF_AFTER) @@ -106,8 +104,7 @@ def if_action(hass, config): return sun.next_setting(hass) + after_offset def time_if(): - """ Validate time based if-condition """ - + """Validate time based if-condition.""" now = dt_util.now() before = before_func() after = after_func() @@ -126,6 +123,7 @@ def if_action(hass, config): def _parse_offset(raw_offset): + """Parse the offset.""" if raw_offset is None: return timedelta(0) diff --git a/homeassistant/components/automation/template.py b/homeassistant/components/automation/template.py index 4aaac359c46..05396f40b1c 100644 --- a/homeassistant/components/automation/template.py +++ b/homeassistant/components/automation/template.py @@ -1,6 +1,4 @@ """ -homeassistant.components.automation.template -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Offers template automation rules. 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): - """ Listen for state changes based on `config`. """ + """Listen for state changes based on configuration.""" value_template = config.get(CONF_VALUE_TEMPLATE) if value_template is None: @@ -27,7 +25,7 @@ def trigger(hass, config, action): already_triggered = False def event_listener(event): - """ Listens for state changes and calls action. """ + """Listens for state changes and calls action.""" nonlocal already_triggered template_result = _check_template(hass, value_template) @@ -43,8 +41,7 @@ def trigger(hass, config, action): 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) if value_template is None: @@ -55,7 +52,7 @@ def if_action(hass, config): def _check_template(hass, value_template): - """ Checks if result of template is true """ + """Checks if result of template is true.""" try: value = template.render(hass, value_template, {}) except TemplateError: diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index d02765f75c6..efee80497ea 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -1,6 +1,4 @@ """ -homeassistant.components.automation.time -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Offers time listening automation rules. 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): - """ Listen for state changes based on `config`. """ + """Listen for state changes based on configuration.""" if CONF_AFTER in config: after = dt_util.parse_time_str(config[CONF_AFTER]) if after is None: @@ -42,7 +40,7 @@ def trigger(hass, config, action): return False def time_automation_listener(now): - """ Listens for time changes and calls action. """ + """Listens for time changes and calls action.""" action() track_time_change(hass, time_automation_listener, @@ -52,7 +50,7 @@ def trigger(hass, config, action): def if_action(hass, config): - """ Wraps action method with time based condition. """ + """Wraps action method with time based condition.""" before = config.get(CONF_BEFORE) after = config.get(CONF_AFTER) weekday = config.get(CONF_WEEKDAY) @@ -76,7 +74,7 @@ def if_action(hass, config): return None def time_if(): - """ Validate time based if-condition """ + """Validate time based if-condition.""" now = dt_util.now() if before is not None and now > now.replace(hour=before.hour, minute=before.minute): @@ -99,7 +97,7 @@ def if_action(hass, config): def _error_time(value, key): - """ Helper method to print error. """ + """Helper method to print error.""" _LOGGER.error( "Received invalid value for '%s': %s", key, value) if isinstance(value, int): diff --git a/homeassistant/components/automation/zone.py b/homeassistant/components/automation/zone.py index 7dc551de32c..ca4d61ecd2d 100644 --- a/homeassistant/components/automation/zone.py +++ b/homeassistant/components/automation/zone.py @@ -1,6 +1,4 @@ """ -homeassistant.components.automation.zone -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Offers zone automation rules. 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): - """ Listen for state changes based on `config`. """ + """Listen for state changes based on configuration.""" entity_id = config.get(CONF_ENTITY_ID) zone_entity_id = config.get(CONF_ZONE) @@ -35,7 +33,7 @@ def trigger(hass, config, action): event = config.get(CONF_EVENT, DEFAULT_EVENT) 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), from_s.attributes.get(ATTR_LONGITUDE)) or \ None in (to_s.attributes.get(ATTR_LATITUDE), @@ -57,7 +55,7 @@ def trigger(hass, config, action): 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) zone_entity_id = config.get(CONF_ZONE) @@ -68,14 +66,14 @@ def if_action(hass, config): return False def if_in_zone(): - """ Test if condition. """ + """Test if condition.""" return _in_zone(hass, zone_entity_id, hass.states.get(entity_id)) return if_in_zone 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), state.attributes.get(ATTR_LONGITUDE)): return False