Add timeout to requests (#4398)

pull/3766/merge
Fabian Affolter 2016-11-16 06:02:17 +01:00 committed by Paulus Schoutsen
parent c6f5a5443f
commit 5d8a465c18
1 changed files with 12 additions and 8 deletions

View File

@ -26,8 +26,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def get_service(hass, config):
"""Get the NMA notification service."""
response = requests.get(_RESOURCE + 'verify',
params={"apikey": config[CONF_API_KEY]})
parameters = {
'apikey': config[CONF_API_KEY],
}
response = requests.get(
'{}{}'.format(_RESOURCE, 'verify'), params=parameters, timeout=5)
tree = ET.fromstring(response.content)
if tree[0].tag == 'error':
@ -47,14 +50,15 @@ class NmaNotificationService(BaseNotificationService):
def send_message(self, message="", **kwargs):
"""Send a message to a user."""
data = {
"apikey": self._api_key,
"application": 'home-assistant',
"event": kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT),
"description": message,
"priority": 0,
'apikey': self._api_key,
'application': 'home-assistant',
'event': kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT),
'description': message,
'priority': 0,
}
response = requests.get(_RESOURCE + 'notify', params=data)
response = requests.get(
'{}{}'.format(_RESOURCE, 'notify'), params=data, timeout=5)
tree = ET.fromstring(response.content)
if tree[0].tag == 'error':