Move imports to top for webostv (#29102)
This commit is contained in:
parent
42ce5e8b07
commit
d0c47dfee2
2 changed files with 7 additions and 13 deletions
|
@ -2,13 +2,15 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from urllib.parse import urlparse
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from pylgtv import PyLGTVPairException, WebOsClient
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
from websockets.exceptions import ConnectionClosed
|
||||||
|
|
||||||
from homeassistant import util
|
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 (
|
from homeassistant.components.media_player.const import (
|
||||||
MEDIA_TYPE_CHANNEL,
|
MEDIA_TYPE_CHANNEL,
|
||||||
SUPPORT_NEXT_TRACK,
|
SUPPORT_NEXT_TRACK,
|
||||||
|
@ -108,9 +110,6 @@ def setup_tv(
|
||||||
host, name, customize, config, timeout, hass, add_entities, turn_on_action
|
host, name, customize, config, timeout, hass, add_entities, turn_on_action
|
||||||
):
|
):
|
||||||
"""Set up a LG WebOS TV based on host parameter."""
|
"""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)
|
client = WebOsClient(host, config, timeout)
|
||||||
|
|
||||||
|
@ -185,7 +184,6 @@ class LgWebOSDevice(MediaPlayerDevice):
|
||||||
|
|
||||||
def __init__(self, host, name, customize, config, timeout, hass, on_action):
|
def __init__(self, host, name, customize, config, timeout, hass, on_action):
|
||||||
"""Initialize the webos device."""
|
"""Initialize the webos device."""
|
||||||
from pylgtv import WebOsClient
|
|
||||||
|
|
||||||
self._client = WebOsClient(host, config, timeout)
|
self._client = WebOsClient(host, config, timeout)
|
||||||
self._on_script = Script(hass, on_action) if on_action else None
|
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)
|
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Retrieve the latest data."""
|
"""Retrieve the latest data."""
|
||||||
from websockets.exceptions import ConnectionClosed
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
current_input = self._client.get_input()
|
current_input = self._client.get_input()
|
||||||
|
@ -331,7 +328,6 @@ class LgWebOSDevice(MediaPlayerDevice):
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
"""Turn off media player."""
|
"""Turn off media player."""
|
||||||
from websockets.exceptions import ConnectionClosed
|
|
||||||
|
|
||||||
self._state = STATE_OFF
|
self._state = STATE_OFF
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
"""Support for LG WebOS TV notification service."""
|
"""Support for LG WebOS TV notification service."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pylgtv import PyLGTVPairException, WebOsClient
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_DATA,
|
ATTR_DATA,
|
||||||
BaseNotificationService,
|
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
|
BaseNotificationService,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_FILENAME, CONF_HOST, CONF_ICON
|
from homeassistant.const import CONF_FILENAME, CONF_HOST, CONF_ICON
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -26,8 +27,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
|
|
||||||
def get_service(hass, config, discovery_info=None):
|
def get_service(hass, config, discovery_info=None):
|
||||||
"""Return the notify service."""
|
"""Return the notify service."""
|
||||||
from pylgtv import WebOsClient
|
|
||||||
from pylgtv import PyLGTVPairException
|
|
||||||
|
|
||||||
path = hass.config.path(config.get(CONF_FILENAME))
|
path = hass.config.path(config.get(CONF_FILENAME))
|
||||||
client = WebOsClient(config.get(CONF_HOST), key_file_path=path, timeout_connect=8)
|
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):
|
def send_message(self, message="", **kwargs):
|
||||||
"""Send a message to the tv."""
|
"""Send a message to the tv."""
|
||||||
from pylgtv import PyLGTVPairException
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = kwargs.get(ATTR_DATA)
|
data = kwargs.get(ATTR_DATA)
|
||||||
|
|
Loading…
Add table
Reference in a new issue