mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 23:37:18 +00:00
Modify docstrings to match PEP257
This commit is contained in:
parent
5222c19b4c
commit
6ac9210919
@ -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,8 +81,7 @@ 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
|
||||||
@ -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
|
||||||
|
|
||||||
@ -135,7 +132,6 @@ 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()
|
||||||
|
|
||||||
@ -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)
|
||||||
|
@ -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:
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
@ -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:
|
||||||
@ -51,7 +51,6 @@ 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))):
|
||||||
@ -65,7 +64,6 @@ 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:
|
||||||
@ -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:
|
||||||
|
@ -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:
|
||||||
@ -81,8 +79,9 @@ def trigger(hass, config, action):
|
|||||||
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)
|
||||||
|
@ -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:
|
||||||
@ -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)
|
||||||
|
|
||||||
|
@ -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:
|
||||||
@ -44,7 +42,6 @@ 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:
|
||||||
|
@ -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:
|
||||||
@ -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):
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user