diff --git a/homeassistant/components/tellduslive/__init__.py b/homeassistant/components/tellduslive/__init__.py index 313699e6f1c..917b927691e 100644 --- a/homeassistant/components/tellduslive/__init__.py +++ b/homeassistant/components/tellduslive/__init__.py @@ -1,15 +1,17 @@ """Support for Telldus Live.""" import asyncio -import logging from functools import partial +import logging +from tellduslive import DIM, TURNON, UP, Session import voluptuous as vol -import homeassistant.helpers.config_validation as cv from homeassistant import config_entries from homeassistant.const import CONF_SCAN_INTERVAL +import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_call_later + from . import config_flow # noqa: F401 from .const import ( CONF_HOST, @@ -51,7 +53,6 @@ INTERVAL_TRACKER = f"{DOMAIN}_INTERVAL" async def async_setup_entry(hass, entry): """Create a tellduslive session.""" - from tellduslive import Session conf = entry.data[KEY_SESSION] @@ -159,7 +160,6 @@ class TelldusLiveClient: """Find out what type of HA component to create.""" if device.is_sensor: return "sensor" - from tellduslive import DIM, UP, TURNON if device.methods & DIM: return "light" diff --git a/homeassistant/components/tellduslive/config_flow.py b/homeassistant/components/tellduslive/config_flow.py index 19f82dd18f4..893f3b80456 100644 --- a/homeassistant/components/tellduslive/config_flow.py +++ b/homeassistant/components/tellduslive/config_flow.py @@ -4,6 +4,7 @@ import logging import os import async_timeout +from tellduslive import Session, supports_local_api import voluptuous as vol from homeassistant import config_entries @@ -43,7 +44,6 @@ class FlowHandler(config_entries.ConfigFlow): self._scan_interval = SCAN_INTERVAL def _get_auth_url(self): - from tellduslive import Session self._session = Session( public_key=PUBLIC_KEY, @@ -116,7 +116,6 @@ class FlowHandler(config_entries.ConfigFlow): async def async_step_discovery(self, user_input): """Run when a Tellstick is discovered.""" - from tellduslive import supports_local_api _LOGGER.info("Discovered tellstick device: %s", user_input) if supports_local_api(user_input[1]): diff --git a/homeassistant/components/tellduslive/entry.py b/homeassistant/components/tellduslive/entry.py index ecd428d3b15..50a219bf7a1 100644 --- a/homeassistant/components/tellduslive/entry.py +++ b/homeassistant/components/tellduslive/entry.py @@ -2,6 +2,8 @@ from datetime import datetime import logging +from tellduslive import BATTERY_LOW, BATTERY_OK, BATTERY_UNKNOWN + from homeassistant.const import ATTR_BATTERY_LEVEL, DEVICE_DEFAULT_NAME from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -91,7 +93,6 @@ class TelldusLiveEntity(Entity): @property def _battery_level(self): """Return the battery level of a device.""" - from tellduslive import BATTERY_LOW, BATTERY_UNKNOWN, BATTERY_OK if self.device.battery == BATTERY_LOW: return 1 diff --git a/tests/components/tellduslive/test_config_flow.py b/tests/components/tellduslive/test_config_flow.py index c615c8e6aea..f4972ada2c7 100644 --- a/tests/components/tellduslive/test_config_flow.py +++ b/tests/components/tellduslive/test_config_flow.py @@ -15,7 +15,7 @@ from homeassistant.components.tellduslive import ( ) from homeassistant.const import CONF_HOST -from tests.common import MockConfigEntry, MockDependency, mock_coro +from tests.common import MockConfigEntry, mock_coro def init_config_flow(hass, side_effect=None): @@ -42,13 +42,17 @@ def authorize(): @pytest.fixture def mock_tellduslive(supports_local_api, authorize): """Mock tellduslive.""" - with MockDependency("tellduslive") as mock_tellduslive_: - mock_tellduslive_.supports_local_api.return_value = supports_local_api - mock_tellduslive_.Session().authorize.return_value = authorize - mock_tellduslive_.Session().access_token = "token" - mock_tellduslive_.Session().access_token_secret = "token_secret" - mock_tellduslive_.Session().authorize_url = "https://example.com" - yield mock_tellduslive_ + with patch( + "homeassistant.components.tellduslive.config_flow.Session" + ) as Session, patch( + "homeassistant.components.tellduslive.config_flow.supports_local_api" + ) as tellduslive_supports_local_api: + tellduslive_supports_local_api.return_value = supports_local_api + Session().authorize.return_value = authorize + Session().access_token = "token" + Session().access_token_secret = "token_secret" + Session().authorize_url = "https://example.com" + yield Session, tellduslive_supports_local_api async def test_abort_if_already_setup(hass):