-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add config flow for simplepush
#73471
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
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0dce1fb
Add config flow for `simplepush`
engrbm87 4d1d4ab
fix warning message
engrbm87 d0fb937
Merge branch 'dev' into simplepush
engrbm87 adf7d51
fix typos
engrbm87 ffb5264
Merge branches 'simplepush' and 'simplepush' of https://github.com/en…
engrbm87 a76372d
Add importing yaml config
engrbm87 2837761
patch integration setup
engrbm87 c66f5f7
Add check for errrors raised by the library
engrbm87 acce590
fix coverage
engrbm87 647a95d
Adjust comment and logging message
MartinHjelmare 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
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 +1,42 @@ | ||
| """The simplepush component.""" | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import Platform | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers import discovery | ||
| import homeassistant.helpers.config_validation as cv | ||
| from homeassistant.helpers.typing import ConfigType | ||
|
|
||
| from .const import DATA_HASS_CONFIG, DOMAIN | ||
|
|
||
| PLATFORMS = [Platform.NOTIFY] | ||
|
|
||
| CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False) | ||
|
|
||
|
|
||
| async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: | ||
| """Set up the simplepush component.""" | ||
|
|
||
| hass.data[DATA_HASS_CONFIG] = config | ||
| return True | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| """Set up simplepush from a config entry.""" | ||
|
|
||
| hass.async_create_task( | ||
| discovery.async_load_platform( | ||
| hass, | ||
| Platform.NOTIFY, | ||
| DOMAIN, | ||
| dict(entry.data), | ||
| hass.data[DATA_HASS_CONFIG], | ||
|
MartinHjelmare marked this conversation as resolved.
|
||
| ) | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| """Unload a config entry.""" | ||
| return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
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,47 @@ | ||
| """Config flow for simplepush integration.""" | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant import config_entries | ||
| from homeassistant.const import CONF_NAME, CONF_PASSWORD | ||
| from homeassistant.data_entry_flow import FlowResult | ||
|
|
||
| from .const import ATTR_ENCRYPTED, CONF_DEVICE_KEY, CONF_SALT, DEFAULT_NAME, DOMAIN | ||
|
|
||
|
|
||
| class SimplePushFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): | ||
| """Handle a config flow for simplepush.""" | ||
|
|
||
| async def async_step_user( | ||
| self, user_input: dict[str, Any] | None = None | ||
| ) -> FlowResult: | ||
| """Handle a flow initiated by the user.""" | ||
| if user_input is not None: | ||
|
|
||
| await self.async_set_unique_id(user_input[CONF_DEVICE_KEY]) | ||
| self._abort_if_unique_id_configured() | ||
|
|
||
| self._async_abort_entries_match( | ||
| { | ||
| CONF_NAME: user_input[CONF_NAME], | ||
| } | ||
| ) | ||
| return self.async_create_entry( | ||
|
MartinHjelmare marked this conversation as resolved.
Outdated
|
||
| title=user_input[CONF_NAME], | ||
| data=user_input, | ||
| ) | ||
|
|
||
| return self.async_show_form( | ||
| step_id="user", | ||
| data_schema=vol.Schema( | ||
| { | ||
| vol.Required(CONF_DEVICE_KEY): str, | ||
| vol.Required(CONF_NAME, default=DEFAULT_NAME): str, | ||
| vol.Inclusive(CONF_PASSWORD, ATTR_ENCRYPTED): str, | ||
| vol.Inclusive(CONF_SALT, ATTR_ENCRYPTED): str, | ||
| } | ||
| ), | ||
| ) | ||
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,13 @@ | ||
| """Constants for the simplepush integration.""" | ||
|
|
||
| from typing import Final | ||
|
|
||
| DOMAIN: Final = "simplepush" | ||
| DEFAULT_NAME: Final = "simplepush" | ||
| DATA_HASS_CONFIG: Final = "simpleush_hass_config" | ||
|
|
||
| ATTR_ENCRYPTED: Final = "encrypted" | ||
| ATTR_EVENT: Final = "event" | ||
|
|
||
| CONF_DEVICE_KEY: Final = "device_key" | ||
| CONF_SALT: Final = "salt" |
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "config": { | ||
| "step": { | ||
| "user": { | ||
| "data": { | ||
| "name": "[%key:common::config_flow::data::name%]", | ||
| "device_key": "The device key of your device", | ||
| "event": "The event for the events.", | ||
| "password": "The password of the encryption used by your device", | ||
| "salt": "The salt used by your device." | ||
| } | ||
| } | ||
| }, | ||
| "abort": { | ||
| "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" | ||
| } | ||
| } | ||
| } |
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,18 @@ | ||
| { | ||
| "config": { | ||
| "abort": { | ||
| "already_configured": "Device is already configured" | ||
| }, | ||
| "step": { | ||
| "user": { | ||
| "data": { | ||
| "device_key": "The device key of your device", | ||
| "event": "The event for the events.", | ||
| "name": "Name", | ||
| "password": "The password of the encryption used by your device", | ||
| "salt": "The salt used by your device." | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -311,6 +311,7 @@ | |
| "shelly", | ||
| "shopping_list", | ||
| "sia", | ||
| "simplepush", | ||
| "simplisafe", | ||
| "skybell", | ||
| "slack", | ||
|
|
||
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 @@ | ||
| """Tests for the simeplush integration.""" |
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,76 @@ | ||
| """Test Simplepush config flow.""" | ||
| from homeassistant import config_entries, data_entry_flow | ||
| from homeassistant.components.simplepush.const import CONF_DEVICE_KEY, CONF_SALT, DOMAIN | ||
| from homeassistant.const import CONF_NAME, CONF_PASSWORD | ||
| from homeassistant.core import HomeAssistant | ||
|
|
||
| from tests.common import MockConfigEntry | ||
|
|
||
| MOCK_CONFIG = { | ||
| CONF_DEVICE_KEY: "abc", | ||
| CONF_NAME: "simplepush", | ||
| CONF_PASSWORD: "password", | ||
| CONF_SALT: "salt", | ||
| } | ||
|
|
||
|
|
||
| async def test_flow_successful(hass: HomeAssistant) -> None: | ||
| """Test user initialized flow.""" | ||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, | ||
| context={"source": config_entries.SOURCE_USER}, | ||
| ) | ||
| result = await hass.config_entries.flow.async_configure( | ||
|
MartinHjelmare marked this conversation as resolved.
|
||
| result["flow_id"], | ||
| user_input=MOCK_CONFIG, | ||
| ) | ||
| assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY | ||
| assert result["title"] == "simplepush" | ||
| assert result["data"] == MOCK_CONFIG | ||
|
|
||
|
|
||
| async def test_flow_user_device_key_already_configured(hass): | ||
| """Test user initialized flow with duplicate device key.""" | ||
| entry = MockConfigEntry( | ||
| domain=DOMAIN, | ||
| data=MOCK_CONFIG, | ||
| unique_id="abc", | ||
| ) | ||
|
|
||
| entry.add_to_hass(hass) | ||
|
|
||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, | ||
| context={"source": config_entries.SOURCE_USER}, | ||
| ) | ||
| result = await hass.config_entries.flow.async_configure( | ||
| result["flow_id"], | ||
| user_input=MOCK_CONFIG, | ||
| ) | ||
| assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT | ||
| assert result["reason"] == "already_configured" | ||
|
|
||
|
|
||
| async def test_flow_user_name_already_configured(hass): | ||
| """Test user initialized flow with duplicate name.""" | ||
| entry = MockConfigEntry( | ||
| domain=DOMAIN, | ||
| data=MOCK_CONFIG, | ||
| unique_id="abc", | ||
| ) | ||
|
|
||
| entry.add_to_hass(hass) | ||
|
|
||
| new_entry = MOCK_CONFIG.copy() | ||
| new_entry[CONF_DEVICE_KEY] = "abc1" | ||
|
|
||
| result = await hass.config_entries.flow.async_init( | ||
| DOMAIN, | ||
| context={"source": config_entries.SOURCE_USER}, | ||
| ) | ||
| result = await hass.config_entries.flow.async_configure( | ||
| result["flow_id"], | ||
| user_input=MOCK_CONFIG, | ||
| ) | ||
| assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT | ||
| assert result["reason"] == "already_configured" | ||
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.