mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Move imports to top for xiaomi_tv (#29073)
This commit is contained in:
parent
c95a01ce3a
commit
3203cba01f
@ -2,6 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
import pymitv
|
||||||
|
|
||||||
from homeassistant.components.media_player import MediaPlayerDevice, PLATFORM_SCHEMA
|
from homeassistant.components.media_player import MediaPlayerDevice, PLATFORM_SCHEMA
|
||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
@ -29,7 +30,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Xiaomi TV platform."""
|
"""Set up the Xiaomi TV platform."""
|
||||||
from pymitv import Discover
|
|
||||||
|
|
||||||
# If a hostname is set. Discovery is skipped.
|
# If a hostname is set. Discovery is skipped.
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
@ -37,14 +37,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
if host is not None:
|
if host is not None:
|
||||||
# Check if there's a valid TV at the IP address.
|
# Check if there's a valid TV at the IP address.
|
||||||
if not Discover().check_ip(host):
|
if not pymitv.Discover().check_ip(host):
|
||||||
_LOGGER.error("Could not find Xiaomi TV with specified IP: %s", host)
|
_LOGGER.error("Could not find Xiaomi TV with specified IP: %s", host)
|
||||||
else:
|
else:
|
||||||
# Register TV with Home Assistant.
|
# Register TV with Home Assistant.
|
||||||
add_entities([XiaomiTV(host, name)])
|
add_entities([XiaomiTV(host, name)])
|
||||||
else:
|
else:
|
||||||
# Otherwise, discover TVs on network.
|
# Otherwise, discover TVs on network.
|
||||||
add_entities(XiaomiTV(tv, DEFAULT_NAME) for tv in Discover().scan())
|
add_entities(XiaomiTV(tv, DEFAULT_NAME) for tv in pymitv.Discover().scan())
|
||||||
|
|
||||||
|
|
||||||
class XiaomiTV(MediaPlayerDevice):
|
class XiaomiTV(MediaPlayerDevice):
|
||||||
@ -52,11 +52,9 @@ class XiaomiTV(MediaPlayerDevice):
|
|||||||
|
|
||||||
def __init__(self, ip, name):
|
def __init__(self, ip, name):
|
||||||
"""Receive IP address and name to construct class."""
|
"""Receive IP address and name to construct class."""
|
||||||
# Import pymitv library.
|
|
||||||
from pymitv import TV
|
|
||||||
|
|
||||||
# Initialize the Xiaomi TV.
|
# Initialize the Xiaomi TV.
|
||||||
self._tv = TV(ip)
|
self._tv = pymitv.TV(ip)
|
||||||
# Default name value, only to be overridden by user.
|
# Default name value, only to be overridden by user.
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = STATE_OFF
|
self._state = STATE_OFF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user