mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Add timeout
This commit is contained in:
parent
1ec392a494
commit
5d3e929599
@ -51,7 +51,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
resource = config.get('resource', None)
|
resource = config.get('resource', None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = get(resource)
|
response = get(resource, timeout=10)
|
||||||
except exceptions.MissingSchema:
|
except 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:// to your URL.")
|
||||||
@ -81,7 +81,8 @@ class ArestSwitch(SwitchDevice):
|
|||||||
self._pin = pin
|
self._pin = pin
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
request = get('{}/mode/{}/o'.format(self._resource, self._pin))
|
request = get('{}/mode/{}/o'.format(self._resource, self._pin),
|
||||||
|
timeout=10)
|
||||||
if request.status_code is not 200:
|
if request.status_code is not 200:
|
||||||
_LOGGER.error("Can't set mode. Is device offline?")
|
_LOGGER.error("Can't set mode. Is device offline?")
|
||||||
|
|
||||||
@ -97,19 +98,26 @@ class ArestSwitch(SwitchDevice):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turn the device on. """
|
""" Turn the device on. """
|
||||||
request = get('{}/digital/{}/1'.format(self._resource, self._pin))
|
request = get('{}/digital/{}/1'.format(self._resource, self._pin),
|
||||||
if request.status_code is not 200:
|
timeout=10)
|
||||||
_LOGGER.error("Can't turn on the pin. Is device offline?")
|
if request.status_code == 200:
|
||||||
self._state = True
|
self._state = True
|
||||||
|
else:
|
||||||
|
_LOGGER.error("Can't turn on pin %s at %s. Is device offline?",
|
||||||
|
self._resource, self._pin)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
""" Turn the device off. """
|
""" Turn the device off. """
|
||||||
request = get('{}/digital/{}/0'.format(self._resource, self._pin))
|
request = get('{}/digital/{}/0'.format(self._resource, self._pin),
|
||||||
if request.status_code is not 200:
|
timeout=10)
|
||||||
_LOGGER.error("Can't turn off the pin. Is device offline?")
|
if request.status_code == 200:
|
||||||
self._state = False
|
self._state = False
|
||||||
|
else:
|
||||||
|
_LOGGER.error("Can't turn on pin %s at %s. Is device offline?",
|
||||||
|
self._resource, self._pin)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
""" Gets the latest data from aREST API and updates the state. """
|
""" Gets the latest data from aREST API and updates the state. """
|
||||||
request = get('{}/digital/{}'.format(self._resource, self._pin))
|
request = get('{}/digital/{}'.format(self._resource, self._pin),
|
||||||
|
timeout=10)
|
||||||
self._state = request.json()['return_value'] != 0
|
self._state = request.json()['return_value'] != 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user