Move imports in nissan_leaf component (#27359)

This commit is contained in:
Quentame authored and Paulus Schoutsen committed 2019-10-10 00:21:40 -07:00
1 parent 549c79b6ce
commit 6c739f4be5
1 file changed
+3 -7
@@ -3,7 +3,7 @@ from datetime import datetime, timedelta
import asyncio
import logging
import sys
from pycarwings2 import CarwingsError, Session
import voluptuous as vol
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
@@ -95,7 +95,6 @@ START_CHARGE_LEAF_SCHEMA = vol.Schema({vol.Required(ATTR_VIN): cv.string})
def setup(hass, config):
"""Set up the Nissan Leaf component."""
import pycarwings2
async def async_handle_update(service):
"""Handle service to update leaf data from Nissan servers."""
@@ -148,7 +147,7 @@ def setup(hass, config):
try:
# This might need to be made async (somehow) causes
# homeassistant to be slow to start
sess = pycarwings2.Session(username, password, region)
sess = Session(username, password, region)
leaf = sess.get_leaf()
except KeyError:
_LOGGER.error(
@@ -156,7 +155,7 @@ def setup(hass, config):
" do you actually have a Leaf connected to your account?"
)
return False
except pycarwings2.CarwingsError:
except CarwingsError:
_LOGGER.error(
"An unknown error occurred while connecting to Nissan: %s",
sys.exc_info()[0],
@@ -274,7 +273,6 @@ class LeafDataStore:
async def async_refresh_data(self, now):
"""Refresh the leaf data and update the datastore."""
from pycarwings2 import CarwingsError
if self.request_in_progress:
_LOGGER.debug("Refresh currently in progress for %s", self.leaf.nickname)
@@ -339,7 +337,6 @@ class LeafDataStore:
async def async_get_battery(self):
"""Request battery update from Nissan servers."""
from pycarwings2 import CarwingsError
try:
# Request battery update from the car
@@ -389,7 +386,6 @@ class LeafDataStore:
async def async_get_climate(self):
"""Request climate data from Nissan servers."""
from pycarwings2 import CarwingsError
try:
return await self.hass.async_add_executor_job(