From fdeef2f707ec0f3609c52369a9f0b3a7d71411f3 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 25 Aug 2017 13:30:00 +0200 Subject: [PATCH] Use const (#9127) * Use const * Align quotes --- homeassistant/components/graphite.py | 13 ++++++------- homeassistant/components/prometheus.py | 21 ++++++++++----------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/graphite.py b/homeassistant/components/graphite.py index fc2a196c4c6..e4626d0f016 100644 --- a/homeassistant/components/graphite.py +++ b/homeassistant/components/graphite.py @@ -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() diff --git a/homeassistant/components/prometheus.py b/homeassistant/components/prometheus.py index f244bcdd740..0396cafd4ff 100644 --- a/homeassistant/components/prometheus.py +++ b/homeassistant/components/prometheus.py @@ -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)