From d0c47dfee25e74bec42c4913413e061df4fd19c1 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Tue, 26 Nov 2019 18:49:14 +0100 Subject: [PATCH] Move imports to top for webostv (#29102) --- homeassistant/components/webostv/media_player.py | 12 ++++-------- homeassistant/components/webostv/notify.py | 8 +++----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index 913d193845f..3bf0011907d 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -2,13 +2,15 @@ import asyncio from datetime import timedelta import logging -from urllib.parse import urlparse from typing import Dict +from urllib.parse import urlparse +from pylgtv import PyLGTVPairException, WebOsClient import voluptuous as vol +from websockets.exceptions import ConnectionClosed from homeassistant import util -from homeassistant.components.media_player import MediaPlayerDevice, PLATFORM_SCHEMA +from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerDevice from homeassistant.components.media_player.const import ( MEDIA_TYPE_CHANNEL, SUPPORT_NEXT_TRACK, @@ -108,9 +110,6 @@ def setup_tv( host, name, customize, config, timeout, hass, add_entities, turn_on_action ): """Set up a LG WebOS TV based on host parameter.""" - from pylgtv import WebOsClient - from pylgtv import PyLGTVPairException - from websockets.exceptions import ConnectionClosed client = WebOsClient(host, config, timeout) @@ -185,7 +184,6 @@ class LgWebOSDevice(MediaPlayerDevice): def __init__(self, host, name, customize, config, timeout, hass, on_action): """Initialize the webos device.""" - from pylgtv import WebOsClient self._client = WebOsClient(host, config, timeout) self._on_script = Script(hass, on_action) if on_action else None @@ -208,7 +206,6 @@ class LgWebOSDevice(MediaPlayerDevice): @util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS) def update(self): """Retrieve the latest data.""" - from websockets.exceptions import ConnectionClosed try: current_input = self._client.get_input() @@ -331,7 +328,6 @@ class LgWebOSDevice(MediaPlayerDevice): def turn_off(self): """Turn off media player.""" - from websockets.exceptions import ConnectionClosed self._state = STATE_OFF try: diff --git a/homeassistant/components/webostv/notify.py b/homeassistant/components/webostv/notify.py index f96c20d49aa..f62c41e9a95 100644 --- a/homeassistant/components/webostv/notify.py +++ b/homeassistant/components/webostv/notify.py @@ -1,15 +1,16 @@ """Support for LG WebOS TV notification service.""" import logging +from pylgtv import PyLGTVPairException, WebOsClient import voluptuous as vol -import homeassistant.helpers.config_validation as cv from homeassistant.components.notify import ( ATTR_DATA, - BaseNotificationService, PLATFORM_SCHEMA, + BaseNotificationService, ) from homeassistant.const import CONF_FILENAME, CONF_HOST, CONF_ICON +import homeassistant.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) @@ -26,8 +27,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def get_service(hass, config, discovery_info=None): """Return the notify service.""" - from pylgtv import WebOsClient - from pylgtv import PyLGTVPairException path = hass.config.path(config.get(CONF_FILENAME)) client = WebOsClient(config.get(CONF_HOST), key_file_path=path, timeout_connect=8) @@ -55,7 +54,6 @@ class LgWebOSNotificationService(BaseNotificationService): def send_message(self, message="", **kwargs): """Send a message to the tv.""" - from pylgtv import PyLGTVPairException try: data = kwargs.get(ATTR_DATA)