Skip to content
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

ConfigFlow / OptionsFlow --> Section not using suggested or default values #22419

Open
3 of 4 tasks
Nisbo opened this issue Oct 18, 2024 · 2 comments
Open
3 of 4 tasks

Comments

@Nisbo
Copy link

Nisbo commented Oct 18, 2024

Checklist

  • I have updated to the latest available Home Assistant version.
  • I have cleared the cache of my browser.
  • I have tried a different browser to see if it is related to my browser.
  • I have tried reproducing the issue in safe mode to rule out problems with unsupported custom resources.

Describe the issue you are experiencing

Fields are not filled with the current saved (or default) values in config_flow.py in a section

grafik

Describe the behavior you expected

Fields are filled with the current saved (or default) values in config_flow.py also in a section.

grafik

Steps to reproduce the issue

  1. create a default config flow and use vol.Schema with section in OptionsFlow
  2. try the code from the documentation
    https://developers.home-assistant.io/docs/data_entry_flow_index/

or use this code which also includes text fields with suggested and default values

        self.options_schema = vol.Schema({
            vol.Required("username"): str,
            vol.Required("password"): str,
            # Items can be grouped by collapsible sections
            "ssl_options": section(
                vol.Schema(
                    {
                        vol.Required("ssl", default=True): bool,
                        vol.Required("verify_ssl", default=True): bool,
			vol.Required("test_str", default="Test Value"): str,
			vol.Optional("test_str_optional", description={"suggested_value": "Test Optinal"}): str,
                    }
                ),
                # Whether or not the section is initially collapsed (default = False)
                {"collapsed": False},
            )
        })

What version of Home Assistant Core has the issue?

2024.10.2

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

Firefox 131.0.3

Which operating system are you using to run this browser?

Windows 10

State of relevant entities

No response

Problem-relevant frontend configuration

No response

Javascript errors shown in your browser console/inspector

No response

Additional information

No response

@karwosts
Copy link
Contributor

I just tried this in the kitchen sink options flow and it seemed to work fine ?

        return self.async_show_form(
            step_id="options_1",
            data_schema=vol.Schema(
                {
                    vol.Required("section_1"): data_entry_flow.section(
                        vol.Schema(
                            {
                                vol.Optional(
                                    CONF_BOOLEAN,
                                    default=self.config_entry.options.get(
                                        CONF_BOOLEAN, False
                                    ),
                                ): bool,
                                vol.Required("ssl", default=True): bool,
                                vol.Required("verify_ssl", default=True): bool,
                                vol.Required("test_str", default="Test Value"): str,
                                vol.Optional("test_str_optional", description={"suggested_value": "Test Optinal"}): str,
                                vol.Optional(
                                    CONF_INT,
                                    default=self.config_entry.options.get(CONF_INT, 10),
                                ): int,
                            }
                        ),
                        {"collapsed": False},
                    ),
                }
            ),
        )

image

@Nisbo
Copy link
Author

Nisbo commented Oct 21, 2024

This is working but only if you use
from homeassistant import data_entry_flow
instead of
from homeassistant.data_entry_flow import section

and it only works with vol.Required("advanced_options"): data_entry_flow.section( and not with vol.Optional("advanced_options"): data_entry_flow.section(

So it looks like the documentation needs an update.
However, thx for the input. I was able to solve my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants