Modify docstrings to match PEP257

This commit is contained in:
Fabian Affolter 2016-02-26 23:52:54 +01:00
parent 278fdc0983
commit 2609852d6e
6 changed files with 36 additions and 60 deletions

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.browser
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to launch a web browser on the host machine. Provides functionality to launch a web browser on the 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
@ -8,14 +6,13 @@ https://home-assistant.io/components/browser/
""" """
DOMAIN = "browser" DOMAIN = "browser"
SERVICE_BROWSE_URL = "browse_url" SERVICE_BROWSE_URL = "browse_url"
def setup(hass, config): def setup(hass, config):
""" Listen for browse_url events and open """
the url in the default webbrowser. """ Listen for browse_url events and open the url in the default web browser.
"""
import webbrowser import webbrowser
hass.services.register(DOMAIN, SERVICE_BROWSE_URL, hass.services.register(DOMAIN, SERVICE_BROWSE_URL,

View File

@ -1,8 +1,6 @@
""" """
homeassistant.components.graphite
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component that records all events and state changes and feeds the data to Component that records all events and state changes and feeds the data to
a graphite installation. a Graphite installation.
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/graphite/ https://home-assistant.io/components/graphite/
@ -22,7 +20,7 @@ _LOGGER = logging.getLogger(__name__)
def setup(hass, config): def setup(hass, config):
""" Setup graphite feeder. """ """Setup the Graphite feeder."""
graphite_config = config.get('graphite', {}) graphite_config = config.get('graphite', {})
host = graphite_config.get('host', 'localhost') host = graphite_config.get('host', 'localhost')
prefix = graphite_config.get('prefix', 'ha') prefix = graphite_config.get('prefix', 'ha')
@ -37,14 +35,13 @@ def setup(hass, config):
class GraphiteFeeder(threading.Thread): class GraphiteFeeder(threading.Thread):
""" Feeds data to graphite. """ """Feeds data to Graphite."""
def __init__(self, hass, host, port, prefix): def __init__(self, hass, host, port, prefix):
super(GraphiteFeeder, self).__init__(daemon=True) super(GraphiteFeeder, self).__init__(daemon=True)
self._hass = hass self._hass = hass
self._host = host self._host = host
self._port = port self._port = port
# rstrip any trailing dots in case they think they # rstrip any trailing dots in case they think they need it
# need it
self._prefix = prefix.rstrip('.') self._prefix = prefix.rstrip('.')
self._queue = queue.Queue() self._queue = queue.Queue()
self._quit_object = object() self._quit_object = object()
@ -65,12 +62,7 @@ class GraphiteFeeder(threading.Thread):
self.start() self.start()
def shutdown(self, event): def shutdown(self, event):
""" Tell the thread that we are done. """Signal shutdown of processing event."""
This does not block because there is nothing to
clean up (and no penalty for killing in-process
connections to graphite.
"""
_LOGGER.debug('Event processing signaled exit') _LOGGER.debug('Event processing signaled exit')
self._queue.put(self._quit_object) self._queue.put(self._quit_object)
@ -84,6 +76,7 @@ class GraphiteFeeder(threading.Thread):
'queuing event!') 'queuing event!')
def _send_to_graphite(self, data): def _send_to_graphite(self, data):
"""Send data to Graphite."""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10) sock.settimeout(10)
sock.connect((self._host, self._port)) sock.connect((self._host, self._port))
@ -92,6 +85,7 @@ class GraphiteFeeder(threading.Thread):
sock.close() sock.close()
def _report_attributes(self, entity_id, new_state): def _report_attributes(self, entity_id, new_state):
"""Report the attributes."""
now = time.time() now = time.time()
things = dict(new_state.attributes) things = dict(new_state.attributes)
try: try:
@ -114,6 +108,7 @@ class GraphiteFeeder(threading.Thread):
_LOGGER.exception('Failed to send data to graphite') _LOGGER.exception('Failed to send data to graphite')
def run(self): def run(self):
"""Run the process to export the data."""
while True: while True:
event = self._queue.get() event = self._queue.get()
if event == self._quit_object: if event == self._quit_object:

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.influxdb A component which allows you to send data to an Influx database.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InfluxDB component which allows you to send data to an Influx database.
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/influxdb/ https://home-assistant.io/components/influxdb/
@ -37,7 +35,6 @@ CONF_VERIFY_SSL = 'verify_ssl'
def setup(hass, config): def setup(hass, config):
"""Setup the InfluxDB component.""" """Setup the InfluxDB component."""
from influxdb import InfluxDBClient, exceptions from influxdb import InfluxDBClient, exceptions
if not validate_config(config, {DOMAIN: ['host', if not validate_config(config, {DOMAIN: ['host',
@ -69,7 +66,6 @@ def setup(hass, config):
def influx_event_listener(event): def influx_event_listener(event):
"""Listen for new messages on the bus and sends them to Influx.""" """Listen for new messages on the bus and sends them to Influx."""
state = event.data.get('new_state') state = event.data.get('new_state')
if state is None or state.state in (STATE_UNKNOWN, ''): if state is None or state.state in (STATE_UNKNOWN, ''):
return return

View File

@ -1,10 +1,8 @@
""" """
homeassistant.components.mqtt_eventstream Connect two Home Assistant instances via MQTT.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connect two Home Assistant instances via MQTT..
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/mqtt_eventstream.html https://home-assistant.io/components/mqtt_eventstream/
""" """
import json import json
@ -17,10 +15,7 @@ from homeassistant.const import (
from homeassistant.core import EventOrigin, State from homeassistant.core import EventOrigin, State
from homeassistant.remote import JSONEncoder from homeassistant.remote import JSONEncoder
# The domain of your component. Should be equal to the name of your component
DOMAIN = "mqtt_eventstream" DOMAIN = "mqtt_eventstream"
# List of component names (string) your component depends upon
DEPENDENCIES = ['mqtt'] DEPENDENCIES = ['mqtt']
@ -61,15 +56,15 @@ def setup(hass, config):
msg = json.dumps(event_info, cls=JSONEncoder) msg = json.dumps(event_info, cls=JSONEncoder)
mqtt.publish(hass, pub_topic, msg) mqtt.publish(hass, pub_topic, msg)
# Only listen for local events if you are going to publish them # Only listen for local events if you are going to publish them.
if pub_topic: if pub_topic:
hass.bus.listen(MATCH_ALL, _event_publisher) hass.bus.listen(MATCH_ALL, _event_publisher)
# Process events from a remote server that are received on a queue # Process events from a remote server that are received on a queue.
def _event_receiver(topic, payload, qos): def _event_receiver(topic, payload, qos):
""" """
Receive events published by the other HA instance and fire Receive events published by the other HA instance and fire them on
them on this hass instance. this hass instance.
""" """
event = json.loads(payload) event = json.loads(payload)
event_type = event.get('event_type') event_type = event.get('event_type')
@ -92,10 +87,10 @@ def setup(hass, config):
origin=EventOrigin.remote origin=EventOrigin.remote
) )
# Only subscribe if you specified a topic # Only subscribe if you specified a topic.
if sub_topic: if sub_topic:
mqtt.subscribe(hass, sub_topic, _event_receiver) mqtt.subscribe(hass, sub_topic, _event_receiver)
hass.states.set('{domain}.initialized'.format(domain=DOMAIN), True) hass.states.set('{domain}.initialized'.format(domain=DOMAIN), True)
# return boolean to indicate that initialization was successful
return True return True

View File

@ -1,8 +1,6 @@
""" """
homeassistant.components.splunk A component which allows you to send data to an Splunk instance utilizing the
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HTTP Event Collector.
Splunk component which allows you to send data to an Splunk instance
utilizing the HTTP Event Collector.
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/splunk/ https://home-assistant.io/components/splunk/
@ -34,7 +32,6 @@ CONF_SSL = 'SSL'
def setup(hass, config): def setup(hass, config):
"""Setup the Splunk component.""" """Setup the Splunk component."""
if not validate_config(config, {DOMAIN: ['token']}, _LOGGER): if not validate_config(config, {DOMAIN: ['token']}, _LOGGER):
_LOGGER.error("You must include the token for your HTTP " _LOGGER.error("You must include the token for your HTTP "
"Event Collector input in Splunk.") "Event Collector input in Splunk.")
@ -56,7 +53,6 @@ def setup(hass, config):
def splunk_event_listener(event): def splunk_event_listener(event):
"""Listen for new messages on the bus and sends them to Splunk.""" """Listen for new messages on the bus and sends them to Splunk."""
state = event.data.get('new_state') state = event.data.get('new_state')
if state is None: if state is None:

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.statsd A component which allows you to send data to StatsD.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StatsD component which allows you to send data to many backends.
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/statsd/ https://home-assistant.io/components/statsd/
@ -32,7 +30,6 @@ CONF_RATE = 'rate'
def setup(hass, config): def setup(hass, config):
"""Setup the StatsD component.""" """Setup the StatsD component."""
from statsd.compat import NUM_TYPES from statsd.compat import NUM_TYPES
import statsd import statsd