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

Use voluptuous for input_slider, input_boolean, input_select #3256

Merged
merged 9 commits into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow_extra
  • Loading branch information
kellerza committed Sep 20, 2016
commit e95a35f13bc39e26ac6c091620d9f56d0fb429ed
9 changes: 0 additions & 9 deletions homeassistant/components/input_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,12 @@
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
})

<<<<<<< HEAD
CONFIG_SCHEMA = vol.Schema({
cv.slug: {
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_INITIAL, default=False): cv.boolean,
vol.Optional(CONF_ICON): cv.icon,
}}, required=True, extra=vol.ALLOW_EXTRA)
=======
CONFIG_SCHEMA = vol.Schema({DOMAIN: {
cv.slug: vol.Any(None, {
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_INITIAL, default=False): cv.boolean,
vol.Optional(CONF_ICON): cv.icon,
})}}, required=True)
>>>>>>> CONFIG_SCHEMA


def is_on(hass, entity_id):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/input_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _cv_input_select(cfg):
[cv.string]),
vol.Optional(CONF_INITIAL): cv.string,
vol.Optional(CONF_ICON): cv.icon,
}, _cv_input_select)}}, required=True)
}, _cv_input_select)}}, required=True, extra=vol.ALLOW_EXTRA)


def select_option(hass, entity_id, option):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/input_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _cv_input_slider(cfg):
vol.Range(min=1e-3)),
vol.Optional(CONF_ICON): cv.icon,
vol.Optional(ATTR_UNIT_OF_MEASUREMENT): cv.string
}, _cv_input_slider)}}, required=True)
}, _cv_input_slider)}}, required=True, extra=vol.ALLOW_EXTRA)


def select_value(hass, entity_id, value):
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/helpers/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from urllib.parse import urlparse

from typing import Any, Union, TypeVar, Callable, Sequence, List, Dict
from typing import Any, Union, TypeVar, Callable, Sequence, Dict

import jinja2
import voluptuous as vol
Expand Down Expand Up @@ -80,7 +80,7 @@ def isfile(value: Any) -> str:
return file_in


def ensure_list(value: Union[T, Sequence[T]]) -> List[T]:
def ensure_list(value: Union[T, Sequence[T]]) -> Sequence[T]:
"""Wrap value in list if it is not one."""
return (value if isinstance(value, list) else
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that ensure_list now has a default value ([]). I would prefer instead to keep it to the original implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, will roll back this change.
Ok if I comment out the failing unit tests with [None] with a comment linking to the voluptuous PR?

Copy link
Member

Choose a reason for hiding this comment

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

Let's just remove it.

[] if value is None else [value])
Expand All @@ -94,7 +94,7 @@ def entity_id(value: Any) -> str:
raise vol.Invalid('Entity ID {} is an invalid entity id'.format(value))


def entity_ids(value: Union[str, Sequence]) -> List[str]:
def entity_ids(value: Union[str, Sequence]) -> Sequence[str]:
"""Validate Entity IDs."""
if value is None:
raise vol.Invalid('Entity IDs can not be None')
Expand Down