move songpal imports to top (#27402)

* move songpal imports to top

* Update media_player.py
This commit is contained in:
Teemu R 2019-10-10 22:53:05 +03:00 committed by Paulus Schoutsen
parent ed3516186b
commit 4b8a35dffb

View File

@ -4,6 +4,14 @@ import logging
from collections import OrderedDict from collections import OrderedDict
import voluptuous as vol import voluptuous as vol
from songpal import (
Device,
SongpalException,
VolumeChange,
ContentChange,
PowerChange,
ConnectChange,
)
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 (
@ -60,8 +68,6 @@ SET_SOUND_SCHEMA = vol.Schema(
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Songpal platform.""" """Set up the Songpal platform."""
from songpal import SongpalException
if PLATFORM not in hass.data: if PLATFORM not in hass.data:
hass.data[PLATFORM] = {} hass.data[PLATFORM] = {}
@ -117,8 +123,6 @@ class SongpalDevice(MediaPlayerDevice):
def __init__(self, name, endpoint, poll=False): def __init__(self, name, endpoint, poll=False):
"""Init.""" """Init."""
from songpal import Device
self._name = name self._name = name
self._endpoint = endpoint self._endpoint = endpoint
self._poll = poll self._poll = poll
@ -151,7 +155,6 @@ class SongpalDevice(MediaPlayerDevice):
async def async_activate_websocket(self): async def async_activate_websocket(self):
"""Activate websocket for listening if wanted.""" """Activate websocket for listening if wanted."""
_LOGGER.info("Activating websocket connection..") _LOGGER.info("Activating websocket connection..")
from songpal import VolumeChange, ContentChange, PowerChange, ConnectChange
async def _volume_changed(volume: VolumeChange): async def _volume_changed(volume: VolumeChange):
_LOGGER.debug("Volume changed: %s", volume) _LOGGER.debug("Volume changed: %s", volume)
@ -230,8 +233,6 @@ class SongpalDevice(MediaPlayerDevice):
async def async_update(self): async def async_update(self):
"""Fetch updates from the device.""" """Fetch updates from the device."""
from songpal import SongpalException
try: try:
volumes = await self.dev.get_volume_information() volumes = await self.dev.get_volume_information()
if not volumes: if not volumes: