Verify withings config (#26698)
This commit is contained in:
parent
46a55ed723
commit
ef9b3321c1
3 changed files with 19 additions and 26 deletions
|
@ -88,7 +88,10 @@ class WithingsFlowHandler(config_entries.ConfigFlow):
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Create an entry for selecting a profile."""
|
"""Create an entry for selecting a profile."""
|
||||||
flow = self.hass.data.get(DATA_FLOW_IMPL, {})
|
flow = self.hass.data.get(DATA_FLOW_IMPL)
|
||||||
|
|
||||||
|
if not flow:
|
||||||
|
return self.async_abort(reason="no_flows")
|
||||||
|
|
||||||
if user_input:
|
if user_input:
|
||||||
return await self.async_step_auth(user_input)
|
return await self.async_step_auth(user_input)
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
},
|
},
|
||||||
"create_entry": {
|
"create_entry": {
|
||||||
"default": "Successfully authenticated with Withings for the selected profile."
|
"default": "Successfully authenticated with Withings for the selected profile."
|
||||||
|
},
|
||||||
|
"abort": {
|
||||||
|
"no_flows": "You need to configure Withings before being able to authenticate with it. Please read the documentation."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,9 +3,7 @@ from aiohttp.web_request import BaseRequest
|
||||||
from asynctest import CoroutineMock, MagicMock
|
from asynctest import CoroutineMock, MagicMock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import setup, data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
import homeassistant.components.api as api
|
|
||||||
import homeassistant.components.http as http
|
|
||||||
from homeassistant.components.withings import const
|
from homeassistant.components.withings import const
|
||||||
from homeassistant.components.withings.config_flow import (
|
from homeassistant.components.withings.config_flow import (
|
||||||
register_flow_implementation,
|
register_flow_implementation,
|
||||||
|
@ -24,27 +22,6 @@ def flow_handler_fixture(hass: HomeAssistantType):
|
||||||
return flow_handler
|
return flow_handler
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="setup_hass")
|
|
||||||
async def setup_hass_fixture(hass: HomeAssistantType):
|
|
||||||
"""Provide hass instance."""
|
|
||||||
config = {
|
|
||||||
http.DOMAIN: {},
|
|
||||||
api.DOMAIN: {"base_url": "http://localhost/"},
|
|
||||||
const.DOMAIN: {
|
|
||||||
const.CLIENT_ID: "my_client_id",
|
|
||||||
const.CLIENT_SECRET: "my_secret",
|
|
||||||
const.PROFILES: ["Person 1", "Person 2"],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
hass.data = {}
|
|
||||||
|
|
||||||
await setup.async_setup_component(hass, "http", config)
|
|
||||||
await setup.async_setup_component(hass, "api", config)
|
|
||||||
|
|
||||||
return hass
|
|
||||||
|
|
||||||
|
|
||||||
def test_flow_handler_init(flow_handler: WithingsFlowHandler):
|
def test_flow_handler_init(flow_handler: WithingsFlowHandler):
|
||||||
"""Test the init of the flow handler."""
|
"""Test the init of the flow handler."""
|
||||||
assert not flow_handler.flow_profile
|
assert not flow_handler.flow_profile
|
||||||
|
@ -173,3 +150,13 @@ async def test_auth_callback_view_get(hass: HomeAssistantType):
|
||||||
"my_flow_id", {const.PROFILE: "my_profile", const.CODE: "my_code"}
|
"my_flow_id", {const.PROFILE: "my_profile", const.CODE: "my_code"}
|
||||||
)
|
)
|
||||||
hass.config_entries.flow.async_configure.reset_mock()
|
hass.config_entries.flow.async_configure.reset_mock()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_init_without_config(hass):
|
||||||
|
"""Try initializin a configg flow without it being configured."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
"withings", context={"source": "user"}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == "abort"
|
||||||
|
assert result["reason"] == "no_flows"
|
||||||
|
|
Loading…
Add table
Reference in a new issue