-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Add wemo options enable_subscription & enable_long_press #56972
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
7 commits
Select commit
Hold shift + click to select a range
771d9e5
Add wemo options enable_subscription & enable_long_press
esev 3ec76fd
Also add polling_interval_seconds option
esev 1b4e1e3
Give feedback about invalid option combinations
esev 34fb800
Use a frozen dataclass for Options
esev d7885b0
Validate polling_interval_seconds
esev 65028e0
Describe message arg
esev 6493772
Replace broad exception with PyWeMoException
esev 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,79 @@ | ||
| """Config flow for Wemo.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import fields | ||
| from typing import Any, get_type_hints | ||
|
|
||
| import pywemo | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers import config_entry_flow | ||
| from homeassistant.config_entries import ConfigEntry, OptionsFlow | ||
| from homeassistant.core import HomeAssistant, callback | ||
| from homeassistant.data_entry_flow import FlowResult | ||
| from homeassistant.helpers.config_entry_flow import DiscoveryFlowHandler | ||
|
|
||
| from .const import DOMAIN | ||
| from .wemo_device import Options, OptionsValidationError | ||
|
|
||
|
|
||
| async def _async_has_devices(hass: HomeAssistant) -> bool: | ||
| """Return if there are devices that can be discovered.""" | ||
| return bool(await hass.async_add_executor_job(pywemo.discover_devices)) | ||
|
|
||
|
|
||
| config_entry_flow.register_discovery_flow(DOMAIN, "Wemo", _async_has_devices) | ||
| class WemoFlow(DiscoveryFlowHandler, domain=DOMAIN): | ||
| """Discovery flow with options for Wemo.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| """Init discovery flow.""" | ||
| super().__init__(DOMAIN, "Wemo", _async_has_devices) | ||
|
|
||
| @staticmethod | ||
| @callback | ||
| def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow: | ||
| """Get the options flow for this handler.""" | ||
| return WemoOptionsFlow(config_entry) | ||
|
|
||
|
|
||
| class WemoOptionsFlow(OptionsFlow): | ||
| """Options flow for the WeMo component.""" | ||
|
|
||
| def __init__(self, config_entry: ConfigEntry) -> None: | ||
| """Initialize options flow.""" | ||
| self.config_entry = config_entry | ||
|
|
||
| async def async_step_init( | ||
| self, user_input: dict[str, Any] | None = None | ||
| ) -> FlowResult: | ||
| """Manage options for the WeMo component.""" | ||
| errors: dict[str, str] | None = None | ||
| if user_input is not None: | ||
| try: | ||
| Options(**user_input) | ||
| except OptionsValidationError as err: | ||
| errors = {err.field_key: err.error_key} | ||
| else: | ||
| return self.async_create_entry(title="", data=user_input) | ||
|
|
||
| return self.async_show_form( | ||
| step_id="init", | ||
| data_schema=_schema_for_options(Options(**self.config_entry.options)), | ||
| errors=errors, | ||
| ) | ||
|
|
||
|
|
||
| def _schema_for_options(options: Options) -> vol.Schema: | ||
| """Return the Voluptuous schema for the Options instance. | ||
|
|
||
| All values are optional. The default value is set to the current value and | ||
| the type hint is set to the value of the field type annotation. | ||
| """ | ||
| return vol.Schema( | ||
| { | ||
| vol.Optional( | ||
| field.name, default=getattr(options, field.name) | ||
| ): get_type_hints(options)[field.name] | ||
| for field in fields(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
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
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.