From 1e727f339fd3328b7930a2700dc9f6ffd6423a77 Mon Sep 17 00:00:00 2001 From: Brig Lamoreaux Date: Fri, 18 Oct 2019 20:58:07 -0700 Subject: [PATCH] Move imports in harmony component (#27904) --- homeassistant/components/harmony/remote.py | 27 ++++++---------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/harmony/remote.py b/homeassistant/components/harmony/remote.py index b78f276bf28..118af7fe34a 100644 --- a/homeassistant/components/harmony/remote.py +++ b/homeassistant/components/harmony/remote.py @@ -3,6 +3,12 @@ import asyncio import json import logging +import aioharmony.exceptions as aioexc +from aioharmony.harmonyapi import ( + ClientCallbackType, + HarmonyAPI as HarmonyClient, + SendCommandDevice, +) import voluptuous as vol from homeassistant.components import remote @@ -23,8 +29,8 @@ from homeassistant.const import ( CONF_PORT, EVENT_HOMEASSISTANT_STOP, ) -import homeassistant.helpers.config_validation as cv from homeassistant.exceptions import PlatformNotReady +import homeassistant.helpers.config_validation as cv from homeassistant.util import slugify _LOGGER = logging.getLogger(__name__) @@ -165,8 +171,6 @@ class HarmonyRemote(remote.RemoteDevice): def __init__(self, name, host, port, activity, out_path, delay_secs): """Initialize HarmonyRemote class.""" - from aioharmony.harmonyapi import HarmonyAPI as HarmonyClient - self._name = name self.host = host self.port = port @@ -180,8 +184,6 @@ class HarmonyRemote(remote.RemoteDevice): async def async_added_to_hass(self): """Complete the initialization.""" - from aioharmony.harmonyapi import ClientCallbackType - _LOGGER.debug("%s: Harmony Hub added", self._name) # Register the callbacks self._client.callbacks = ClientCallbackType( @@ -195,8 +197,6 @@ class HarmonyRemote(remote.RemoteDevice): # activity await self.new_config() - import aioharmony.exceptions as aioexc - async def shutdown(_): """Close connection on shutdown.""" _LOGGER.debug("%s: Closing Harmony Hub", self._name) @@ -234,8 +234,6 @@ class HarmonyRemote(remote.RemoteDevice): async def connect(self): """Connect to the Harmony HUB.""" - import aioharmony.exceptions as aioexc - _LOGGER.debug("%s: Connecting", self._name) try: if not await self._client.connect(): @@ -284,8 +282,6 @@ class HarmonyRemote(remote.RemoteDevice): async def async_turn_on(self, **kwargs): """Start an activity from the Harmony device.""" - import aioharmony.exceptions as aioexc - _LOGGER.debug("%s: Turn On", self.name) activity = kwargs.get(ATTR_ACTIVITY, self._default_activity) @@ -314,8 +310,6 @@ class HarmonyRemote(remote.RemoteDevice): async def async_turn_off(self, **kwargs): """Start the PowerOff activity.""" - import aioharmony.exceptions as aioexc - _LOGGER.debug("%s: Turn Off", self.name) try: await self._client.power_off() @@ -325,9 +319,6 @@ class HarmonyRemote(remote.RemoteDevice): # pylint: disable=arguments-differ async def async_send_command(self, command, **kwargs): """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) device = kwargs.get(ATTR_DEVICE) if device is None: @@ -390,8 +381,6 @@ class HarmonyRemote(remote.RemoteDevice): async def change_channel(self, channel): """Change the channel using Harmony remote.""" - import aioharmony.exceptions as aioexc - _LOGGER.debug("%s: Changing channel to %s", self.name, channel) try: await self._client.change_channel(channel) @@ -400,8 +389,6 @@ class HarmonyRemote(remote.RemoteDevice): async def sync(self): """Sync the Harmony device with the web service.""" - import aioharmony.exceptions as aioexc - _LOGGER.debug("%s: Syncing hub with Harmony cloud", self.name) try: await self._client.sync()