move imports to top-level (#27630)

This commit is contained in:
Malte Franken 2019-10-14 19:56:40 +11:00 committed by cgtobi
parent b7023a96a3
commit 1cae6e664c

View file

@ -1,7 +1,9 @@
"""Pushover platform for notify component.""" """Pushover platform for notify component."""
import logging import logging
import requests
import voluptuous as vol import voluptuous as vol
from pushover import InitError, Client, RequestError
from homeassistant.const import CONF_API_KEY from homeassistant.const import CONF_API_KEY
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -28,8 +30,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def get_service(hass, config, discovery_info=None): def get_service(hass, config, discovery_info=None):
"""Get the Pushover notification service.""" """Get the Pushover notification service."""
from pushover import InitError
try: try:
return PushoverNotificationService( return PushoverNotificationService(
hass, config[CONF_USER_KEY], config[CONF_API_KEY] hass, config[CONF_USER_KEY], config[CONF_API_KEY]
@ -44,8 +44,6 @@ class PushoverNotificationService(BaseNotificationService):
def __init__(self, hass, user_key, api_token): def __init__(self, hass, user_key, api_token):
"""Initialize the service.""" """Initialize the service."""
from pushover import Client
self._hass = hass self._hass = hass
self._user_key = user_key self._user_key = user_key
self._api_token = api_token self._api_token = api_token
@ -53,8 +51,6 @@ class PushoverNotificationService(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."""
from pushover import RequestError
# Make a copy and use empty dict if necessary # Make a copy and use empty dict if necessary
data = dict(kwargs.get(ATTR_DATA) or {}) data = dict(kwargs.get(ATTR_DATA) or {})
@ -65,8 +61,6 @@ class PushoverNotificationService(BaseNotificationService):
# If attachment is a URL, use requests to open it as a stream. # If attachment is a URL, use requests to open it as a stream.
if data[ATTR_ATTACHMENT].startswith("http"): if data[ATTR_ATTACHMENT].startswith("http"):
try: try:
import requests
response = requests.get( response = requests.get(
data[ATTR_ATTACHMENT], stream=True, timeout=5 data[ATTR_ATTACHMENT], stream=True, timeout=5
) )