Add timeout to requests (#4398)

This commit is contained in:
Fabian Affolter 2016-11-16 06:02:17 +01:00 committed by Paulus Schoutsen
parent c6f5a5443f
commit 5d8a465c18

View File

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