Move imports in harmony component (#27904)

This commit is contained in:
Brig Lamoreaux 2019-10-18 20:58:07 -07:00 committed by Paulus Schoutsen
parent 00521b5e80
commit 1e727f339f

View File

@ -3,6 +3,12 @@ import asyncio
import json import json
import logging import logging
import aioharmony.exceptions as aioexc
from aioharmony.harmonyapi import (
ClientCallbackType,
HarmonyAPI as HarmonyClient,
SendCommandDevice,
)
import voluptuous as vol import voluptuous as vol
from homeassistant.components import remote from homeassistant.components import remote
@ -23,8 +29,8 @@ from homeassistant.const import (
CONF_PORT, CONF_PORT,
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_STOP,
) )
import homeassistant.helpers.config_validation as cv
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.util import slugify from homeassistant.util import slugify
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -165,8 +171,6 @@ class HarmonyRemote(remote.RemoteDevice):
def __init__(self, name, host, port, activity, out_path, delay_secs): def __init__(self, name, host, port, activity, out_path, delay_secs):
"""Initialize HarmonyRemote class.""" """Initialize HarmonyRemote class."""
from aioharmony.harmonyapi import HarmonyAPI as HarmonyClient
self._name = name self._name = name
self.host = host self.host = host
self.port = port self.port = port
@ -180,8 +184,6 @@ class HarmonyRemote(remote.RemoteDevice):
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Complete the initialization.""" """Complete the initialization."""
from aioharmony.harmonyapi import ClientCallbackType
_LOGGER.debug("%s: Harmony Hub added", self._name) _LOGGER.debug("%s: Harmony Hub added", self._name)
# Register the callbacks # Register the callbacks
self._client.callbacks = ClientCallbackType( self._client.callbacks = ClientCallbackType(
@ -195,8 +197,6 @@ class HarmonyRemote(remote.RemoteDevice):
# activity # activity
await self.new_config() await self.new_config()
import aioharmony.exceptions as aioexc
async def shutdown(_): async def shutdown(_):
"""Close connection on shutdown.""" """Close connection on shutdown."""
_LOGGER.debug("%s: Closing Harmony Hub", self._name) _LOGGER.debug("%s: Closing Harmony Hub", self._name)
@ -234,8 +234,6 @@ class HarmonyRemote(remote.RemoteDevice):
async def connect(self): async def connect(self):
"""Connect to the Harmony HUB.""" """Connect to the Harmony HUB."""
import aioharmony.exceptions as aioexc
_LOGGER.debug("%s: Connecting", self._name) _LOGGER.debug("%s: Connecting", self._name)
try: try:
if not await self._client.connect(): if not await self._client.connect():
@ -284,8 +282,6 @@ class HarmonyRemote(remote.RemoteDevice):
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs):
"""Start an activity from the Harmony device.""" """Start an activity from the Harmony device."""
import aioharmony.exceptions as aioexc
_LOGGER.debug("%s: Turn On", self.name) _LOGGER.debug("%s: Turn On", self.name)
activity = kwargs.get(ATTR_ACTIVITY, self._default_activity) activity = kwargs.get(ATTR_ACTIVITY, self._default_activity)
@ -314,8 +310,6 @@ class HarmonyRemote(remote.RemoteDevice):
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs):
"""Start the PowerOff activity.""" """Start the PowerOff activity."""
import aioharmony.exceptions as aioexc
_LOGGER.debug("%s: Turn Off", self.name) _LOGGER.debug("%s: Turn Off", self.name)
try: try:
await self._client.power_off() await self._client.power_off()
@ -325,9 +319,6 @@ class HarmonyRemote(remote.RemoteDevice):
# pylint: disable=arguments-differ # pylint: disable=arguments-differ
async def async_send_command(self, command, **kwargs): async def async_send_command(self, command, **kwargs):
"""Send a list of commands to one device.""" """Send a list of commands to one device."""
from aioharmony.harmonyapi import SendCommandDevice
import aioharmony.exceptions as aioexc
_LOGGER.debug("%s: Send Command", self.name) _LOGGER.debug("%s: Send Command", self.name)
device = kwargs.get(ATTR_DEVICE) device = kwargs.get(ATTR_DEVICE)
if device is None: if device is None:
@ -390,8 +381,6 @@ class HarmonyRemote(remote.RemoteDevice):
async def change_channel(self, channel): async def change_channel(self, channel):
"""Change the channel using Harmony remote.""" """Change the channel using Harmony remote."""
import aioharmony.exceptions as aioexc
_LOGGER.debug("%s: Changing channel to %s", self.name, channel) _LOGGER.debug("%s: Changing channel to %s", self.name, channel)
try: try:
await self._client.change_channel(channel) await self._client.change_channel(channel)
@ -400,8 +389,6 @@ class HarmonyRemote(remote.RemoteDevice):
async def sync(self): async def sync(self):
"""Sync the Harmony device with the web service.""" """Sync the Harmony device with the web service."""
import aioharmony.exceptions as aioexc
_LOGGER.debug("%s: Syncing hub with Harmony cloud", self.name) _LOGGER.debug("%s: Syncing hub with Harmony cloud", self.name)
try: try:
await self._client.sync() await self._client.sync()