-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add config flow to Meteo-France #29927
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 17 commits into
home-assistant:dev
from
Quentame:meteo_france/config-flow
Feb 4, 2020
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
505efca
Add config flow to Meteo-France
Quentame 309ede5
Review 1
Quentame dde52eb
Use config_entry.unique_id
Quentame 4133f06
Fix config_flow _show_setup_form + init
Quentame a321cad
Remove empty *_setup_platform()
Quentame 227a5e4
Avoid HomeAssistantError: Entity id already exists: sensor.[city_name…
Quentame 59e10c5
Review + abort when API error
Quentame bd7ffb4
Fix I/O
Quentame e74ad0c
Remove monitored_conditions
Quentame b02122e
Add async_unload_entry
Quentame b6d6a86
Review 3
Quentame d1c314d
Fix pipe
Quentame 5c70341
alert_watcher is already None
Quentame 8297fdc
Review 4
Quentame 4249ac0
Better fix for "Entity id already exists"
Quentame 90c63f9
Whoops, fix tests
Quentame fc159c4
Fix string
Quentame 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
17 changes: 17 additions & 0 deletions
17
homeassistant/components/meteo_france/.translations/en.json
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,17 @@ | ||
| { | ||
| "config": { | ||
| "abort": { | ||
| "already_configured": "City already configured", | ||
| "unknown": "Unknown error: please retry later" | ||
| }, | ||
| "step": { | ||
| "user": { | ||
| "data": { | ||
| "city": "City or postal code" | ||
| }, | ||
| "title": "M\u00e9t\u00e9o-France" | ||
| } | ||
| }, | ||
| "title": "M\u00e9t\u00e9o-France" | ||
| } | ||
| } |
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,63 @@ | ||
| """Config flow to configure the Meteo-France integration.""" | ||
| import logging | ||
|
|
||
| from meteofrance.client import meteofranceClient, meteofranceError | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant import config_entries | ||
| from homeassistant.data_entry_flow import AbortFlow | ||
|
|
||
| from .const import CONF_CITY | ||
| from .const import DOMAIN # pylint: disable=unused-import | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class MeteoFranceFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): | ||
| """Handle a Meteo-France config flow.""" | ||
|
|
||
| VERSION = 1 | ||
| CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL | ||
|
|
||
| def _show_setup_form(self, user_input=None, errors=None): | ||
| """Show the setup form to the user.""" | ||
|
|
||
| if user_input is None: | ||
| user_input = {} | ||
|
|
||
| return self.async_show_form( | ||
| step_id="user", | ||
| data_schema=vol.Schema( | ||
| {vol.Required(CONF_CITY, default=user_input.get(CONF_CITY, "")): str} | ||
| ), | ||
| errors=errors or {}, | ||
| ) | ||
|
|
||
| async def async_step_user(self, user_input=None): | ||
| """Handle a flow initiated by the user.""" | ||
| errors = {} | ||
|
|
||
| if user_input is None: | ||
| return self._show_setup_form(user_input, errors) | ||
|
|
||
| city = user_input[CONF_CITY] # Might be a city name or a postal code | ||
| city_name = None | ||
|
|
||
| try: | ||
| client = await self.hass.async_add_executor_job(meteofranceClient, city) | ||
| city_name = client.get_data()["name"] | ||
| except meteofranceError as exp: | ||
| _LOGGER.error( | ||
| "Unexpected error when creating the meteofrance proxy: %s", exp | ||
| ) | ||
| raise AbortFlow("unknown") | ||
|
Quentame marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Check if already configured | ||
| await self.async_set_unique_id(city_name) | ||
| self._abort_if_unique_id_configured() | ||
|
|
||
| return self.async_create_entry(title=city_name, data={CONF_CITY: city_name}) | ||
|
|
||
| async def async_step_import(self, user_input): | ||
| """Import a config entry.""" | ||
| 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
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.