diff --git a/homeassistant/components/openuv/__init__.py b/homeassistant/components/openuv/__init__.py index 16b7a50a4ae..167fcdcd0e6 100644 --- a/homeassistant/components/openuv/__init__.py +++ b/homeassistant/components/openuv/__init__.py @@ -1,7 +1,9 @@ """Support for UV data from openuv.io.""" -import logging import asyncio +import logging +from pyopenuv import Client +from pyopenuv.errors import OpenUvError import voluptuous as vol from homeassistant.config_entries import SOURCE_IMPORT @@ -164,8 +166,6 @@ async def async_setup(hass, config): async def async_setup_entry(hass, config_entry): """Set up OpenUV as config entry.""" - from pyopenuv import Client - from pyopenuv.errors import OpenUvError _verify_domain_control = verify_domain_control(hass, DOMAIN) @@ -255,7 +255,6 @@ class OpenUV: async def async_update_protection_data(self): """Update binary sensor (protection window) data.""" - from pyopenuv.errors import OpenUvError if TYPE_PROTECTION_WINDOW in self.binary_sensor_conditions: try: @@ -268,7 +267,6 @@ class OpenUV: async def async_update_uv_index_data(self): """Update sensor (uv index, etc) data.""" - from pyopenuv.errors import OpenUvError if any(c in self.sensor_conditions for c in SENSORS): try: diff --git a/homeassistant/components/openuv/config_flow.py b/homeassistant/components/openuv/config_flow.py index 40ec2abf2fe..7dd8ed45a79 100644 --- a/homeassistant/components/openuv/config_flow.py +++ b/homeassistant/components/openuv/config_flow.py @@ -1,5 +1,6 @@ """Config flow to configure the OpenUV component.""" - +from pyopenuv import Client +from pyopenuv.errors import OpenUvError import voluptuous as vol from homeassistant import config_entries @@ -59,8 +60,6 @@ class OpenUvFlowHandler(config_entries.ConfigFlow): async def async_step_user(self, user_input=None): """Handle the start of the config flow.""" - from pyopenuv import Client - from pyopenuv.errors import OpenUvError if not user_input: return await self._show_form() diff --git a/tests/components/openuv/test_config_flow.py b/tests/components/openuv/test_config_flow.py index c57e22e44e2..43dd5924a72 100644 --- a/tests/components/openuv/test_config_flow.py +++ b/tests/components/openuv/test_config_flow.py @@ -1,6 +1,7 @@ """Define tests for the OpenUV config flow.""" import pytest from pyopenuv.errors import OpenUvError +from unittest.mock import patch from homeassistant import data_entry_flow from homeassistant.components.openuv import DOMAIN, config_flow @@ -11,7 +12,7 @@ from homeassistant.const import ( CONF_LONGITUDE, ) -from tests.common import MockConfigEntry, MockDependency, mock_coro +from tests.common import MockConfigEntry, mock_coro @pytest.fixture @@ -23,9 +24,9 @@ def uv_index_response(): @pytest.fixture def mock_pyopenuv(uv_index_response): """Mock the pyopenuv library.""" - with MockDependency("pyopenuv") as mock_pyopenuv_: - mock_pyopenuv_.Client().uv_index.return_value = uv_index_response - yield mock_pyopenuv_ + with patch("homeassistant.components.openuv.config_flow.Client") as MockClient: + MockClient().uv_index.return_value = uv_index_response + yield MockClient async def test_duplicate_error(hass):