From 87961873892075594619a0475dd88619b9a98d5d Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 19 Dec 2015 10:06:54 +0100 Subject: [PATCH] Equalize log messages --- .../components/binary_sensor/rest.py | 11 ++++----- homeassistant/components/sensor/rest.py | 23 +++++++++---------- homeassistant/components/switch/rest.py | 7 +++--- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/binary_sensor/rest.py b/homeassistant/components/binary_sensor/rest.py index 60963988f39..bbb8c0bf47d 100644 --- a/homeassistant/components/binary_sensor/rest.py +++ b/homeassistant/components/binary_sensor/rest.py @@ -23,7 +23,7 @@ DEFAULT_METHOD = 'GET' MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60) -# pylint: disable=unused-variable +# pylint: disable=unused-variable, logging-too-many-args def setup_platform(hass, config, add_devices, discovery_info=None): """ Get the REST binary sensor. """ @@ -47,15 +47,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None): response = requests.post(resource, data=payload, timeout=10, verify=verify_ssl) if not response.ok: - _LOGGER.error('Response status is "%s"', response.status_code) + _LOGGER.error("Response status is '%s'", response.status_code) return False except requests.exceptions.MissingSchema: - _LOGGER.error('Missing resource or schema in configuration. ' - 'Add http:// to your URL.') + _LOGGER.error("Missing resource or schema in configuration. " + "Add http:// or https:// to your URL") return False except requests.exceptions.ConnectionError: - _LOGGER.error('No route to resource/endpoint: %s', - resource) + _LOGGER.error('No route to resource/endpoint: %s', resource) return False if use_get: diff --git a/homeassistant/components/sensor/rest.py b/homeassistant/components/sensor/rest.py index 4dcd036df5e..8afa5b26783 100644 --- a/homeassistant/components/sensor/rest.py +++ b/homeassistant/components/sensor/rest.py @@ -10,7 +10,7 @@ from datetime import timedelta import logging import requests -from homeassistant.const import CONF_VALUE_TEMPLATE +from homeassistant.const import (CONF_VALUE_TEMPLATE, STATE_UNKNOWN) from homeassistant.util import template, Throttle from homeassistant.helpers.entity import Entity @@ -47,15 +47,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None): response = requests.post(resource, data=payload, timeout=10, verify=verify_ssl) if not response.ok: - _LOGGER.error('Response status is "%s"', response.status_code) + _LOGGER.error("Response status is '%s'", response.status_code) return False except requests.exceptions.MissingSchema: - _LOGGER.error('Missing resource or schema in configuration. ' - 'Add http:// to your URL.') + _LOGGER.error("Missing resource or schema in configuration. " + "Add http:// or https:// to your URL") return False except requests.exceptions.ConnectionError: - _LOGGER.error('No route to resource/endpoint. ' - 'Please check the URL in the configuration file.') + _LOGGER.error("No route to resource/endpoint: %s", resource) return False if use_get: @@ -78,7 +77,7 @@ class RestSensor(Entity): self._hass = hass self.rest = rest self._name = name - self._state = 'n/a' + self._state = STATE_UNKNOWN self._unit_of_measurement = unit_of_measurement self._value_template = value_template self.update() @@ -108,7 +107,7 @@ class RestSensor(Entity): else: if self._value_template is not None: value = template.render_with_possible_json_value( - self._hass, self._value_template, value, 'N/A') + self._hass, self._value_template, value, STATE_UNKNOWN) self._state = value @@ -131,8 +130,8 @@ class RestDataGet(object): del self.data['error'] self.data = response.text except requests.exceptions.ConnectionError: - _LOGGER.error("No route to resource/endpoint.") - self.data['error'] = 'N/A' + _LOGGER.error("No route to resource/endpoint: %s", self._resource) + self.data['error'] = STATE_UNKNOWN # pylint: disable=too-few-public-methods @@ -155,5 +154,5 @@ class RestDataPost(object): del self.data['error'] self.data = response.text except requests.exceptions.ConnectionError: - _LOGGER.error("No route to resource/endpoint.") - self.data['error'] = 'N/A' + _LOGGER.error("No route to resource/endpoint: %s", self._resource) + self.data['error'] = STATE_UNKNOWN diff --git a/homeassistant/components/switch/rest.py b/homeassistant/components/switch/rest.py index 2435829637e..5c4b9b37e1e 100644 --- a/homeassistant/components/switch/rest.py +++ b/homeassistant/components/switch/rest.py @@ -18,7 +18,7 @@ DEFAULT_BODY_ON = "ON" DEFAULT_BODY_OFF = "OFF" -# pylint: disable=unused-argument +# pylint: disable=unused-argument, def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Get REST switch. """ @@ -32,11 +32,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): requests.get(resource, timeout=10) except requests.exceptions.MissingSchema: _LOGGER.error("Missing resource or schema in configuration. " - "Add http:// to your URL.") + "Add http:// or https:// to your URL") return False except requests.exceptions.ConnectionError: - _LOGGER.error("No route to resource/endpoint. " - "Please check the IP address in the configuration file.") + _LOGGER.error("No route to resource/endpoint: %s", resource) return False add_devices_callback([RestSwitch(