-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Add config flow for zodiac #95447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MartinHjelmare
merged 4 commits into
home-assistant:dev
from
joostlek:zodiac_config_flow
Jun 30, 2023
Merged
Add config flow for zodiac #95447
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,31 @@ | ||
| """Config flow to configure the Zodiac integration.""" | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from homeassistant.config_entries import ConfigFlow | ||
| from homeassistant.data_entry_flow import FlowResult | ||
|
|
||
| from .const import DEFAULT_NAME, DOMAIN | ||
|
|
||
|
|
||
| class ZodiacConfigFlow(ConfigFlow, domain=DOMAIN): | ||
| """Config flow for Zodiac.""" | ||
|
|
||
| VERSION = 1 | ||
|
|
||
| async def async_step_user( | ||
| self, user_input: dict[str, Any] | None = None | ||
| ) -> FlowResult: | ||
| """Handle a flow initialized by the user.""" | ||
| if self._async_current_entries(): | ||
| return self.async_abort(reason="single_instance_allowed") | ||
|
|
||
| if user_input is not None: | ||
| return self.async_create_entry(title=DEFAULT_NAME, data={}) | ||
|
|
||
| return self.async_show_form(step_id="user") | ||
|
|
||
| async def async_step_import(self, user_input: dict[str, Any]) -> FlowResult: | ||
| """Handle import from configuration.yaml.""" | ||
| return await self.async_step_user(user_input) |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| """Constants for Zodiac.""" | ||
| DOMAIN = "zodiac" | ||
| DEFAULT_NAME = "Zodiac" | ||
|
|
||
| # Signs | ||
| SIGN_ARIES = "aries" | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -534,6 +534,7 @@ | |
| "zerproc", | ||
| "zeversolar", | ||
| "zha", | ||
| "zodiac", | ||
| "zwave_js", | ||
| "zwave_me", | ||
| ], | ||
|
|
||
This file contains hidden or 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 hidden or 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,70 @@ | ||
| """Tests for the Zodiac config flow.""" | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| from homeassistant.components.zodiac.const import DOMAIN | ||
| from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.data_entry_flow import FlowResultType | ||
|
|
||
| from tests.common import MockConfigEntry | ||
|
|
||
|
|
||
| async def test_full_user_flow(hass: HomeAssistant) -> None: | ||
| """Test the full user configuration flow.""" | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, context={"source": SOURCE_USER} | ||
| ) | ||
|
|
||
| assert result.get("type") == FlowResultType.FORM | ||
| assert result.get("step_id") == "user" | ||
|
|
||
| with patch( | ||
| "homeassistant.components.zodiac.async_setup_entry", | ||
| return_value=True, | ||
| ) as mock_setup_entry: | ||
| result = await hass.config_entries.flow.async_configure( | ||
| result["flow_id"], | ||
| user_input={}, | ||
| ) | ||
|
|
||
| assert result.get("type") == FlowResultType.CREATE_ENTRY | ||
| assert result.get("title") == "Zodiac" | ||
| assert result.get("data") == {} | ||
| assert result.get("options") == {} | ||
| assert len(mock_setup_entry.mock_calls) == 1 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("source", [SOURCE_USER, SOURCE_IMPORT]) | ||
| async def test_single_instance_allowed( | ||
| hass: HomeAssistant, | ||
| source: str, | ||
| ) -> None: | ||
| """Test we abort if already setup.""" | ||
| mock_config_entry = MockConfigEntry(domain=DOMAIN) | ||
|
|
||
| mock_config_entry.add_to_hass(hass) | ||
|
|
||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, context={"source": source} | ||
| ) | ||
|
|
||
| assert result.get("type") == FlowResultType.ABORT | ||
| assert result.get("reason") == "single_instance_allowed" | ||
|
|
||
|
|
||
| async def test_import_flow( | ||
| hass: HomeAssistant, | ||
| ) -> None: | ||
| """Test the import configuration flow.""" | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, | ||
| context={"source": SOURCE_IMPORT}, | ||
| data={}, | ||
| ) | ||
|
|
||
| assert result.get("type") == FlowResultType.CREATE_ENTRY | ||
| assert result.get("title") == "Zodiac" | ||
| assert result.get("data") == {} | ||
| assert result.get("options") == {} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.