-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
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 all 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,39 @@ | ||
| """The simplepush component.""" | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import Platform | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers import discovery | ||
| from homeassistant.helpers.typing import ConfigType | ||
|
|
||
| from .const import DATA_HASS_CONFIG, DOMAIN | ||
|
|
||
| PLATFORMS = [Platform.NOTIFY] | ||
|
|
||
|
|
||
| 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], | ||
| ) | ||
| ) | ||
|
|
||
| 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,88 @@ | ||
| """Config flow for simplepush integration.""" | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from simplepush import UnknownError, send, send_encrypted | ||
| 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 | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def validate_input(entry: dict[str, str]) -> dict[str, str] | None: | ||
| """Validate user input.""" | ||
| try: | ||
| if CONF_PASSWORD in entry: | ||
| send_encrypted( | ||
| entry[CONF_DEVICE_KEY], | ||
| entry[CONF_PASSWORD], | ||
| entry[CONF_PASSWORD], | ||
| "HA test", | ||
| "Message delivered successfully", | ||
| ) | ||
| else: | ||
| send(entry[CONF_DEVICE_KEY], "HA test", "Message delivered successfully") | ||
| except UnknownError: | ||
| return {"base": "cannot_connect"} | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| 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.""" | ||
| errors: dict[str, str] | None = None | ||
| 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], | ||
| } | ||
| ) | ||
|
|
||
| if not ( | ||
| errors := await self.hass.async_add_executor_job( | ||
| validate_input, user_input | ||
| ) | ||
| ): | ||
| return self.async_create_entry( | ||
| 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, | ||
| } | ||
| ), | ||
| errors=errors, | ||
| ) | ||
|
|
||
| async def async_step_import(self, import_config: dict[str, str]) -> FlowResult: | ||
| """Import a config entry from configuration.yaml.""" | ||
| _LOGGER.warning( | ||
| "Configuration of the simplepush integration in YAML is deprecated and " | ||
| "will be removed in a future release; Your existing configuration " | ||
| "has been imported into the UI automatically and can be safely removed " | ||
| "from your configuration.yaml file" | ||
| ) | ||
| return await self.async_step_user(import_config) |
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 = "simplepush_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,21 @@ | ||
| { | ||
| "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." | ||
| } | ||
| } | ||
| }, | ||
| "error": { | ||
| "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" | ||
| }, | ||
| "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,21 @@ | ||
| { | ||
| "config": { | ||
| "abort": { | ||
| "already_configured": "Device is already configured" | ||
| }, | ||
| "error": { | ||
| "cannot_connect": "Failed to connect" | ||
| }, | ||
| "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.""" |
Oops, something went wrong.
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.