forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config_flow to shopping_list (home-assistant#32388)
* Add config_flow to shopping_list * Fix pylint unused import error * Use _abort_if_unique_id_configured * Remove SHOPPING_LIST const * Use const.py for DOMAIN and CONF_TYPE * Fix tests * Remove unchanged variable _errors * Revert CONF_TYPE (wrong usage) * Use consts in test * Remove import check * Remove data={} * Remove parameters and default values * Re-add data={}, because it's needed * Unique ID checks and reverts for default parameters * remove pylint comment * Remove block till done * Address change requests * Update homeassistant/components/shopping_list/strings.json Co-Authored-By: Quentame <[email protected]> * Update homeassistant/components/shopping_list/strings.json Co-Authored-By: Quentame <[email protected]> * Update tests/components/shopping_list/test_config_flow.py Co-Authored-By: Quentame <[email protected]> * Update tests/components/shopping_list/test_config_flow.py Co-Authored-By: Quentame <[email protected]> * Update tests/components/shopping_list/test_config_flow.py Co-Authored-By: Quentame <[email protected]> * Update tests/components/shopping_list/test_config_flow.py Co-Authored-By: Quentame <[email protected]> * Only test config_flow * Generate translations * Move data to end * @asyncio.coroutine --> async def, yield from --> await * @asyncio.coroutine --> async def, yield from --> await (tests) * Remove init in config flow * remove if not hass.config_entries.async_entries(DOMAIN) * Add DOMAIN not in config * Fix tests * Update homeassistant/components/shopping_list/config_flow.py Co-Authored-By: Paulus Schoutsen <[email protected]> * Fix tests * Update homeassistant/components/shopping_list/__init__.py Co-Authored-By: Martin Hjelmare <[email protected]> Co-authored-by: Quentame <[email protected]> Co-authored-by: Paulus Schoutsen <[email protected]> Co-authored-by: Martin Hjelmare <[email protected]>
- Loading branch information
1 parent
e1cc2ac
commit 8f2567f
Showing
10 changed files
with
163 additions
and
65 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
homeassistant/components/shopping_list/.translations/en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"config": { | ||
"abort": { | ||
"already_configured": "The shopping list is already configured." | ||
}, | ||
"step": { | ||
"user": { | ||
"description": "Do you want to configure the shopping list?", | ||
"title": "Shopping List" | ||
} | ||
}, | ||
"title": "Shopping List" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Config flow to configure ShoppingList component.""" | ||
from homeassistant import config_entries | ||
|
||
from .const import DOMAIN | ||
|
||
|
||
class ShoppingListFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): | ||
"""Config flow for ShoppingList component.""" | ||
|
||
VERSION = 1 | ||
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH | ||
|
||
async def async_step_user(self, user_input=None): | ||
"""Handle a flow initialized by the user.""" | ||
# Check if already configured | ||
await self.async_set_unique_id(DOMAIN) | ||
self._abort_if_unique_id_configured() | ||
|
||
if user_input is not None: | ||
return self.async_create_entry(title="Shopping List", data=user_input) | ||
|
||
return self.async_show_form(step_id="user") | ||
|
||
async_step_import = async_step_user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"""All constants related to the shopping list component.""" | ||
DOMAIN = "shopping_list" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"config": { | ||
"title": "Shopping List", | ||
"step": { | ||
"user": { | ||
"title": "Shopping List", | ||
"description": "Do you want to configure the shopping list?" | ||
} | ||
}, | ||
"abort": { | ||
"already_configured": "The shopping list is already configured." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ | |
"samsungtv", | ||
"sense", | ||
"sentry", | ||
"shopping_list", | ||
"simplisafe", | ||
"smartthings", | ||
"smhi", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Test config flow.""" | ||
|
||
from homeassistant import data_entry_flow | ||
from homeassistant.components.shopping_list.const import DOMAIN | ||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER | ||
|
||
|
||
async def test_import(hass): | ||
"""Test entry will be imported.""" | ||
|
||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": SOURCE_IMPORT}, data={} | ||
) | ||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY | ||
|
||
|
||
async def test_user(hass): | ||
"""Test we can start a config flow.""" | ||
|
||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": SOURCE_USER} | ||
) | ||
|
||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM | ||
assert result["step_id"] == "user" | ||
|
||
|
||
async def test_user_confirm(hass): | ||
"""Test we can finish a config flow.""" | ||
|
||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": SOURCE_USER}, data={} | ||
) | ||
|
||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY | ||
assert result["result"].data == {} |
Oops, something went wrong.