Skip to content

Commit

Permalink
Modify docstrings to match PEP257
Browse files Browse the repository at this point in the history
  • Loading branch information
fabaff committed Feb 26, 2016
1 parent 278fdc0 commit 2609852
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 60 deletions.
11 changes: 4 additions & 7 deletions homeassistant/components/browser.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
"""
homeassistant.components.browser
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to launch a webbrowser 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
https://home-assistant.io/components/browser/
"""

DOMAIN = "browser"

SERVICE_BROWSE_URL = "browse_url"


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

hass.services.register(DOMAIN, SERVICE_BROWSE_URL,
Expand Down
25 changes: 10 additions & 15 deletions homeassistant/components/graphite.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
homeassistant.components.graphite
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
https://home-assistant.io/components/graphite/
Expand All @@ -22,7 +20,7 @@


def setup(hass, config):
""" Setup graphite feeder. """
"""Setup the Graphite feeder."""
graphite_config = config.get('graphite', {})
host = graphite_config.get('host', 'localhost')
prefix = graphite_config.get('prefix', 'ha')
Expand All @@ -37,14 +35,13 @@ def setup(hass, config):


class GraphiteFeeder(threading.Thread):
""" Feeds data to graphite. """
"""Feeds data to Graphite."""
def __init__(self, hass, host, port, prefix):
super(GraphiteFeeder, self).__init__(daemon=True)
self._hass = hass
self._host = host
self._port = port
# rstrip any trailing dots in case they think they
# need it
# rstrip any trailing dots in case they think they need it
self._prefix = prefix.rstrip('.')
self._queue = queue.Queue()
self._quit_object = object()
Expand All @@ -59,23 +56,18 @@ def __init__(self, hass, host, port, prefix):
self._host, self._port)

def start_listen(self, event):
""" Start event-processing thread. """
"""Start event-processing thread."""
_LOGGER.debug('Event processing thread started')
self._we_started = True
self.start()

def shutdown(self, event):
""" Tell the thread that we are done.
This does not block because there is nothing to
clean up (and no penalty for killing in-process
connections to graphite.
"""
"""Signal shutdown of processing event."""
_LOGGER.debug('Event processing signaled exit')
self._queue.put(self._quit_object)

def event_listener(self, event):
""" Queue an event for processing. """
"""Queue an event for processing."""
if self.is_alive() or not self._we_started:
_LOGGER.debug('Received event')
self._queue.put(event)
Expand All @@ -84,6 +76,7 @@ def event_listener(self, event):
'queuing event!')

def _send_to_graphite(self, data):
"""Send data to Graphite."""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
sock.connect((self._host, self._port))
Expand All @@ -92,6 +85,7 @@ def _send_to_graphite(self, data):
sock.close()

def _report_attributes(self, entity_id, new_state):
"""Report the attributes."""
now = time.time()
things = dict(new_state.attributes)
try:
Expand All @@ -114,6 +108,7 @@ def _report_attributes(self, entity_id, new_state):
_LOGGER.exception('Failed to send data to graphite')

def run(self):
"""Run the process to export the data."""
while True:
event = self._queue.get()
if event == self._quit_object:
Expand Down
14 changes: 5 additions & 9 deletions homeassistant/components/influxdb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
homeassistant.components.influxdb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InfluxDB component which allows you to send data to an Influx database.
A component which allows you to send data to an Influx database.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/influxdb/
Expand Down Expand Up @@ -36,8 +34,7 @@


def setup(hass, config):
""" Setup the InfluxDB component. """

"""Setup the InfluxDB component."""
from influxdb import InfluxDBClient, exceptions

if not validate_config(config, {DOMAIN: ['host',
Expand All @@ -63,13 +60,12 @@ def setup(hass, config):
influx.query("select * from /.*/ LIMIT 1;")
except exceptions.InfluxDBClientError as exc:
_LOGGER.error("Database host is not accessible due to '%s', please "
"check your entries in the configuration file and that"
" the database exists and is READ/WRITE.", exc)
"check your entries in the configuration file and that "
"the database exists and is READ/WRITE.", exc)
return False

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')
if state is None or state.state in (STATE_UNKNOWN, ''):
return
Expand Down
25 changes: 10 additions & 15 deletions homeassistant/components/mqtt_eventstream.py
Original file line number Diff line number Diff line change
@@ -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
https://home-assistant.io/components/mqtt_eventstream.html
https://home-assistant.io/components/mqtt_eventstream/
"""
import json

Expand All @@ -17,21 +15,18 @@
from homeassistant.core import EventOrigin, State
from homeassistant.remote import JSONEncoder

# The domain of your component. Should be equal to the name of your component
DOMAIN = "mqtt_eventstream"

# List of component names (string) your component depends upon
DEPENDENCIES = ['mqtt']


def setup(hass, config):
""" Setup th MQTT eventstream component. """
"""Setup th MQTT eventstream component."""
mqtt = loader.get_component('mqtt')
pub_topic = config[DOMAIN].get('publish_topic', None)
sub_topic = config[DOMAIN].get('subscribe_topic', None)

def _event_publisher(event):
""" Handle events by publishing them on the MQTT queue. """
"""Handle events by publishing them on the MQTT queue."""
if event.origin != EventOrigin.local:
return
if event.event_type == EVENT_TIME_CHANGED:
Expand Down Expand Up @@ -61,15 +56,15 @@ def _event_publisher(event):
msg = json.dumps(event_info, cls=JSONEncoder)
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:
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):
"""
Receive events published by the other HA instance and fire
them on this hass instance.
Receive events published by the other HA instance and fire them on
this hass instance.
"""
event = json.loads(payload)
event_type = event.get('event_type')
Expand All @@ -92,10 +87,10 @@ def _event_receiver(topic, payload, qos):
origin=EventOrigin.remote
)

# Only subscribe if you specified a topic
# Only subscribe if you specified a topic.
if sub_topic:
mqtt.subscribe(hass, sub_topic, _event_receiver)

hass.states.set('{domain}.initialized'.format(domain=DOMAIN), True)
# return boolean to indicate that initialization was successful

return True
12 changes: 4 additions & 8 deletions homeassistant/components/splunk.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
homeassistant.components.splunk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Splunk component which allows you to send data to an Splunk instance
utilizing the HTTP Event Collector.
A 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
https://home-assistant.io/components/splunk/
Expand Down Expand Up @@ -33,8 +31,7 @@


def setup(hass, config):
""" Setup the Splunk component. """

"""Setup the Splunk component."""
if not validate_config(config, {DOMAIN: ['token']}, _LOGGER):
_LOGGER.error("You must include the token for your HTTP "
"Event Collector input in Splunk.")
Expand All @@ -55,8 +52,7 @@ def setup(hass, config):
headers = {'Authorization': 'Splunk ' + token}

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')

if state is None:
Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/statsd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
homeassistant.components.statsd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StatsD component which allows you to send data to many backends.
A component which allows you to send data to StatsD.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/statsd/
Expand Down Expand Up @@ -31,8 +29,7 @@


def setup(hass, config):
""" Setup the StatsD component. """

"""Setup the StatsD component."""
from statsd.compat import NUM_TYPES
import statsd

Expand All @@ -53,7 +50,7 @@ def setup(hass, config):
meter = statsd.Gauge(prefix, statsd_connection)

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')

Expand Down

0 comments on commit 2609852

Please sign in to comment.