Move imports in nissan_leaf component (#27359)

This commit is contained in:
Quentame 2019-10-10 09:21:40 +02:00 committed by Paulus Schoutsen
parent 549c79b6ce
commit 6c739f4be5

View File

@ -3,7 +3,7 @@ from datetime import datetime, timedelta
import asyncio import asyncio
import logging import logging
import sys import sys
from pycarwings2 import CarwingsError, Session
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME 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): def setup(hass, config):
"""Set up the Nissan Leaf component.""" """Set up the Nissan Leaf component."""
import pycarwings2
async def async_handle_update(service): async def async_handle_update(service):
"""Handle service to update leaf data from Nissan servers.""" """Handle service to update leaf data from Nissan servers."""
@ -148,7 +147,7 @@ def setup(hass, config):
try: try:
# This might need to be made async (somehow) causes # This might need to be made async (somehow) causes
# homeassistant to be slow to start # homeassistant to be slow to start
sess = pycarwings2.Session(username, password, region) sess = Session(username, password, region)
leaf = sess.get_leaf() leaf = sess.get_leaf()
except KeyError: except KeyError:
_LOGGER.error( _LOGGER.error(
@ -156,7 +155,7 @@ def setup(hass, config):
" do you actually have a Leaf connected to your account?" " do you actually have a Leaf connected to your account?"
) )
return False return False
except pycarwings2.CarwingsError: except CarwingsError:
_LOGGER.error( _LOGGER.error(
"An unknown error occurred while connecting to Nissan: %s", "An unknown error occurred while connecting to Nissan: %s",
sys.exc_info()[0], sys.exc_info()[0],
@ -274,7 +273,6 @@ class LeafDataStore:
async def async_refresh_data(self, now): async def async_refresh_data(self, now):
"""Refresh the leaf data and update the datastore.""" """Refresh the leaf data and update the datastore."""
from pycarwings2 import CarwingsError
if self.request_in_progress: if self.request_in_progress:
_LOGGER.debug("Refresh currently in progress for %s", self.leaf.nickname) _LOGGER.debug("Refresh currently in progress for %s", self.leaf.nickname)
@ -339,7 +337,6 @@ class LeafDataStore:
async def async_get_battery(self): async def async_get_battery(self):
"""Request battery update from Nissan servers.""" """Request battery update from Nissan servers."""
from pycarwings2 import CarwingsError
try: try:
# Request battery update from the car # Request battery update from the car
@ -389,7 +386,6 @@ class LeafDataStore:
async def async_get_climate(self): async def async_get_climate(self):
"""Request climate data from Nissan servers.""" """Request climate data from Nissan servers."""
from pycarwings2 import CarwingsError
try: try:
return await self.hass.async_add_executor_job( return await self.hass.async_add_executor_job(