mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Add timeout to requests (#4398)
This commit is contained in:
parent
c6f5a5443f
commit
5d8a465c18
@ -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':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user