Update docstrings to match PEP257

This commit is contained in:
Fabian Affolter 2016-03-07 18:49:31 +01:00
parent 7ff9aecd4e
commit b8a40457ee
40 changed files with 371 additions and 483 deletions

View File

@ -1,8 +1,5 @@
""" """
homeassistant.components.apcupsd Support for status output of APCUPSd via its Network Information Server (NIS).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets up and provides access to the status output of APCUPSd via its Network
Information Server (NIS).
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/apcupsd/ https://home-assistant.io/components/apcupsd/

View File

@ -1,8 +1,5 @@
""" """
components.arduino Support for Arduino boards running with the Firmata firmware.
~~~~~~~~~~~~~~~~~~
Arduino component that connects to a directly attached Arduino board which
runs with the Firmata firmware.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/arduino/ https://home-assistant.io/components/arduino/
@ -21,7 +18,6 @@ _LOGGER = logging.getLogger(__name__)
def setup(hass, config): def setup(hass, config):
"""Setup the Arduino component.""" """Setup the Arduino component."""
if not validate_config(config, if not validate_config(config,
{DOMAIN: ['port']}, {DOMAIN: ['port']},
_LOGGER): _LOGGER):
@ -54,14 +50,13 @@ def setup(hass, config):
class ArduinoBoard(object): class ArduinoBoard(object):
"""Represents an Arduino board.""" """Represents an Arduino board."""
def __init__(self, port): def __init__(self, port):
from PyMata.pymata import PyMata from PyMata.pymata import PyMata
self._port = port self._port = port
self._board = PyMata(self._port, verbose=False) self._board = PyMata(self._port, verbose=False)
def set_mode(self, pin, direction, mode): def set_mode(self, pin, direction, mode):
""" Sets the mode and the direction of a given pin. """ """Set the mode and the direction of a given pin."""
if mode == 'analog' and direction == 'in': if mode == 'analog' and direction == 'in':
self._board.set_pin_mode(pin, self._board.set_pin_mode(pin,
self._board.INPUT, self._board.INPUT,
@ -89,19 +84,19 @@ class ArduinoBoard(object):
return self._board.get_analog_response_table() return self._board.get_analog_response_table()
def set_digital_out_high(self, pin): def set_digital_out_high(self, pin):
""" Sets a given digital pin to high. """ """Set a given digital pin to high."""
self._board.digital_write(pin, 1) self._board.digital_write(pin, 1)
def set_digital_out_low(self, pin): def set_digital_out_low(self, pin):
""" Sets a given digital pin to low. """ """Set a given digital pin to low."""
self._board.digital_write(pin, 0) self._board.digital_write(pin, 0)
def get_digital_in(self, pin): def get_digital_in(self, pin):
""" Gets the value from a given digital pin. """ """Get the value from a given digital pin."""
self._board.digital_read(pin) self._board.digital_read(pin)
def get_analog_in(self, pin): def get_analog_in(self, pin):
""" Gets the value from a given analog pin. """ """Get the value from a given analog pin."""
self._board.analog_read(pin) self._board.analog_read(pin)
def get_firmata(self): def get_firmata(self):

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.bloomsky
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for BloomSky weather station. Support for BloomSky weather station.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at

View File

@ -1,8 +1,5 @@
""" """
homeassistant.components.configurator Support to allow pieces of code to request configuration from the user.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A component to allow pieces of code to request configuration from the user.
Initiate a request by calling the `request_config` method with a callback. Initiate a request by calling the `request_config` method with a callback.
This will return a request id that has to be used for future calls. This will return a request id that has to be used for future calls.
@ -38,9 +35,9 @@ _LOGGER = logging.getLogger(__name__)
def request_config( def request_config(
hass, name, callback, description=None, description_image=None, hass, name, callback, description=None, description_image=None,
submit_caption=None, fields=None): submit_caption=None, fields=None):
""" Create a new request for config. """Create a new request for configuration.
Will return an ID to be used for sequent calls. """ Will return an ID to be used for sequent calls.
"""
instance = _get_instance(hass) instance = _get_instance(hass)
request_id = instance.request_config( request_id = instance.request_config(
@ -62,7 +59,7 @@ def notify_errors(request_id, error):
def request_done(request_id): def request_done(request_id):
""" Mark a config request as done. """ """Mark a configuration request as done."""
try: try:
_REQUESTS.pop(request_id).request_done(request_id) _REQUESTS.pop(request_id).request_done(request_id)
except KeyError: except KeyError:
@ -71,7 +68,7 @@ def request_done(request_id):
def setup(hass, config): def setup(hass, config):
""" Set up Configurator. """ """Setup the configurator component."""
return True return True
@ -89,10 +86,7 @@ def _get_instance(hass):
class Configurator(object): class Configurator(object):
""" """Class to keep track of current configuration requests."""
Class to keep track of current configuration requests.
"""
def __init__(self, hass): def __init__(self, hass):
self.hass = hass self.hass = hass
self._cur_id = 0 self._cur_id = 0
@ -105,7 +99,6 @@ class Configurator(object):
self, name, callback, self, name, callback,
description, description_image, submit_caption, fields): description, description_image, submit_caption, fields):
"""Setup a request for configuration.""" """Setup a request for configuration."""
entity_id = generate_entity_id(ENTITY_ID_FORMAT, name, hass=self.hass) entity_id = generate_entity_id(ENTITY_ID_FORMAT, name, hass=self.hass)
if fields is None: if fields is None:
@ -147,7 +140,7 @@ class Configurator(object):
self.hass.states.set(entity_id, STATE_CONFIGURE, new_data) self.hass.states.set(entity_id, STATE_CONFIGURE, new_data)
def request_done(self, request_id): def request_done(self, request_id):
""" Remove the config request. """ """Remove the configuration request."""
if not self._validate_request_id(request_id): if not self._validate_request_id(request_id):
return return
@ -180,7 +173,7 @@ class Configurator(object):
callback(call.data.get(ATTR_FIELDS, {})) callback(call.data.get(ATTR_FIELDS, {}))
def _generate_unique_id(self): def _generate_unique_id(self):
""" Generates a unique configurator id. """ """Generates a unique configurator ID."""
self._cur_id += 1 self._cur_id += 1
return "{}-{}".format(id(self), self._cur_id) return "{}-{}".format(id(self), self._cur_id)

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.conversation Support for functionality to have conversations with Home Assistant.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to have conversations with Home Assistant.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/conversation/ https://home-assistant.io/components/conversation/
@ -31,7 +29,7 @@ def setup(hass, config):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def process(service): def process(service):
""" Parses text into commands for Home Assistant. """ """Parses text into commands."""
if ATTR_TEXT not in service.data: if ATTR_TEXT not in service.data:
logger.error("Received process service call without a text") logger.error("Received process service call without a text")
return return

View File

@ -29,7 +29,7 @@ CONF_DEVICE_GROUP = 'device_group'
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
def setup(hass, config): def setup(hass, config):
""" Triggers to turn lights on or off based on device precense. """ """Triggers to turn lights on or off based on device presence."""
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
device_tracker = get_component('device_tracker') device_tracker = get_component('device_tracker')
group = get_component('group') group = get_component('group')
@ -78,26 +78,29 @@ def setup(hass, config):
@track_state_change(sun.ENTITY_ID, sun.STATE_BELOW_HORIZON, @track_state_change(sun.ENTITY_ID, sun.STATE_BELOW_HORIZON,
sun.STATE_ABOVE_HORIZON) sun.STATE_ABOVE_HORIZON)
def schedule_lights_at_sun_set(hass, entity, old_state, new_state): def schedule_lights_at_sun_set(hass, entity, old_state, new_state):
"""The moment sun sets we want to have all the lights on. """
The moment sun sets we want to have all the lights on.
We will schedule to have each light start after one another We will schedule to have each light start after one another
and slowly transition in.""" and slowly transition in.
"""
start_point = calc_time_for_light_when_sunset() start_point = calc_time_for_light_when_sunset()
if not start_point: if not start_point:
return return
def turn_on(light_id): def turn_on(light_id):
""" Lambda can keep track of function parameters but not local """
Lambda can keep track of function parameters but not local
parameters. If we put the lambda directly in the below statement parameters. If we put the lambda directly in the below statement
only the last light will be turned on.. """ only the last light will be turned on.
"""
return lambda now: turn_light_on_before_sunset(light_id) return lambda now: turn_light_on_before_sunset(light_id)
for index, light_id in enumerate(light_ids): for index, light_id in enumerate(light_ids):
track_point_in_time(hass, turn_on(light_id), track_point_in_time(hass, turn_on(light_id),
start_point + index * LIGHT_TRANSITION_TIME) start_point + index * LIGHT_TRANSITION_TIME)
# If the sun is already above horizon # If the sun is already above horizon schedule the time-based pre-sun set
# schedule the time-based pre-sun set event # event.
if sun.is_on(hass): if sun.is_on(hass):
schedule_lights_at_sun_set(hass, None, None, None) schedule_lights_at_sun_set(hass, None, None, None)

View File

@ -37,8 +37,8 @@ SERVICE_HANDLERS = {
def listen(hass, service, callback): def listen(hass, service, callback):
"""Setup listener for discovery of specific service. """
Setup listener for discovery of specific service.
Service can be a string or a list/tuple. Service can be a string or a list/tuple.
""" """
if isinstance(service, str): if isinstance(service, str):
@ -55,10 +55,7 @@ def listen(hass, service, callback):
def discover(hass, service, discovered=None, component=None, hass_config=None): def discover(hass, service, discovered=None, component=None, hass_config=None):
"""Fire discovery event. """Fire discovery event. Can ensure a component is loaded."""
Can ensure a component is loaded.
"""
if component is not None: if component is not None:
bootstrap.setup_component(hass, component, hass_config) bootstrap.setup_component(hass, component, hass_config)
@ -90,7 +87,7 @@ def setup(hass, config):
component = SERVICE_HANDLERS.get(service) component = SERVICE_HANDLERS.get(service)
# We do not know how to handle this service # We do not know how to handle this service.
if not component: if not component:
return return

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.downloader Support for functionality to download files.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to download files.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/downloader/ https://home-assistant.io/components/downloader/
@ -29,7 +27,6 @@ CONF_DOWNLOAD_DIR = 'download_dir'
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
def setup(hass, config): def setup(hass, config):
"""Listens for download events to download files.""" """Listens for download events to download files."""
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
if not validate_config(config, {DOMAIN: [CONF_DOWNLOAD_DIR]}, logger): if not validate_config(config, {DOMAIN: [CONF_DOWNLOAD_DIR]}, logger):
@ -50,8 +47,7 @@ def setup(hass, config):
return False return False
def download_file(service): def download_file(service):
""" Starts thread to download file specified in the url. """ """Starts thread to download file specified in the URL."""
if ATTR_URL not in service.data: if ATTR_URL not in service.data:
logger.error("Service called but 'url' parameter not specified.") logger.error("Service called but 'url' parameter not specified.")
return return

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.ecobee Support for Ecobee.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ecobee component
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/ecobee/ https://home-assistant.io/components/ecobee/
@ -31,7 +29,7 @@ _LOGGER = logging.getLogger(__name__)
ECOBEE_CONFIG_FILE = 'ecobee.conf' ECOBEE_CONFIG_FILE = 'ecobee.conf'
_CONFIGURING = {} _CONFIGURING = {}
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago.
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=180) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=180)
@ -94,7 +92,6 @@ def setup_ecobee(hass, network, config):
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
class EcobeeData(object): class EcobeeData(object):
"""Gets the latest data and update the states.""" """Gets the latest data and update the states."""
def __init__(self, config_file): def __init__(self, config_file):
from pyecobee import Ecobee from pyecobee import Ecobee
self.ecobee = Ecobee(config_file) self.ecobee = Ecobee(config_file)

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.history
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provide pre-made queries on top of the recorder component. Provide pre-made queries on top of the recorder component.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
@ -39,12 +37,12 @@ def last_5_states(entity_id):
def get_significant_states(start_time, end_time=None, entity_id=None): def get_significant_states(start_time, end_time=None, entity_id=None):
"""Return states changes during UTC period start_time - end_time. """
Return states changes during UTC period start_time - end_time.
Significant states are all states where there is a state change, Significant states are all states where there is a state change,
as well as all states from certain domains (for instance as well as all states from certain domains (for instance
thermostat so that we get current temperature in our graphs). thermostat so that we get current temperature in our graphs).
""" """
where = """ where = """
(domain IN ({}) OR last_changed=last_updated) (domain IN ({}) OR last_changed=last_updated)
@ -124,7 +122,8 @@ def get_states(utc_point_in_time, entity_ids=None, run=None):
def states_to_json(states, start_time, entity_id): def states_to_json(states, start_time, entity_id):
"""Converts SQL results into JSON friendly data structure. """
Converts SQL results into JSON friendly data structure.
This takes our state list and turns it into a JSON friendly data This takes our state list and turns it into a JSON friendly data
structure {'entity_id': [list of states], 'entity_id2': [list of states]} structure {'entity_id': [list of states], 'entity_id2': [list of states]}
@ -133,7 +132,6 @@ def states_to_json(states, start_time, entity_id):
each list of states, otherwise our graphs won't start on the Y each list of states, otherwise our graphs won't start on the Y
axis correctly. axis correctly.
""" """
result = defaultdict(list) result = defaultdict(list)
entity_ids = [entity_id] if entity_id is not None else None entity_ids = [entity_id] if entity_id is not None else None
@ -206,7 +204,8 @@ def _api_history_period(handler, path_match, data):
def _is_significant(state): def _is_significant(state):
"""Test if state is significant for history charts. """
Test if state is significant for history charts.
Will only test for things that are not filtered out in SQL. Will only test for things that are not filtered out in SQL.
""" """

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.http
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This module provides an API and a HTTP interface for debug purposes. This module provides an API and a HTTP interface for debug purposes.
For more details about the RESTful API, please refer to the documentation at For more details about the RESTful API, please refer to the documentation at
@ -89,7 +87,6 @@ def setup(hass, config):
class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer): class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer):
"""Handle HTTP requests in a threaded fashion.""" """Handle HTTP requests in a threaded fashion."""
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
allow_reuse_address = True allow_reuse_address = True
daemon_threads = True daemon_threads = True
@ -144,7 +141,7 @@ class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer):
self.paths.append((method, url, callback, require_auth)) self.paths.append((method, url, callback, require_auth))
def log_message(self, fmt, *args): def log_message(self, fmt, *args):
""" Redirect built-in log to HA logging """ """Redirect built-in log to HA logging."""
# pylint: disable=no-self-use # pylint: disable=no-self-use
_LOGGER.info(fmt, *args) _LOGGER.info(fmt, *args)
@ -157,17 +154,16 @@ class RequestHandler(SimpleHTTPRequestHandler):
We extend from SimpleHTTPRequestHandler instead of Base so we We extend from SimpleHTTPRequestHandler instead of Base so we
can use the guess content type methods. can use the guess content type methods.
""" """
server_version = "HomeAssistant/1.0" server_version = "HomeAssistant/1.0"
def __init__(self, req, client_addr, server): def __init__(self, req, client_addr, server):
""" Contructor, call the base constructor and set up session """ """Contructor, call the base constructor and set up session."""
# Track if this was an authenticated request # Track if this was an authenticated request
self.authenticated = False self.authenticated = False
SimpleHTTPRequestHandler.__init__(self, req, client_addr, server) SimpleHTTPRequestHandler.__init__(self, req, client_addr, server)
def log_message(self, fmt, *arguments): def log_message(self, fmt, *arguments):
""" Redirect built-in log to HA logging """ """Redirect built-in log to HA logging."""
if self.server.api_password is None: if self.server.api_password is None:
_LOGGER.info(fmt, *arguments) _LOGGER.info(fmt, *arguments)
else: else:
@ -354,7 +350,7 @@ class RequestHandler(SimpleHTTPRequestHandler):
self.copyfile(inp, self.wfile) self.copyfile(inp, self.wfile)
def set_cache_header(self): def set_cache_header(self):
""" Add cache headers if not in development """ """Add cache headers if not in development."""
if self.server.development: if self.server.development:
return return
@ -369,7 +365,7 @@ class RequestHandler(SimpleHTTPRequestHandler):
self.date_time_string(time.time()+cache_time)) self.date_time_string(time.time()+cache_time))
def set_session_cookie_header(self): def set_session_cookie_header(self):
""" Add the header for the session cookie and return session id. """ """Add the header for the session cookie and return session ID."""
if not self.authenticated: if not self.authenticated:
return None return None
@ -392,8 +388,8 @@ class RequestHandler(SimpleHTTPRequestHandler):
def get_cookie_session_id(self): def get_cookie_session_id(self):
""" """
Extracts the current session id from the Extracts the current session id from the cookie or returns None if not
cookie or returns None if not set or invalid set or invalid.
""" """
if 'Cookie' not in self.headers: if 'Cookie' not in self.headers:
return None return None
@ -433,9 +429,9 @@ def session_valid_time():
class SessionStore(object): class SessionStore(object):
""" Responsible for storing and retrieving http sessions """ """Responsible for storing and retrieving HTTP sessions."""
def __init__(self): def __init__(self):
""" Set up the session store """ """Setup the session store."""
self._sessions = {} self._sessions = {}
self._lock = threading.RLock() self._lock = threading.RLock()

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.ifttt Support to trigger Maker IFTTT recipes.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This component enable you to trigger Maker IFTTT recipes.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/ifttt/ https://home-assistant.io/components/ifttt/
@ -38,15 +36,14 @@ def trigger(hass, event, value1=None, value2=None, value3=None):
def setup(hass, config): def setup(hass, config):
""" Setup the ifttt service component. """ """Setup the IFTTT service component."""
if not validate_config(config, {DOMAIN: ['key']}, _LOGGER): if not validate_config(config, {DOMAIN: ['key']}, _LOGGER):
return False return False
key = config[DOMAIN]['key'] key = config[DOMAIN]['key']
def trigger_service(call): def trigger_service(call):
""" Handle ifttt trigger service calls. """ """Handle IFTTT trigger service calls."""
event = call.data.get(ATTR_EVENT) event = call.data.get(ATTR_EVENT)
value1 = call.data.get(ATTR_VALUE1) value1 = call.data.get(ATTR_VALUE1)
value2 = call.data.get(ATTR_VALUE2) value2 = call.data.get(ATTR_VALUE2)

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.input_boolean
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to keep track of user controlled booleans for within automation. Component to keep track of user controlled booleans for within automation.
For more details about this component, please refer to the documentation For more details about this component, please refer to the documentation
@ -87,7 +85,6 @@ def setup(hass, config):
class InputBoolean(ToggleEntity): class InputBoolean(ToggleEntity):
"""Represent a boolean input.""" """Represent a boolean input."""
def __init__(self, object_id, name, state, icon): def __init__(self, object_id, name, state, icon):
""" Initialize a boolean input. """ """ Initialize a boolean input. """
self.entity_id = ENTITY_ID_FORMAT.format(object_id) self.entity_id = ENTITY_ID_FORMAT.format(object_id)
@ -97,22 +94,22 @@ class InputBoolean(ToggleEntity):
@property @property
def should_poll(self): def should_poll(self):
"""If entitiy should be polled.""" """If entity should be polled."""
return False return False
@property @property
def name(self): def name(self):
"""Name of the boolean input.""" """Return name of the boolean input."""
return self._name return self._name
@property @property
def icon(self): def icon(self):
"""Icon to be used for this entity.""" """Returh the icon to be used for this entity."""
return self._icon return self._icon
@property @property
def is_on(self): def is_on(self):
"""True if entity is on.""" """Return true if entity is on."""
return self._state return self._state
def turn_on(self, **kwargs): def turn_on(self, **kwargs):

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.input_select
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to offer a way to select an option from a list. Component to offer a way to select an option from a list.
For more details about this component, please refer to the documentation For more details about this component, please refer to the documentation
@ -93,7 +91,6 @@ def setup(hass, config):
class InputSelect(Entity): class InputSelect(Entity):
"""Represent a select input.""" """Represent a select input."""
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, object_id, name, state, options, icon): def __init__(self, object_id, name, state, options, icon):
""" Initialize a select input. """ """ Initialize a select input. """
@ -110,22 +107,22 @@ class InputSelect(Entity):
@property @property
def name(self): def name(self):
""" Name of the select input. """ """Return the name of the select input."""
return self._name return self._name
@property @property
def icon(self): def icon(self):
""" Icon to be used for this entity. """ """Return the icon to be used for this entity."""
return self._icon return self._icon
@property @property
def state(self): def state(self):
""" State of the component. """ """Return the state of the component."""
return self._current_option return self._current_option
@property @property
def state_attributes(self): def state_attributes(self):
""" State attributes. """ """Return the state attributes."""
return { return {
ATTR_OPTIONS: self._options, ATTR_OPTIONS: self._options,
} }

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.insteon_hub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Insteon Hub. Support for Insteon Hub.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
@ -58,20 +56,19 @@ def setup(hass, config):
class InsteonToggleDevice(ToggleEntity): class InsteonToggleDevice(ToggleEntity):
""" Abstract Class for an Insteon node. """ """ An abstract Class for an Insteon node."""
def __init__(self, node): def __init__(self, node):
self.node = node self.node = node
self._value = 0 self._value = 0
@property @property
def name(self): def name(self):
""" Returns the name of the node. """ """Return the the name of the node."""
return self.node.DeviceName return self.node.DeviceName
@property @property
def unique_id(self): def unique_id(self):
""" Returns the id of this insteon node. """ """Return the ID of this insteon node."""
return self.node.DeviceID return self.node.DeviceID
def update(self): def update(self):
@ -84,7 +81,7 @@ class InsteonToggleDevice(ToggleEntity):
@property @property
def is_on(self): def is_on(self):
""" Returns boolean response if the node is on. """ """Return the boolean response if the node is on."""
return self._value != 0 return self._value != 0
def turn_on(self, **kwargs): def turn_on(self, **kwargs):

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.introduction
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component that will help guide the user taking its first steps. Component that will help guide the user taking its first steps.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at

View File

@ -1,8 +1,5 @@
""" """
homeassistant.components.isy994 Support the ISY-994 controllers.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connects to an ISY-994 controller and loads relevant components to control its
devices. Also contains the base classes for ISY Sensors, Lights, and Switches.
For configuration details please visit the documentation for this component at For configuration details please visit the documentation for this component at
https://home-assistant.io/components/isy994/ https://home-assistant.io/components/isy994/
@ -45,7 +42,7 @@ def setup(hass, config):
_LOGGER): _LOGGER):
return False return False
# pull and parse standard configuration # Pull and parse standard configuration.
user = config[DOMAIN][CONF_USERNAME] user = config[DOMAIN][CONF_USERNAME]
password = config[DOMAIN][CONF_PASSWORD] password = config[DOMAIN][CONF_PASSWORD]
host = urlparse(config[DOMAIN][CONF_HOST]) host = urlparse(config[DOMAIN][CONF_HOST])
@ -62,24 +59,24 @@ def setup(hass, config):
port = host.port port = host.port
addr = addr.replace(':{}'.format(port), '') addr = addr.replace(':{}'.format(port), '')
# pull and parse optional configuration # Pull and parse optional configuration.
global SENSOR_STRING global SENSOR_STRING
global HIDDEN_STRING global HIDDEN_STRING
SENSOR_STRING = str(config[DOMAIN].get('sensor_string', SENSOR_STRING)) SENSOR_STRING = str(config[DOMAIN].get('sensor_string', SENSOR_STRING))
HIDDEN_STRING = str(config[DOMAIN].get('hidden_string', HIDDEN_STRING)) HIDDEN_STRING = str(config[DOMAIN].get('hidden_string', HIDDEN_STRING))
tls_version = config[DOMAIN].get(CONF_TLS_VER, None) tls_version = config[DOMAIN].get(CONF_TLS_VER, None)
# connect to ISY controller # Connect to ISY controller.
global ISY global ISY
ISY = PyISY.ISY(addr, port, user, password, use_https=https, ISY = PyISY.ISY(addr, port, user, password, use_https=https,
tls_ver=tls_version, log=_LOGGER) tls_ver=tls_version, log=_LOGGER)
if not ISY.connected: if not ISY.connected:
return False return False
# listen for HA stop to disconnect # Listen for HA stop to disconnect.
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop) hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop)
# Load components for the devices in the ISY controller that we support # Load components for the devices in the ISY controller that we support.
for comp_name, discovery in ((('sensor', DISCOVER_SENSORS), for comp_name, discovery in ((('sensor', DISCOVER_SENSORS),
('light', DISCOVER_LIGHTS), ('light', DISCOVER_LIGHTS),
('switch', DISCOVER_SWITCHES))): ('switch', DISCOVER_SWITCHES))):
@ -99,8 +96,7 @@ def stop(event):
class ISYDeviceABC(ToggleEntity): class ISYDeviceABC(ToggleEntity):
""" Abstract Class for an ISY device. """ """An abstract Class for an ISY device."""
_attrs = {} _attrs = {}
_onattrs = [] _onattrs = []
_states = [] _states = []
@ -117,35 +113,35 @@ class ISYDeviceABC(ToggleEntity):
subscribe('changed', self.on_update) subscribe('changed', self.on_update)
def __del__(self): def __del__(self):
""" cleanup subscriptions because it is the right thing to do. """ """Cleanup subscriptions because it is the right thing to do."""
self._change_handler.unsubscribe() self._change_handler.unsubscribe()
@property @property
def domain(self): def domain(self):
""" Returns the domain of the entity. """ """Return the domain of the entity."""
return self._domain return self._domain
@property @property
def dtype(self): def dtype(self):
""" Returns the data type of the entity (binary or analog). """ """Return the data type of the entity (binary or analog)."""
if self._dtype in ['analog', 'binary']: if self._dtype in ['analog', 'binary']:
return self._dtype return self._dtype
return 'binary' if self.unit_of_measurement is None else 'analog' return 'binary' if self.unit_of_measurement is None else 'analog'
@property @property
def should_poll(self): def should_poll(self):
""" Tells Home Assistant not to poll this entity. """ """No polling needed."""
return False return False
@property @property
def value(self): def value(self):
""" Returns the unclean value from the controller. """ """Return the unclean value from the controller."""
# pylint: disable=protected-access # pylint: disable=protected-access
return self.node.status._val return self.node.status._val
@property @property
def state_attributes(self): def state_attributes(self):
""" Returns the state attributes for the node. """ """Return the state attributes for the node."""
attr = {} attr = {}
for name, prop in self._attrs.items(): for name, prop in self._attrs.items():
attr[name] = getattr(self, prop) attr[name] = getattr(self, prop)
@ -153,25 +149,25 @@ class ISYDeviceABC(ToggleEntity):
return attr return attr
def _attr_filter(self, attr): def _attr_filter(self, attr):
""" Placeholder for attribute filters. """ """A Placeholder for attribute filters."""
# pylint: disable=no-self-use # pylint: disable=no-self-use
return attr return attr
@property @property
def unique_id(self): def unique_id(self):
""" Returns the id of this ISY sensor. """ """Return the ID of this ISY sensor."""
# pylint: disable=protected-access # pylint: disable=protected-access
return self.node._id return self.node._id
@property @property
def raw_name(self): def raw_name(self):
""" Returns the unclean node name. """ """Return the unclean node name."""
return str(self._name) \ return str(self._name) \
if self._name is not None else str(self.node.name) if self._name is not None else str(self.node.name)
@property @property
def name(self): def name(self):
""" Returns the cleaned name of the node. """ """Return the cleaned name of the node."""
return self.raw_name.replace(HIDDEN_STRING, '').strip() \ return self.raw_name.replace(HIDDEN_STRING, '').strip() \
.replace('_', ' ') .replace('_', ' ')
@ -191,17 +187,17 @@ class ISYDeviceABC(ToggleEntity):
@property @property
def is_on(self): def is_on(self):
""" Returns boolean response if the node is on. """ """Return a boolean response if the node is on."""
return bool(self.value) return bool(self.value)
@property @property
def is_open(self): def is_open(self):
""" Returns boolean respons if the node is open. On = Open. """ """Return boolean response if the node is open. On = Open."""
return self.is_on return self.is_on
@property @property
def state(self): def state(self):
""" Returns the state of the node. """ """Return the state of the node."""
if len(self._states) > 0: if len(self._states) > 0:
return self._states[0] if self.is_on else self._states[1] return self._states[0] if self.is_on else self._states[1]
return self.value return self.value
@ -223,7 +219,7 @@ class ISYDeviceABC(ToggleEntity):
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
""" Returns the defined units of measurement or None. """ """Return the defined units of measurement or None."""
try: try:
return self.node.units return self.node.units
except AttributeError: except AttributeError:

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.keyboard
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to emulate keyboard presses on host machine. Provides functionality to emulate keyboard presses on host machine.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at

View File

@ -56,7 +56,6 @@ def log_entry(hass, name, message, domain=None, entity_id=None):
def setup(hass, config): def setup(hass, config):
"""Listens for download events to download files.""" """Listens for download events to download files."""
def log_message(service): def log_message(service):
"""Handle sending notification message service calls.""" """Handle sending notification message service calls."""
message = service.data.get(ATTR_MESSAGE) message = service.data.get(ATTR_MESSAGE)
@ -101,7 +100,6 @@ def _handle_get_logbook(handler, path_match, data):
class Entry(object): class Entry(object):
"""A human readable version of the log.""" """A human readable version of the log."""
# pylint: disable=too-many-arguments, too-few-public-methods # pylint: disable=too-many-arguments, too-few-public-methods
def __init__(self, when=None, name=None, message=None, domain=None, def __init__(self, when=None, name=None, message=None, domain=None,
entity_id=None): entity_id=None):
@ -237,7 +235,6 @@ def _entry_message_from_state(domain, state):
"""Convert a state to a message for the logbook.""" """Convert a state to a message for the logbook."""
# We pass domain in so we don't have to split entity_id again # We pass domain in so we don't have to split entity_id again
# pylint: disable=too-many-return-statements # pylint: disable=too-many-return-statements
if domain == 'device_tracker': if domain == 'device_tracker':
if state.state == STATE_NOT_HOME: if state.state == STATE_NOT_HOME:
return 'is away' return 'is away'

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.logger
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component that will help set the level of logging for components. Component that will help set the level of logging for components.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
@ -29,14 +27,13 @@ LOGGER_LOGS = 'logs'
class HomeAssistantLogFilter(logging.Filter): class HomeAssistantLogFilter(logging.Filter):
"""A log filter.""" """A log filter."""
# pylint: disable=no-init,too-few-public-methods # pylint: disable=no-init,too-few-public-methods
def __init__(self, logfilter): def __init__(self, logfilter):
super().__init__() super().__init__()
self.logfilter = logfilter self.logfilter = logfilter
def filter(self, record): def filter(self, record):
"""A filter to use."""
# Log with filtered severity # Log with filtered severity
if LOGGER_LOGS in self.logfilter: if LOGGER_LOGS in self.logfilter:
for filtername in self.logfilter[LOGGER_LOGS]: for filtername in self.logfilter[LOGGER_LOGS]:
@ -51,7 +48,6 @@ class HomeAssistantLogFilter(logging.Filter):
def setup(hass, config=None): def setup(hass, config=None):
"""Setup the logger component.""" """Setup the logger component."""
logfilter = dict() logfilter = dict()
# Set default log severity # Set default log severity

View File

@ -157,7 +157,6 @@ def pf_callback_factory(map_sv_types, devices, add_devices, entity_class):
class GatewayWrapper(object): class GatewayWrapper(object):
"""Gateway wrapper class.""" """Gateway wrapper class."""
def __init__(self, gateway, version, optimistic): def __init__(self, gateway, version, optimistic):
"""Setup class attributes on instantiation. """Setup class attributes on instantiation.

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.thermostat.nest Support for Nest thermostats.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adds support for Nest thermostats.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/thermostat.nest/ https://home-assistant.io/components/thermostat.nest/
@ -18,7 +16,7 @@ NEST = None
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup(hass, config): def setup(hass, config):
""" Sets up the nest thermostat. """ """Setup the Nest thermostat component."""
global NEST global NEST
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.proximity
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to monitor the proximity of devices to a particular zone and the Component to monitor the proximity of devices to a particular zone and the
direction of travel. direction of travel.
@ -38,7 +36,7 @@ def setup(hass, config): # pylint: disable=too-many-locals,too-many-statements
for variable in config[DOMAIN]['ignored_zones']: for variable in config[DOMAIN]['ignored_zones']:
ignored_zones.append(variable) ignored_zones.append(variable)
# Get the devices from configuration.yaml # Get the devices from configuration.yaml.
if 'devices' not in config[DOMAIN]: if 'devices' not in config[DOMAIN]:
_LOGGER.error('devices not found in config') _LOGGER.error('devices not found in config')
return False return False
@ -47,10 +45,10 @@ def setup(hass, config): # pylint: disable=too-many-locals,too-many-statements
for variable in config[DOMAIN]['devices']: for variable in config[DOMAIN]['devices']:
proximity_devices.append(variable) proximity_devices.append(variable)
# Get the direction of travel tolerance from configuration.yaml # Get the direction of travel tolerance from configuration.yaml.
tolerance = config[DOMAIN].get('tolerance', DEFAULT_TOLERANCE) tolerance = config[DOMAIN].get('tolerance', DEFAULT_TOLERANCE)
# Get the zone to monitor proximity to from configuration.yaml # Get the zone to monitor proximity to from configuration.yaml.
proximity_zone = config[DOMAIN].get('zone', DEFAULT_PROXIMITY_ZONE) proximity_zone = config[DOMAIN].get('zone', DEFAULT_PROXIMITY_ZONE)
entity_id = DOMAIN + '.' + proximity_zone entity_id = DOMAIN + '.' + proximity_zone
@ -59,7 +57,7 @@ def setup(hass, config): # pylint: disable=too-many-locals,too-many-statements
state = hass.states.get(proximity_zone) state = hass.states.get(proximity_zone)
zone_friendly_name = (state.name).lower() zone_friendly_name = (state.name).lower()
# set the default values # Set the default values.
dist_to_zone = 'not set' dist_to_zone = 'not set'
dir_of_travel = 'not set' dir_of_travel = 'not set'
nearest = 'not set' nearest = 'not set'
@ -71,7 +69,7 @@ def setup(hass, config): # pylint: disable=too-many-locals,too-many-statements
proximity.update_ha_state() proximity.update_ha_state()
# Main command to monitor proximity of devices # Main command to monitor proximity of devices.
track_state_change(hass, proximity_devices, track_state_change(hass, proximity_devices,
proximity.check_proximity_state_change) proximity.check_proximity_state_change)
@ -101,17 +99,17 @@ class Proximity(Entity): # pylint: disable=too-many-instance-attributes
@property @property
def state(self): def state(self):
""" Returns the state. """ """Return the state."""
return self.dist_to return self.dist_to
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
""" Unit of measurement of this entity. """ """Return the unit of measurement of this entity."""
return "km" return "km"
@property @property
def state_attributes(self): def state_attributes(self):
""" Returns the state attributes. """ """Return the state attributes."""
return { return {
ATTR_DIR_OF_TRAVEL: self.dir_of_travel, ATTR_DIR_OF_TRAVEL: self.dir_of_travel,
ATTR_NEAREST: self.nearest, ATTR_NEAREST: self.nearest,
@ -128,21 +126,21 @@ class Proximity(Entity): # pylint: disable=too-many-instance-attributes
proximity_latitude = zone_state.attributes.get('latitude') proximity_latitude = zone_state.attributes.get('latitude')
proximity_longitude = zone_state.attributes.get('longitude') proximity_longitude = zone_state.attributes.get('longitude')
# Check for devices in the monitored zone # Check for devices in the monitored zone.
for device in self.proximity_devices: for device in self.proximity_devices:
device_state = self.hass.states.get(device) device_state = self.hass.states.get(device)
if device_state.state not in self.ignored_zones: if device_state.state not in self.ignored_zones:
devices_to_calculate = True devices_to_calculate = True
# Check the location of all devices # Check the location of all devices.
if (device_state.state).lower() == (self.friendly_name).lower(): if (device_state.state).lower() == (self.friendly_name).lower():
device_friendly = device_state.name device_friendly = device_state.name
if devices_in_zone != '': if devices_in_zone != '':
devices_in_zone = devices_in_zone + ', ' devices_in_zone = devices_in_zone + ', '
devices_in_zone = devices_in_zone + device_friendly devices_in_zone = devices_in_zone + device_friendly
# No-one to track so reset the entity # No-one to track so reset the entity.
if not devices_to_calculate: if not devices_to_calculate:
self.dist_to = 'not set' self.dist_to = 'not set'
self.dir_of_travel = 'not set' self.dir_of_travel = 'not set'
@ -150,7 +148,7 @@ class Proximity(Entity): # pylint: disable=too-many-instance-attributes
self.update_ha_state() self.update_ha_state()
return return
# At least one device is in the monitored zone so update the entity # At least one device is in the monitored zone so update the entity.
if devices_in_zone != '': if devices_in_zone != '':
self.dist_to = 0 self.dist_to = 0
self.dir_of_travel = 'arrived' self.dir_of_travel = 'arrived'
@ -158,32 +156,33 @@ class Proximity(Entity): # pylint: disable=too-many-instance-attributes
self.update_ha_state() self.update_ha_state()
return return
# We can't check proximity because latitude and longitude don't exist # We can't check proximity because latitude and longitude don't exist.
if 'latitude' not in new_state.attributes: if 'latitude' not in new_state.attributes:
return return
# Collect distances to the zone for all devices # Collect distances to the zone for all devices.
distances_to_zone = {} distances_to_zone = {}
for device in self.proximity_devices: for device in self.proximity_devices:
# Ignore devices in an ignored zone # Ignore devices in an ignored zone.
device_state = self.hass.states.get(device) device_state = self.hass.states.get(device)
if device_state.state in self.ignored_zones: if device_state.state in self.ignored_zones:
continue continue
# Ignore devices if proximity cannot be calculated # Ignore devices if proximity cannot be calculated.
if 'latitude' not in device_state.attributes: if 'latitude' not in device_state.attributes:
continue continue
# Calculate the distance to the proximity zone # Calculate the distance to the proximity zone.
dist_to_zone = distance(proximity_latitude, dist_to_zone = distance(proximity_latitude,
proximity_longitude, proximity_longitude,
device_state.attributes['latitude'], device_state.attributes['latitude'],
device_state.attributes['longitude']) device_state.attributes['longitude'])
# Add the device and distance to a dictionary # Add the device and distance to a dictionary.
distances_to_zone[device] = round(dist_to_zone / 1000, 1) distances_to_zone[device] = round(dist_to_zone / 1000, 1)
# Loop through each of the distances collected and work out the closest # Loop through each of the distances collected and work out the
# closest.
closest_device = '' closest_device = ''
dist_to_zone = 1000000 dist_to_zone = 1000000
@ -192,7 +191,7 @@ class Proximity(Entity): # pylint: disable=too-many-instance-attributes
closest_device = device closest_device = device
dist_to_zone = distances_to_zone[device] dist_to_zone = distances_to_zone[device]
# If the closest device is one of the other devices # If the closest device is one of the other devices.
if closest_device != entity: if closest_device != entity:
self.dist_to = round(distances_to_zone[closest_device]) self.dist_to = round(distances_to_zone[closest_device])
self.dir_of_travel = 'unknown' self.dir_of_travel = 'unknown'
@ -202,7 +201,7 @@ class Proximity(Entity): # pylint: disable=too-many-instance-attributes
return return
# Stop if we cannot calculate the direction of travel (i.e. we don't # Stop if we cannot calculate the direction of travel (i.e. we don't
# have a previous state and a current LAT and LONG) # have a previous state and a current LAT and LONG).
if old_state is None or 'latitude' not in old_state.attributes: if old_state is None or 'latitude' not in old_state.attributes:
self.dist_to = round(distances_to_zone[entity]) self.dist_to = round(distances_to_zone[entity])
self.dir_of_travel = 'unknown' self.dir_of_travel = 'unknown'
@ -213,7 +212,7 @@ class Proximity(Entity): # pylint: disable=too-many-instance-attributes
# Reset the variables # Reset the variables
distance_travelled = 0 distance_travelled = 0
# Calculate the distance travelled # Calculate the distance travelled.
old_distance = distance(proximity_latitude, proximity_longitude, old_distance = distance(proximity_latitude, proximity_longitude,
old_state.attributes['latitude'], old_state.attributes['latitude'],
old_state.attributes['longitude']) old_state.attributes['longitude'])

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.recorder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component that records all events and state changes. Allows other components Component that records all events and state changes. Allows other components
to query this database. to query this database.
@ -160,7 +158,7 @@ class RecorderRun(object):
class Recorder(threading.Thread): class Recorder(threading.Thread):
""" Threaded recorder class """ """A threaded recorder class."""
def __init__(self, hass): def __init__(self, hass):
threading.Thread.__init__(self) threading.Thread.__init__(self)
@ -305,11 +303,11 @@ class Recorder(threading.Thread):
# without the STOP event being fired. # without the STOP event being fired.
atexit.register(self._close_connection) atexit.register(self._close_connection)
# Have datetime objects be saved as integers # Have datetime objects be saved as integers.
sqlite3.register_adapter(date, _adapt_datetime) sqlite3.register_adapter(date, _adapt_datetime)
sqlite3.register_adapter(datetime, _adapt_datetime) sqlite3.register_adapter(datetime, _adapt_datetime)
# Validate we are on the correct schema or that we have to migrate # Validate we are on the correct schema or that we have to migrate.
cur = self.conn.cursor() cur = self.conn.cursor()
def save_migration(migration_id): def save_migration(migration_id):
@ -324,7 +322,7 @@ class Recorder(threading.Thread):
migration_id = cur.fetchone()[0] or 0 migration_id = cur.fetchone()[0] or 0
except sqlite3.OperationalError: except sqlite3.OperationalError:
# The table does not exist # The table does not exist.
cur.execute('CREATE TABLE schema_version (' cur.execute('CREATE TABLE schema_version ('
'migration_id integer primary key, performed integer)') 'migration_id integer primary key, performed integer)')
migration_id = 0 migration_id = 0
@ -399,7 +397,7 @@ class Recorder(threading.Thread):
save_migration(3) save_migration(3)
if migration_id < 4: if migration_id < 4:
# We had a bug where we did not save utc offset for recorder runs # We had a bug where we did not save utc offset for recorder runs.
cur.execute( cur.execute(
"""UPDATE recorder_runs SET utc_offset=? """UPDATE recorder_runs SET utc_offset=?
WHERE utc_offset IS NULL""", [self.utc_offset]) WHERE utc_offset IS NULL""", [self.utc_offset])
@ -412,15 +410,15 @@ class Recorder(threading.Thread):
save_migration(4) save_migration(4)
if migration_id < 5: if migration_id < 5:
# Add domain so that thermostat graphs look right # Add domain so that thermostat graphs look right.
try: try:
cur.execute(""" cur.execute("""
ALTER TABLE states ALTER TABLE states
ADD COLUMN domain text ADD COLUMN domain text
""") """)
except sqlite3.OperationalError: except sqlite3.OperationalError:
# We had a bug in this migration for a while on dev # We had a bug in this migration for a while on dev.
# Without this, dev-users will have to throw away their db # Without this, dev-users will have to throw away their db.
pass pass
# TravisCI has Python compiled against an old version of SQLite3 # TravisCI has Python compiled against an old version of SQLite3
@ -429,13 +427,13 @@ class Recorder(threading.Thread):
"instr", 2, "instr", 2,
lambda string, substring: string.find(substring) + 1) lambda string, substring: string.find(substring) + 1)
# populate domain with defaults # Populate domain with defaults.
cur.execute(""" cur.execute("""
UPDATE states UPDATE states
set domain=substr(entity_id, 0, instr(entity_id, '.')) set domain=substr(entity_id, 0, instr(entity_id, '.'))
""") """)
# add indexes we are going to use a lot on selects # Add indexes we are going to use a lot on selects.
cur.execute(""" cur.execute("""
CREATE INDEX states__state_changes ON CREATE INDEX states__state_changes ON
states (last_changed, last_updated, entity_id)""") states (last_changed, last_updated, entity_id)""")

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.rfxtrx Support for RFXtrx components.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides support for RFXtrx components.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/rfxtrx/ https://home-assistant.io/components/rfxtrx/
@ -34,7 +32,6 @@ RFXOBJECT = None
def setup(hass, config): def setup(hass, config):
"""Setup the RFXtrx component.""" """Setup the RFXtrx component."""
# Declare the Handle event # Declare the Handle event
def handle_receive(event): def handle_receive(event):
"""Callback all subscribers for RFXtrx gateway.""" """Callback all subscribers for RFXtrx gateway."""
@ -47,14 +44,14 @@ def setup(hass, config):
_LOGGER.info("Receive RFXCOM event from %s => %s", _LOGGER.info("Receive RFXCOM event from %s => %s",
event.device, entity_name) event.device, entity_name)
# Callback to HA registered components # Callback to HA registered components.
for subscriber in RECEIVED_EVT_SUBSCRIBERS: for subscriber in RECEIVED_EVT_SUBSCRIBERS:
subscriber(event) subscriber(event)
# Try to load the RFXtrx module # Try to load the RFXtrx module.
import RFXtrx as rfxtrxmod import RFXtrx as rfxtrxmod
# Init the rfxtrx module # Init the rfxtrx module.
global RFXOBJECT global RFXOBJECT
if ATTR_DEVICE not in config[DOMAIN]: if ATTR_DEVICE not in config[DOMAIN]:

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.rpi_gpio Support for controlling GPIO pins of a Raspberry Pi.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to control the GPIO pins of a Raspberry Pi.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/rpi_gpio/ https://home-assistant.io/components/rpi_gpio/
@ -19,11 +17,11 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=no-member # pylint: disable=no-member
def setup(hass, config): def setup(hass, config):
""" Sets up the Raspberry PI GPIO component. """ """Setup the Raspberry PI GPIO component."""
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
def cleanup_gpio(event): def cleanup_gpio(event):
""" Stuff to do before stop home assistant. """ """Stuff to do before stopping."""
GPIO.cleanup() GPIO.cleanup()
def prepare_gpio(event): def prepare_gpio(event):

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Scripts are a sequence of actions that can be triggered manually Scripts are a sequence of actions that can be triggered manually
by the user or automatically based upon automation events, etc. by the user or automatically based upon automation events, etc.
@ -68,7 +66,6 @@ def toggle(hass, entity_id):
def setup(hass, config): def setup(hass, config):
"""Load the scripts from the configuration.""" """Load the scripts from the configuration."""
component = EntityComponent(_LOGGER, DOMAIN, hass) component = EntityComponent(_LOGGER, DOMAIN, hass)
def service_handler(service): def service_handler(service):
@ -136,16 +133,17 @@ class Script(ToggleEntity):
@property @property
def should_poll(self): def should_poll(self):
"""No polling needed."""
return False return False
@property @property
def name(self): def name(self):
""" Returns the name of the entity. """ """Return the name of the entity."""
return self._name return self._name
@property @property
def state_attributes(self): def state_attributes(self):
""" Returns the state attributes. """ """Return the state attributes."""
attrs = {} attrs = {}
if self._can_cancel: if self._can_cancel:
attrs[ATTR_CAN_CANCEL] = self._can_cancel attrs[ATTR_CAN_CANCEL] = self._can_cancel

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.scsgate Support for SCSGate components.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides support for SCSGate components.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/scsgate/ https://home-assistant.io/components/scsgate/
@ -19,7 +17,6 @@ _LOGGER = logging.getLogger(__name__)
class SCSGate: class SCSGate:
"""Class dealing with the SCSGate device via scsgate.Reactor.""" """Class dealing with the SCSGate device via scsgate.Reactor."""
def __init__(self, device, logger): def __init__(self, device, logger):
self._logger = logger self._logger = logger
self._devices = {} self._devices = {}

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.shell_command
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Exposes regular shell commands as services. Exposes regular shell commands as services.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at

View File

@ -51,7 +51,6 @@ def setup(hass, config):
def statsd_event_listener(event): def statsd_event_listener(event):
"""Listen for new messages on the bus and sends them to StatsD.""" """Listen for new messages on the bus and sends them to StatsD."""
state = event.data.get('new_state') state = event.data.get('new_state')
if state is None: if state is None:

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sun
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to keep track of the sun. Provides functionality to keep track of the sun.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.tellduslive Support for Telldus Live.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tellduslive Component.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/tellduslive/ https://home-assistant.io/components/tellduslive/
@ -41,10 +39,10 @@ NETWORK = None
@Throttle(MIN_TIME_BETWEEN_SWITCH_UPDATES) @Throttle(MIN_TIME_BETWEEN_SWITCH_UPDATES)
def request_switches(): def request_switches():
""" make request to online service """ """Make request to online service."""
_LOGGER.debug("Updating switches from Telldus Live") _LOGGER.debug("Updating switches from Telldus Live")
switches = NETWORK.request("devices/list")["device"] switches = NETWORK.request("devices/list")["device"]
# filter out any group of switches # Filter out any group of switches.
switches = {switch["id"]: switch for switch in switches switches = {switch["id"]: switch for switch in switches
if switch["type"] == "device"} if switch["type"] == "device"}
return switches return switches
@ -52,10 +50,10 @@ def request_switches():
@Throttle(MIN_TIME_BETWEEN_SENSOR_UPDATES) @Throttle(MIN_TIME_BETWEEN_SENSOR_UPDATES)
def request_sensors(): def request_sensors():
""" make request to online service """ """Make request to online service."""
_LOGGER.debug("Updating sensors from Telldus Live") _LOGGER.debug("Updating sensors from Telldus Live")
units = NETWORK.request("sensors/list")["sensor"] units = NETWORK.request("sensors/list")["sensor"]
# one unit can contain many sensors # One unit can contain many sensors.
sensors = {unit["id"]+sensor["name"]: dict(unit, data=sensor) sensors = {unit["id"]+sensor["name"]: dict(unit, data=sensor)
for unit in units for unit in units
for sensor in unit["data"]} for sensor in unit["data"]}
@ -64,7 +62,6 @@ def request_sensors():
class TelldusLiveData(object): class TelldusLiveData(object):
"""Gets the latest data and update the states.""" """Gets the latest data and update the states."""
def __init__(self, hass, config): def __init__(self, hass, config):
public_key = config[DOMAIN].get(CONF_PUBLIC_KEY) public_key = config[DOMAIN].get(CONF_PUBLIC_KEY)
private_key = config[DOMAIN].get(CONF_PRIVATE_KEY) private_key = config[DOMAIN].get(CONF_PRIVATE_KEY)
@ -85,18 +82,17 @@ class TelldusLiveData(object):
access_secret=token_secret) access_secret=token_secret)
def validate_session(self): def validate_session(self):
""" Make a dummy request to see if the session is valid """ """Make a dummy request to see if the session is valid."""
response = self.request("user/profile") response = self.request("user/profile")
return response and 'email' in response return response and 'email' in response
def discover(self): def discover(self):
""" Update states, will trigger discover """ """Update states, will trigger discover."""
self.update_sensors() self.update_sensors()
self.update_switches() self.update_switches()
def _discover(self, found_devices, component_name): def _discover(self, found_devices, component_name):
""" Send discovery event if component not yet discovered """ """Send discovery event if component not yet discovered."""
if not len(found_devices): if not len(found_devices):
return return
@ -115,7 +111,7 @@ class TelldusLiveData(object):
ATTR_DISCOVERED: found_devices}) ATTR_DISCOVERED: found_devices})
def request(self, what, **params): def request(self, what, **params):
""" Sends a request to the tellstick live API """ """Sends a request to the Tellstick Live API."""
from tellive.live import const from tellive.live import const
supported_methods = const.TELLSTICK_TURNON \ supported_methods = const.TELLSTICK_TURNON \
@ -149,12 +145,8 @@ class TelldusLiveData(object):
_LOGGER.error("failed to make request to Tellduslive servers") _LOGGER.error("failed to make request to Tellduslive servers")
return None return None
def update_devices(self, def update_devices(self, local_devices, remote_devices, component_name):
local_devices, """Update local device list and discover new devices."""
remote_devices,
component_name):
""" update local device list and discover new devices """
if remote_devices is None: if remote_devices is None:
return local_devices return local_devices
@ -172,28 +164,28 @@ class TelldusLiveData(object):
return remote_devices return remote_devices
def update_sensors(self): def update_sensors(self):
""" update local list of sensors """ """Update local list of sensors."""
self._sensors = self.update_devices(self._sensors, self._sensors = self.update_devices(self._sensors,
request_sensors(), request_sensors(),
"sensor") "sensor")
def update_switches(self): def update_switches(self):
""" update local list of switches """ """Update local list of switches."""
self._switches = self.update_devices(self._switches, self._switches = self.update_devices(self._switches,
request_switches(), request_switches(),
"switch") "switch")
def _check_request(self, what, **params): def _check_request(self, what, **params):
""" Make request, check result if successful """ """Make request, check result if successful."""
response = self.request(what, **params) response = self.request(what, **params)
return response and response.get('status') == 'success' return response and response.get('status') == 'success'
def get_switch(self, switch_id): def get_switch(self, switch_id):
""" return switch representation """ """Return the switch representation."""
return self._switches[switch_id] return self._switches[switch_id]
def get_sensor(self, sensor_id): def get_sensor(self, sensor_id):
""" return sensor representation """ """Return the sensor representation."""
return self._sensors[sensor_id] return self._sensors[sensor_id]
def turn_switch_on(self, switch_id): def turn_switch_on(self, switch_id):
@ -211,9 +203,7 @@ class TelldusLiveData(object):
def setup(hass, config): def setup(hass, config):
"""Setup the Telldus Live component.""" """Setup the Telldus Live component."""
# FIXME: aquire app key and provide authentication using username+password
# fixme: aquire app key and provide authentication
# using username + password
if not validate_config(config, if not validate_config(config,
{DOMAIN: [CONF_PUBLIC_KEY, {DOMAIN: [CONF_PUBLIC_KEY,
CONF_PRIVATE_KEY, CONF_PRIVATE_KEY,

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.updater Support to check for available updates.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component that checks for available updates.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
at https://home-assistant.io/components/updater/ at https://home-assistant.io/components/updater/
@ -22,7 +20,6 @@ ENTITY_ID = 'updater.updater'
def setup(hass, config): def setup(hass, config):
"""Setup the updater component.""" """Setup the updater component."""
def check_newest_version(_=None): def check_newest_version(_=None):
"""Check if a new version is available and report if one is.""" """Check if a new version is available and report if one is."""
newest = get_newest_version() newest = get_newest_version()

View File

@ -1,7 +1,5 @@
""" """
components.verisure Support for Verisure components.
~~~~~~~~~~~~~~~~~~~
Provides support for verisure components.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/verisure/ https://home-assistant.io/components/verisure/
@ -34,7 +32,6 @@ HUB = None
def setup(hass, config): def setup(hass, config):
"""Setup the Verisure component.""" """Setup the Verisure component."""
if not validate_config(config, if not validate_config(config,
{DOMAIN: [CONF_USERNAME, CONF_PASSWORD]}, {DOMAIN: [CONF_USERNAME, CONF_PASSWORD]},
_LOGGER): _LOGGER):
@ -46,7 +43,6 @@ def setup(hass, config):
if not HUB.login(): if not HUB.login():
return False return False
# Load components for the devices in the ISY controller that we support
for comp_name, discovery in ((('sensor', DISCOVER_SENSORS), for comp_name, discovery in ((('sensor', DISCOVER_SENSORS),
('switch', DISCOVER_SWITCHES), ('switch', DISCOVER_SWITCHES),
('alarm_control_panel', DISCOVER_ALARMS), ('alarm_control_panel', DISCOVER_ALARMS),
@ -62,8 +58,7 @@ def setup(hass, config):
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
class VerisureHub(object): class VerisureHub(object):
""" Verisure wrapper class """ """A Verisure wrapper class."""
def __init__(self, domain_config, verisure): def __init__(self, domain_config, verisure):
self.alarm_status = {} self.alarm_status = {}
self.lock_status = {} self.lock_status = {}
@ -88,7 +83,7 @@ class VerisureHub(object):
domain_config[CONF_PASSWORD]) domain_config[CONF_PASSWORD])
def login(self): def login(self):
""" Login to MyPages """ """Login to Verisure MyPages."""
try: try:
self.my_pages.login() self.my_pages.login()
except self._verisure.Error as ex: except self._verisure.Error as ex:
@ -105,21 +100,21 @@ class VerisureHub(object):
@Throttle(timedelta(seconds=1)) @Throttle(timedelta(seconds=1))
def update_locks(self): def update_locks(self):
""" Updates the status of the alarm. """ """Updates the status of the locks."""
self.update_component( self.update_component(
self.my_pages.lock.get, self.my_pages.lock.get,
self.lock_status) self.lock_status)
@Throttle(timedelta(seconds=60)) @Throttle(timedelta(seconds=60))
def update_climate(self): def update_climate(self):
""" Updates the status of the smartplugs. """ """Updates the status of the climate units."""
self.update_component( self.update_component(
self.my_pages.climate.get, self.my_pages.climate.get,
self.climate_status) self.climate_status)
@Throttle(timedelta(seconds=60)) @Throttle(timedelta(seconds=60))
def update_mousedetection(self): def update_mousedetection(self):
""" Updates the status of the smartplugs. """ """Updates the status of the mouse detectors."""
self.update_component( self.update_component(
self.my_pages.mousedetection.get, self.my_pages.mousedetection.get,
self.mouse_status) self.mouse_status)
@ -132,7 +127,7 @@ class VerisureHub(object):
self.smartplug_status) self.smartplug_status)
def update_component(self, get_function, status): def update_component(self, get_function, status):
""" Updates the status of verisure components. """ """Updates the status of Verisure components."""
if self._wrong_password_given: if self._wrong_password_given:
_LOGGER.error('Wrong password for Verisure, update config') _LOGGER.error('Wrong password for Verisure, update config')
return return
@ -147,7 +142,7 @@ class VerisureHub(object):
self.reconnect() self.reconnect()
def reconnect(self): def reconnect(self):
""" Reconnect to verisure mypages. """ """Reconnect to Verisure MyPages."""
if self._reconnect_timeout > time.time(): if self._reconnect_timeout > time.time():
return return
if not self._lock.acquire(blocking=False): if not self._lock.acquire(blocking=False):

View File

@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
""" """
homeassistant.components.weblink Support for links to external web pages.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adds links to external webpages.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/weblink/ https://home-assistant.io/components/weblink/
@ -24,7 +21,6 @@ _LOGGER = logging.getLogger(__name__)
def setup(hass, config): def setup(hass, config):
"""Setup weblink component.""" """Setup weblink component."""
links = config.get(DOMAIN) links = config.get(DOMAIN)
for link in links.get('entities'): for link in links.get('entities'):
@ -40,7 +36,6 @@ def setup(hass, config):
class Link(Entity): class Link(Entity):
"""Represent a link.""" """Represent a link."""
def __init__(self, hass, name, url, icon): def __init__(self, hass, name, url, icon):
self.hass = hass self.hass = hass
self._name = name self._name = name
@ -51,15 +46,15 @@ class Link(Entity):
@property @property
def icon(self): def icon(self):
""" Icon to use in the frontend, if any. """ """Return the icon to use in the frontend, if any."""
return self._icon return self._icon
@property @property
def name(self): def name(self):
""" Returns the name of the URL. """ """Return the name of the URL."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the URL. """ """Return the URL."""
return self._url return self._url

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.wemo Support for WeMo device discovery.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WeMo device discovery.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/wemo/ https://home-assistant.io/components/wemo/
@ -18,7 +16,7 @@ DISCOVER_LIGHTS = 'wemo.light'
DISCOVER_MOTION = 'wemo.motion' DISCOVER_MOTION = 'wemo.motion'
DISCOVER_SWITCHES = 'wemo.switch' DISCOVER_SWITCHES = 'wemo.switch'
# mapping from Wemo model_name to service # Mapping from Wemo model_name to service.
WEMO_MODEL_DISPATCH = { WEMO_MODEL_DISPATCH = {
'Bridge': DISCOVER_LIGHTS, 'Bridge': DISCOVER_LIGHTS,
'Insight': DISCOVER_SWITCHES, 'Insight': DISCOVER_SWITCHES,
@ -77,7 +75,7 @@ def setup(hass, config):
_LOGGER.info("Scanning for WeMo devices.") _LOGGER.info("Scanning for WeMo devices.")
devices = [(device.host, device) for device in pywemo.discover_devices()] devices = [(device.host, device) for device in pywemo.discover_devices()]
# Add static devices from the config file # Add static devices from the config file.
devices.extend((address, None) devices.extend((address, None)
for address in config.get(DOMAIN, {}).get('static', [])) for address in config.get(DOMAIN, {}).get('static', []))

View File

@ -1,7 +1,6 @@
""" """
homeassistant.components.wink Support for Wink hubs.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connects to a Wink hub and loads relevant components to control its devices.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/wink/ https://home-assistant.io/components/wink/
""" """
@ -27,7 +26,7 @@ DISCOVER_GARAGE_DOORS = "wink.garage_doors"
def setup(hass, config): def setup(hass, config):
""" Sets up the Wink component. """ """Setup the Wink component."""
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
if not validate_config(config, {DOMAIN: [CONF_ACCESS_TOKEN]}, logger): if not validate_config(config, {DOMAIN: [CONF_ACCESS_TOKEN]}, logger):
@ -64,34 +63,33 @@ def setup(hass, config):
class WinkToggleDevice(ToggleEntity): class WinkToggleDevice(ToggleEntity):
""" Represents a Wink toogle (switch) device. """ """Represents a Wink toggle (switch) device."""
def __init__(self, wink): def __init__(self, wink):
self.wink = wink self.wink = wink
@property @property
def unique_id(self): def unique_id(self):
""" Returns the id of this Wink switch. """ """Return the ID of this Wink device."""
return "{}.{}".format(self.__class__, self.wink.device_id()) return "{}.{}".format(self.__class__, self.wink.device_id())
@property @property
def name(self): def name(self):
""" Returns the name of the light if any. """ """Return the name of the device."""
return self.wink.name() return self.wink.name()
@property @property
def is_on(self): def is_on(self):
""" True if light is on. """ """True if decive is on."""
return self.wink.state() return self.wink.state()
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turns the switch on. """ """Turns the device on."""
self.wink.set_state(True) self.wink.set_state(True)
def turn_off(self): def turn_off(self):
""" Turns the switch off. """ """Turns the device off."""
self.wink.set_state(False) self.wink.set_state(False)
def update(self): def update(self):
""" Update state of the light. """ """Update state of the device."""
self.wink.update_state() self.wink.update_state()

View File

@ -1,8 +1,5 @@
""" """
homeassistant.components.zigbee Support for ZigBee devices.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets up and provides access to a ZigBee device and contains generic entity
classes.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/zigbee/ https://home-assistant.io/components/zigbee/

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.zone Support for the definition of zones.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows defintion of zones in Home Assistant.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/zone/ https://home-assistant.io/components/zone/
@ -108,7 +106,7 @@ def setup(hass, config):
class Zone(Entity): class Zone(Entity):
""" Represents a Zone in Home Assistant. """ """Represents a Zone."""
# pylint: disable=too-many-arguments, too-many-instance-attributes # pylint: disable=too-many-arguments, too-many-instance-attributes
def __init__(self, hass, name, latitude, longitude, radius, icon, passive): def __init__(self, hass, name, latitude, longitude, radius, icon, passive):
self.hass = hass self.hass = hass
@ -121,19 +119,22 @@ class Zone(Entity):
@property @property
def name(self): def name(self):
""" Return the name of the zone."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" The state property really does nothing for a zone. """ """Return the state property really does nothing for a zone."""
return STATE return STATE
@property @property
def icon(self): def icon(self):
"""Return the icon if any."""
return self._icon return self._icon
@property @property
def state_attributes(self): def state_attributes(self):
""" Return the state attributes of the zone."""
data = { data = {
ATTR_HIDDEN: True, ATTR_HIDDEN: True,
ATTR_LATITUDE: self._latitude, ATTR_LATITUDE: self._latitude,

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.zwave Support for Z-Wave.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connects Home Assistant to a Z-Wave network.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/zwave/ https://home-assistant.io/components/zwave/
@ -56,8 +54,8 @@ TYPE_BOOL = "Bool"
TYPE_DECIMAL = "Decimal" TYPE_DECIMAL = "Decimal"
# list of tuple (DOMAIN, discovered service, supported command # List of tuple (DOMAIN, discovered service, supported command classes,
# classes, value type) # value type).
DISCOVERY_COMPONENTS = [ DISCOVERY_COMPONENTS = [
('sensor', ('sensor',
DISCOVER_SENSORS, DISCOVER_SENSORS,
@ -113,8 +111,8 @@ def _value_name(value):
def _object_id(value): def _object_id(value):
"""Returns the object_id of the device value. """Returns the object_id of the device value.
The object_id contains node_id and value instance id The object_id contains node_id and value instance id
to not collide with other entity_ids""" to not collide with other entity_ids.
"""
object_id = "{}_{}".format(slugify(_value_name(value)), object_id = "{}_{}".format(slugify(_value_name(value)),
value.node.node_id) value.node.node_id)
@ -138,8 +136,7 @@ def nice_print_node(node):
def get_config_value(node, value_index): def get_config_value(node, value_index):
""" Returns the current config value for a specific index. """ """Returns the current configuration value for a specific index."""
try: try:
for value in node.values.values(): for value in node.values.values():
# 112 == config command class # 112 == config command class
@ -194,7 +191,6 @@ def setup(hass, config):
def value_added(node, value): def value_added(node, value):
"""Called when a value is added to a node on the network.""" """Called when a value is added to a node on the network."""
for (component, for (component,
discovery_service, discovery_service,
command_ids, command_ids,
@ -245,11 +241,11 @@ def setup(hass, config):
scene_activated, ZWaveNetwork.SIGNAL_SCENE_EVENT, weak=False) scene_activated, ZWaveNetwork.SIGNAL_SCENE_EVENT, weak=False)
def add_node(event): def add_node(event):
""" Switch into inclusion mode """ """Switch into inclusion mode."""
NETWORK.controller.begin_command_add_device() NETWORK.controller.begin_command_add_device()
def remove_node(event): def remove_node(event):
""" Switch into exclusion mode""" """Switch into exclusion mode."""
NETWORK.controller.begin_command_remove_device() NETWORK.controller.begin_command_remove_device()
def stop_zwave(event): def stop_zwave(event):
@ -257,7 +253,7 @@ def setup(hass, config):
NETWORK.stop() NETWORK.stop()
def start_zwave(event): def start_zwave(event):
""" Called when Home Assistant starts up. """ """Startup """
NETWORK.start() NETWORK.start()
polling_interval = convert( polling_interval = convert(
@ -267,7 +263,7 @@ def setup(hass, config):
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zwave) hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zwave)
# register add / remove node services for zwave sticks without # Register add / remove node services for Z-Wave sticks without
# hardware inclusion button # hardware inclusion button
hass.services.register(DOMAIN, SERVICE_ADD_NODE, add_node) hass.services.register(DOMAIN, SERVICE_ADD_NODE, add_node)
hass.services.register(DOMAIN, SERVICE_REMOVE_NODE, remove_node) hass.services.register(DOMAIN, SERVICE_REMOVE_NODE, remove_node)
@ -278,14 +274,14 @@ def setup(hass, config):
class ZWaveDeviceEntity: class ZWaveDeviceEntity:
""" Represents a ZWave node entity within Home Assistant. """ """Represents a Z-Wave node entity."""
def __init__(self, value, domain): def __init__(self, value, domain):
self._value = value self._value = value
self.entity_id = "{}.{}".format(domain, self._object_id()) self.entity_id = "{}.{}".format(domain, self._object_id())
@property @property
def should_poll(self): def should_poll(self):
""" False because we will push our own state to HA when changed. """ """No polling needed."""
return False return False
@property @property
@ -300,15 +296,15 @@ class ZWaveDeviceEntity:
return _value_name(self._value) return _value_name(self._value)
def _object_id(self): def _object_id(self):
""" Returns the object_id of the device value. """
The object_id contains node_id and value instance id Returns the object_id of the device value. The object_id contains
to not collide with other entity_ids""" node_id and value instance id to not collide with other entity_ids.
"""
return _object_id(self._value) return _object_id(self._value)
@property @property
def device_state_attributes(self): def device_state_attributes(self):
""" Returns device specific state attributes. """ """Return device specific state attributes."""
attrs = { attrs = {
ATTR_NODE_ID: self._value.node.node_id, ATTR_NODE_ID: self._value.node.node_id,
} }