Modify docstrings to match PEP257
This commit is contained in:
parent
278fdc0983
commit
2609852d6e
6 changed files with 36 additions and 60 deletions
|
@ -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/
|
||||
|
@ -22,7 +20,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
|
||||
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')
|
||||
|
@ -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()
|
||||
|
@ -59,23 +56,18 @@ class GraphiteFeeder(threading.Thread):
|
|||
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)
|
||||
|
@ -84,6 +76,7 @@ class GraphiteFeeder(threading.Thread):
|
|||
'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))
|
||||
|
@ -92,6 +85,7 @@ class GraphiteFeeder(threading.Thread):
|
|||
sock.close()
|
||||
|
||||
def _report_attributes(self, entity_id, new_state):
|
||||
"""Report the attributes."""
|
||||
now = time.time()
|
||||
things = dict(new_state.attributes)
|
||||
try:
|
||||
|
@ -114,6 +108,7 @@ class GraphiteFeeder(threading.Thread):
|
|||
_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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue