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

Breaking changes: change select options to (key, value) tuple #5

Merged
merged 2 commits into from
Jul 26, 2018

Conversation

awarecan
Copy link
Contributor

@awarecan awarecan commented Jul 24, 2018

For dict

vol.Schema(vol.In({'key1': 'value1', 'key2': 'value2'})
==>
{
  'type': 'select',
  'options': [
    ('key1', 'value1'),
    ('key2', 'value2'),
  ]
}

And it can covert to JSON

{
  "type": "select",
  "options": [
    ["key1", "value1"],
    ["key2", "value2"]
  ]
}

For list, key and value is same

vol.Schema(vol.In(['value1', 'value2'])
==>
{
  'type': 'select',
  'options': [
    ('value1', 'value1'),
    ('value2', 'value2'),
  ]
}

Therefore, it can better support dropdown selection.

else:
return {
'type': 'select',
'options': list(schema.container)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of options should always be the same. I suggest that if a non-mapping is given, both key and value are the same.

if isinstance(schema.container, collections.Mapping):
return {
'type': 'select',
'options': [{key: value}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just write list(schema.container.items())

@awarecan awarecan changed the title Add better support for vol.In(dict) Breaking changes: change select options to (key, value) tuple Jul 25, 2018
@balloob balloob merged commit f98ce63 into home-assistant-libs:master Jul 26, 2018
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

Successfully merging this pull request may close these issues.

2 participants