mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Merge branch 'pr/780' into dev
This commit is contained in:
commit
e7b1682a4e
@ -47,15 +47,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
response = requests.post(resource, data=payload, timeout=10,
|
response = requests.post(resource, data=payload, timeout=10,
|
||||||
verify=verify_ssl)
|
verify=verify_ssl)
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
_LOGGER.error('Response status is "%s"', response.status_code)
|
_LOGGER.error("Response status is '%s'", response.status_code)
|
||||||
return False
|
return False
|
||||||
except requests.exceptions.MissingSchema:
|
except requests.exceptions.MissingSchema:
|
||||||
_LOGGER.error('Missing resource or schema in configuration. '
|
_LOGGER.error("Missing resource or schema in configuration. "
|
||||||
'Add http:// to your URL.')
|
"Add http:// or https:// to your URL")
|
||||||
return False
|
return False
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.error('No route to resource/endpoint: %s',
|
_LOGGER.error('No route to resource/endpoint: %s', resource)
|
||||||
resource)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if use_get:
|
if use_get:
|
||||||
|
@ -10,7 +10,7 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
import requests
|
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.util import template, Throttle
|
||||||
from homeassistant.helpers.entity import Entity
|
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,
|
response = requests.post(resource, data=payload, timeout=10,
|
||||||
verify=verify_ssl)
|
verify=verify_ssl)
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
_LOGGER.error('Response status is "%s"', response.status_code)
|
_LOGGER.error("Response status is '%s'", response.status_code)
|
||||||
return False
|
return False
|
||||||
except requests.exceptions.MissingSchema:
|
except requests.exceptions.MissingSchema:
|
||||||
_LOGGER.error('Missing resource or schema in configuration. '
|
_LOGGER.error("Missing resource or schema in configuration. "
|
||||||
'Add http:// to your URL.')
|
"Add http:// or https:// to your URL")
|
||||||
return False
|
return False
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.error('No route to resource/endpoint. '
|
_LOGGER.error("No route to resource/endpoint: %s", resource)
|
||||||
'Please check the URL in the configuration file.')
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if use_get:
|
if use_get:
|
||||||
@ -78,7 +77,7 @@ class RestSensor(Entity):
|
|||||||
self._hass = hass
|
self._hass = hass
|
||||||
self.rest = rest
|
self.rest = rest
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = 'n/a'
|
self._state = STATE_UNKNOWN
|
||||||
self._unit_of_measurement = unit_of_measurement
|
self._unit_of_measurement = unit_of_measurement
|
||||||
self._value_template = value_template
|
self._value_template = value_template
|
||||||
self.update()
|
self.update()
|
||||||
@ -108,7 +107,7 @@ class RestSensor(Entity):
|
|||||||
else:
|
else:
|
||||||
if self._value_template is not None:
|
if self._value_template is not None:
|
||||||
value = template.render_with_possible_json_value(
|
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
|
self._state = value
|
||||||
|
|
||||||
|
|
||||||
@ -131,8 +130,8 @@ class RestDataGet(object):
|
|||||||
del self.data['error']
|
del self.data['error']
|
||||||
self.data = response.text
|
self.data = response.text
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.error("No route to resource/endpoint.")
|
_LOGGER.error("No route to resource/endpoint: %s", self._resource)
|
||||||
self.data['error'] = 'N/A'
|
self.data['error'] = STATE_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
@ -155,5 +154,5 @@ class RestDataPost(object):
|
|||||||
del self.data['error']
|
del self.data['error']
|
||||||
self.data = response.text
|
self.data = response.text
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.error("No route to resource/endpoint.")
|
_LOGGER.error("No route to resource/endpoint: %s", self._resource)
|
||||||
self.data['error'] = 'N/A'
|
self.data['error'] = STATE_UNKNOWN
|
||||||
|
@ -18,7 +18,7 @@ DEFAULT_BODY_ON = "ON"
|
|||||||
DEFAULT_BODY_OFF = "OFF"
|
DEFAULT_BODY_OFF = "OFF"
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument,
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Get REST switch. """
|
""" Get REST switch. """
|
||||||
|
|
||||||
@ -32,11 +32,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
requests.get(resource, timeout=10)
|
requests.get(resource, timeout=10)
|
||||||
except requests.exceptions.MissingSchema:
|
except requests.exceptions.MissingSchema:
|
||||||
_LOGGER.error("Missing resource or schema in configuration. "
|
_LOGGER.error("Missing resource or schema in configuration. "
|
||||||
"Add http:// to your URL.")
|
"Add http:// or https:// to your URL")
|
||||||
return False
|
return False
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.error("No route to resource/endpoint. "
|
_LOGGER.error("No route to resource/endpoint: %s", resource)
|
||||||
"Please check the IP address in the configuration file.")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
add_devices_callback([RestSwitch(
|
add_devices_callback([RestSwitch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user