From 5d8a465c1890519e51b8c1c3f074bc63eea0c1fa Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 16 Nov 2016 06:02:17 +0100 Subject: [PATCH] Add timeout to requests (#4398) --- homeassistant/components/notify/nma.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/notify/nma.py b/homeassistant/components/notify/nma.py index a21a37bb323..7a05d08134f 100644 --- a/homeassistant/components/notify/nma.py +++ b/homeassistant/components/notify/nma.py @@ -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':