Move imports to top for webostv (#29102)

This commit is contained in:
springstan 2019-11-26 18:49:14 +01:00 committed by Paulus Schoutsen
parent 42ce5e8b07
commit d0c47dfee2
2 changed files with 7 additions and 13 deletions

View file

@ -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:

View file

@ -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)