diff --git a/.coveragerc b/.coveragerc index 02cd35bcd60..81f2d17c671 100644 --- a/.coveragerc +++ b/.coveragerc @@ -934,7 +934,12 @@ omit = homeassistant/components/soma/__init__.py homeassistant/components/soma/cover.py homeassistant/components/soma/sensor.py - homeassistant/components/somfy/* + homeassistant/components/somfy/__init__.py + homeassistant/components/somfy/api.py + homeassistant/components/somfy/climate.py + homeassistant/components/somfy/cover.py + homeassistant/components/somfy/sensor.py + homeassistant/components/somfy/switch.py homeassistant/components/somfy_mylink/__init__.py homeassistant/components/somfy_mylink/cover.py homeassistant/components/sonos/* diff --git a/script/hassfest/coverage.py b/script/hassfest/coverage.py index 06e38902060..1a4b1fbf8ba 100644 --- a/script/hassfest/coverage.py +++ b/script/hassfest/coverage.py @@ -51,7 +51,6 @@ ALLOWED_IGNORE_VIOLATIONS = { ("sense", "config_flow.py"), ("sms", "config_flow.py"), ("solarlog", "config_flow.py"), - ("somfy", "config_flow.py"), ("sonos", "config_flow.py"), ("speedtestdotnet", "config_flow.py"), ("spider", "config_flow.py"), diff --git a/tests/components/somfy/test_config_flow.py b/tests/components/somfy/test_config_flow.py index 60200824c00..4e969358b2a 100644 --- a/tests/components/somfy/test_config_flow.py +++ b/tests/components/somfy/test_config_flow.py @@ -2,10 +2,8 @@ import asyncio from unittest.mock import patch -import pytest - from homeassistant import config_entries, data_entry_flow, setup -from homeassistant.components.somfy import DOMAIN, config_flow +from homeassistant.components.somfy import DOMAIN from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET from homeassistant.helpers import config_entry_oauth2_flow @@ -15,39 +13,22 @@ CLIENT_ID_VALUE = "1234" CLIENT_SECRET_VALUE = "5678" -@pytest.fixture() -async def mock_impl(hass): - """Mock implementation.""" - await setup.async_setup_component(hass, "http", {}) - - impl = config_entry_oauth2_flow.LocalOAuth2Implementation( - hass, - DOMAIN, - CLIENT_ID_VALUE, - CLIENT_SECRET_VALUE, - "https://accounts.somfy.com/oauth/oauth/v2/auth", - "https://accounts.somfy.com/oauth/oauth/v2/token", - ) - config_flow.SomfyFlowHandler.async_register_implementation(hass, impl) - return impl - - async def test_abort_if_no_configuration(hass): """Check flow abort when no configuration.""" - flow = config_flow.SomfyFlowHandler() - flow.hass = hass - result = await flow.async_step_user() + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "missing_configuration" async def test_abort_if_existing_entry(hass): """Check flow abort when an entry already exist.""" - flow = config_flow.SomfyFlowHandler() - flow.hass = hass MockConfigEntry(domain=DOMAIN).add_to_hass(hass) - result = await flow.async_step_user() + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "single_instance_allowed" @@ -63,8 +44,7 @@ async def test_full_flow( DOMAIN: { CONF_CLIENT_ID: CLIENT_ID_VALUE, CONF_CLIENT_SECRET: CLIENT_SECRET_VALUE, - }, - "http": {"base_url": "https://example.com"}, + } }, ) @@ -123,17 +103,27 @@ async def test_full_flow( assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED -async def test_abort_if_authorization_timeout( - hass, mock_impl, current_request_with_host -): +async def test_abort_if_authorization_timeout(hass, current_request_with_host): """Check Somfy authorization timeout.""" - flow = config_flow.SomfyFlowHandler() - flow.hass = hass + assert await setup.async_setup_component( + hass, + DOMAIN, + { + DOMAIN: { + CONF_CLIENT_ID: CLIENT_ID_VALUE, + CONF_CLIENT_SECRET: CLIENT_SECRET_VALUE, + } + }, + ) - with patch.object( - mock_impl, "async_generate_authorize_url", side_effect=asyncio.TimeoutError + with patch( + "homeassistant.components.somfy.config_entry_oauth2_flow." + "LocalOAuth2Implementation.async_generate_authorize_url", + side_effect=asyncio.TimeoutError, ): - result = await flow.async_step_user() + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "authorize_url_timeout"