* Use const

* Align quotes
This commit is contained in:
Fabian Affolter 2017-08-25 13:30:00 +02:00 committed by GitHub
parent 2ec0d25a38
commit fdeef2f707
2 changed files with 16 additions and 18 deletions

View File

@ -45,13 +45,12 @@ def setup(hass, config):
try:
sock.connect((host, port))
sock.shutdown(2)
_LOGGER.debug('Connection to Graphite possible')
_LOGGER.debug("Connection to Graphite possible")
except socket.error:
_LOGGER.error('Not able to connect to Graphite')
_LOGGER.error("Not able to connect to Graphite")
return False
GraphiteFeeder(hass, host, port, prefix)
return True
@ -143,15 +142,15 @@ class GraphiteFeeder(threading.Thread):
_LOGGER.debug("Processing STATE_CHANGED event for %s",
event.data['entity_id'])
try:
self._report_attributes(event.data['entity_id'],
event.data['new_state'])
self._report_attributes(
event.data['entity_id'], event.data['new_state'])
# pylint: disable=broad-except
except Exception:
# Catch this so we can avoid the thread dying and
# make it visible.
_LOGGER.exception("Failed to process STATE_CHANGED event")
else:
_LOGGER.warning("Processing unexpected event type %s",
event.event_type)
_LOGGER.warning(
"Processing unexpected event type %s", event.event_type)
self._queue.task_done()

View File

@ -12,16 +12,18 @@ from aiohttp import web
from homeassistant.components.http import HomeAssistantView
from homeassistant.components import recorder
from homeassistant.const import (CONF_DOMAINS, CONF_ENTITIES, CONF_EXCLUDE,
CONF_INCLUDE, EVENT_STATE_CHANGED,
TEMP_CELSIUS, TEMP_FAHRENHEIT)
from homeassistant.const import (
CONF_DOMAINS, CONF_ENTITIES, CONF_EXCLUDE, CONF_INCLUDE, TEMP_CELSIUS,
EVENT_STATE_CHANGED, TEMP_FAHRENHEIT, CONTENT_TYPE_TEXT_PLAIN)
from homeassistant import core as hacore
from homeassistant.helpers import state as state_helper
from homeassistant.util.temperature import fahrenheit_to_celsius
REQUIREMENTS = ['prometheus_client==0.0.19']
_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['prometheus_client==0.0.19']
API_ENDPOINT = '/api/prometheus'
DOMAIN = 'prometheus'
DEPENDENCIES = ['http']
@ -30,8 +32,6 @@ CONFIG_SCHEMA = vol.Schema({
DOMAIN: recorder.FILTER_SCHEMA,
}, extra=vol.ALLOW_EXTRA)
API_ENDPOINT = '/api/prometheus'
def setup(hass, config):
"""Activate Prometheus component."""
@ -45,11 +45,10 @@ def setup(hass, config):
metrics = Metrics(prometheus_client, exclude, include)
hass.bus.listen(EVENT_STATE_CHANGED, metrics.handle_event)
return True
class Metrics:
class Metrics(object):
"""Model all of the metrics which should be exposed to Prometheus."""
def __init__(self, prometheus_client, exclude, include):
@ -81,7 +80,7 @@ class Metrics:
entity_id not in self.include_entities):
return
handler = '_handle_' + domain
handler = '_handle_{}'.format(domain)
if hasattr(self, handler):
getattr(self, handler)(state)
@ -233,8 +232,8 @@ class PrometheusView(HomeAssistantView):
@asyncio.coroutine
def get(self, request):
"""Handle request for Prometheus metrics."""
_LOGGER.debug('Received Prometheus metrics request')
_LOGGER.debug("Received Prometheus metrics request")
return web.Response(
body=self.prometheus_client.generate_latest(),
content_type="text/plain")
content_type=CONTENT_TYPE_TEXT_PLAIN)