-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add opentherm_gw config flow #27148
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
Add opentherm_gw config flow #27148
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
23 changes: 23 additions & 0 deletions
23
homeassistant/components/opentherm_gw/.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,23 @@ | ||
| { | ||
| "config": { | ||
| "error": { | ||
| "already_configured": "Gateway already configured", | ||
| "id_exists": "Gateway id already exists", | ||
| "serial_error": "Error connecting to device", | ||
| "timeout": "Connection attempt timed out" | ||
| }, | ||
| "step": { | ||
| "init": { | ||
| "data": { | ||
| "device": "Path or URL", | ||
| "floor_temperature": "Floor climate temperature", | ||
| "id": "ID", | ||
| "name": "Name", | ||
| "precision": "Climate temperature precision" | ||
| }, | ||
| "title": "OpenTherm Gateway" | ||
| } | ||
| }, | ||
| "title": "OpenTherm Gateway" | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
homeassistant/components/opentherm_gw/.translations/nl.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,23 @@ | ||
| { | ||
| "config": { | ||
| "error": { | ||
| "already_configured": "Gateway is reeds geconfigureerd", | ||
| "id_exists": "Gateway id bestaat reeds", | ||
| "serial_error": "Kan niet verbinden met de Gateway", | ||
| "timeout": "Time-out van de verbinding" | ||
| }, | ||
| "step": { | ||
| "init": { | ||
| "data": { | ||
| "device": "Pad of URL", | ||
| "floor_temperature": "Thermostaat temperaturen naar beneden afronden", | ||
| "id": "ID", | ||
| "name": "Naam", | ||
| "precision": "Thermostaat temperatuur precisie" | ||
| }, | ||
| "title": "OpenTherm Gateway" | ||
| } | ||
| }, | ||
| "title": "OpenTherm Gateway" | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| """OpenTherm Gateway config flow.""" | ||
| import asyncio | ||
| from serial import SerialException | ||
|
|
||
| import pyotgw | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant import config_entries | ||
| from homeassistant.const import CONF_DEVICE, CONF_ID, CONF_NAME | ||
|
|
||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| from . import DOMAIN | ||
|
|
||
|
|
||
| class OpenThermGwConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | ||
| """OpenTherm Gateway Config Flow.""" | ||
|
|
||
| VERSION = 1 | ||
| CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH | ||
|
|
||
| async def async_step_init(self, info=None): | ||
| """Handle config flow initiation.""" | ||
| if info: | ||
| name = info[CONF_NAME] | ||
| device = info[CONF_DEVICE] | ||
| gw_id = cv.slugify(info.get(CONF_ID, name)) | ||
|
|
||
| entries = [e.data for e in self.hass.config_entries.async_entries(DOMAIN)] | ||
|
|
||
| if gw_id in [e[CONF_ID] for e in entries]: | ||
| return self._show_form({"base": "id_exists"}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use the |
||
|
|
||
| if device in [e[CONF_DEVICE] for e in entries]: | ||
| return self._show_form({"base": "already_configured"}) | ||
|
|
||
| async def test_connection(): | ||
| """Try to connect to the OpenTherm Gateway.""" | ||
| otgw = pyotgw.pyotgw() | ||
| status = await otgw.connect(self.hass.loop, device) | ||
| await otgw.disconnect() | ||
| return status.get(pyotgw.OTGW_ABOUT) | ||
|
|
||
| try: | ||
| res = await asyncio.wait_for(test_connection(), timeout=10) | ||
| except asyncio.TimeoutError: | ||
| return self._show_form({"base": "timeout"}) | ||
| except SerialException: | ||
| return self._show_form({"base": "serial_error"}) | ||
|
|
||
| if res: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is this not true? |
||
| return self._create_entry(gw_id, name, device) | ||
|
|
||
| return self._show_form() | ||
|
|
||
| async def async_step_user(self, info=None): | ||
| """Handle manual initiation of the config flow.""" | ||
| return await self.async_step_init(info) | ||
|
|
||
| async def async_step_import(self, import_config): | ||
| """ | ||
| Import an OpenTherm Gateway device as a config entry. | ||
|
|
||
| This flow is triggered by `async_setup` for configured devices. | ||
| """ | ||
| formatted_config = { | ||
| CONF_NAME: import_config.get(CONF_NAME, import_config[CONF_ID]), | ||
| CONF_DEVICE: import_config[CONF_DEVICE], | ||
| CONF_ID: import_config[CONF_ID], | ||
| } | ||
| return await self.async_step_init(info=formatted_config) | ||
|
|
||
| def _show_form(self, errors=None): | ||
| """Show the config flow form with possible errors.""" | ||
| return self.async_show_form( | ||
| step_id="init", | ||
| data_schema=vol.Schema( | ||
| { | ||
| vol.Required(CONF_NAME): str, | ||
| vol.Required(CONF_DEVICE): str, | ||
| vol.Optional(CONF_ID): str, | ||
| } | ||
| ), | ||
| errors=errors or {}, | ||
| ) | ||
|
|
||
| def _create_entry(self, gw_id, name, device): | ||
| """Create entry for the OpenTherm Gateway device.""" | ||
| return self.async_create_entry( | ||
| title=name, data={CONF_ID: gw_id, CONF_DEVICE: device, CONF_NAME: name} | ||
| ) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't add other translations in the config flow PR. Just the default English translation.
Translations are handled separately via Lokalise and synced regularly to github.
https://developers.home-assistant.io/docs/en/internationalization_backend_localization.html#translation-strings