Move imports to top for openuv (#29541)

* Move imports to top for openuv

* Renamed mock_pyopenuv_ to MockClient in test_config_flow
This commit is contained in:
springstan 2019-12-06 22:13:43 +01:00 committed by Aaron Bach
parent 1ee8057662
commit 23fb364076
3 changed files with 10 additions and 12 deletions

View file

@ -1,7 +1,9 @@
"""Support for UV data from openuv.io.""" """Support for UV data from openuv.io."""
import logging
import asyncio import asyncio
import logging
from pyopenuv import Client
from pyopenuv.errors import OpenUvError
import voluptuous as vol import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT 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): async def async_setup_entry(hass, config_entry):
"""Set up OpenUV as 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) _verify_domain_control = verify_domain_control(hass, DOMAIN)
@ -255,7 +255,6 @@ class OpenUV:
async def async_update_protection_data(self): async def async_update_protection_data(self):
"""Update binary sensor (protection window) data.""" """Update binary sensor (protection window) data."""
from pyopenuv.errors import OpenUvError
if TYPE_PROTECTION_WINDOW in self.binary_sensor_conditions: if TYPE_PROTECTION_WINDOW in self.binary_sensor_conditions:
try: try:
@ -268,7 +267,6 @@ class OpenUV:
async def async_update_uv_index_data(self): async def async_update_uv_index_data(self):
"""Update sensor (uv index, etc) data.""" """Update sensor (uv index, etc) data."""
from pyopenuv.errors import OpenUvError
if any(c in self.sensor_conditions for c in SENSORS): if any(c in self.sensor_conditions for c in SENSORS):
try: try:

View file

@ -1,5 +1,6 @@
"""Config flow to configure the OpenUV component.""" """Config flow to configure the OpenUV component."""
from pyopenuv import Client
from pyopenuv.errors import OpenUvError
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
@ -59,8 +60,6 @@ class OpenUvFlowHandler(config_entries.ConfigFlow):
async def async_step_user(self, user_input=None): async def async_step_user(self, user_input=None):
"""Handle the start of the config flow.""" """Handle the start of the config flow."""
from pyopenuv import Client
from pyopenuv.errors import OpenUvError
if not user_input: if not user_input:
return await self._show_form() return await self._show_form()

View file

@ -1,6 +1,7 @@
"""Define tests for the OpenUV config flow.""" """Define tests for the OpenUV config flow."""
import pytest import pytest
from pyopenuv.errors import OpenUvError from pyopenuv.errors import OpenUvError
from unittest.mock import patch
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components.openuv import DOMAIN, config_flow from homeassistant.components.openuv import DOMAIN, config_flow
@ -11,7 +12,7 @@ from homeassistant.const import (
CONF_LONGITUDE, CONF_LONGITUDE,
) )
from tests.common import MockConfigEntry, MockDependency, mock_coro from tests.common import MockConfigEntry, mock_coro
@pytest.fixture @pytest.fixture
@ -23,9 +24,9 @@ def uv_index_response():
@pytest.fixture @pytest.fixture
def mock_pyopenuv(uv_index_response): def mock_pyopenuv(uv_index_response):
"""Mock the pyopenuv library.""" """Mock the pyopenuv library."""
with MockDependency("pyopenuv") as mock_pyopenuv_: with patch("homeassistant.components.openuv.config_flow.Client") as MockClient:
mock_pyopenuv_.Client().uv_index.return_value = uv_index_response MockClient().uv_index.return_value = uv_index_response
yield mock_pyopenuv_ yield MockClient
async def test_duplicate_error(hass): async def test_duplicate_error(hass):