Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion homeassistant/components/withings/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ async def async_step_import(self, user_input=None):

async def async_step_user(self, user_input=None):
"""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:
return await self.async_step_auth(user_input)
Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/withings/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
},
"create_entry": {
"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."
}
}
}
}
35 changes: 11 additions & 24 deletions tests/components/withings/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from asynctest import CoroutineMock, MagicMock
import pytest

from homeassistant import setup, data_entry_flow
import homeassistant.components.api as api
import homeassistant.components.http as http
from homeassistant import data_entry_flow
from homeassistant.components.withings import const
from homeassistant.components.withings.config_flow import (
register_flow_implementation,
Expand All @@ -24,27 +22,6 @@ def flow_handler_fixture(hass: HomeAssistantType):
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):
"""Test the init of the flow handler."""
assert not flow_handler.flow_profile
Expand Down Expand Up @@ -173,3 +150,13 @@ async def test_auth_callback_view_get(hass: HomeAssistantType):
"my_flow_id", {const.PROFILE: "my_profile", const.CODE: "my_code"}
)
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"