From 3ed1738f769cbaf050a132f3f16ffb95e2154ab3 Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Tue, 10 Dec 2019 17:24:33 -0500 Subject: [PATCH] Fix input_text initialization with empty config. (#29829) --- homeassistant/components/input_text/__init__.py | 10 ++++++---- tests/components/input_text/test_init.py | 9 +++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/input_text/__init__.py b/homeassistant/components/input_text/__init__.py index 77f007c5ba8f..2049de7ab272 100644 --- a/homeassistant/components/input_text/__init__.py +++ b/homeassistant/components/input_text/__init__.py @@ -23,7 +23,9 @@ ENTITY_ID_FORMAT = DOMAIN + ".{}" CONF_INITIAL = "initial" CONF_MIN = "min" +CONF_MIN_VALUE = 0 CONF_MAX = "max" +CONF_MAX_VALUE = 100 MODE_TEXT = "text" MODE_PASSWORD = "password" @@ -59,8 +61,8 @@ CONFIG_SCHEMA = vol.Schema( vol.All( { vol.Optional(CONF_NAME): cv.string, - vol.Optional(CONF_MIN, default=0): vol.Coerce(int), - vol.Optional(CONF_MAX, default=100): vol.Coerce(int), + vol.Optional(CONF_MIN, default=CONF_MIN_VALUE): vol.Coerce(int), + vol.Optional(CONF_MAX, default=CONF_MAX_VALUE): vol.Coerce(int), vol.Optional(CONF_INITIAL, ""): cv.string, vol.Optional(CONF_ICON): cv.icon, vol.Optional(ATTR_UNIT_OF_MEASUREMENT): cv.string, @@ -121,8 +123,8 @@ async def _async_process_config(config): if cfg is None: cfg = {} name = cfg.get(CONF_NAME) - minimum = cfg.get(CONF_MIN) - maximum = cfg.get(CONF_MAX) + minimum = cfg.get(CONF_MIN, CONF_MIN_VALUE) + maximum = cfg.get(CONF_MAX, CONF_MAX_VALUE) initial = cfg.get(CONF_INITIAL) icon = cfg.get(CONF_ICON) unit = cfg.get(ATTR_UNIT_OF_MEASUREMENT) diff --git a/tests/components/input_text/test_init.py b/tests/components/input_text/test_init.py index 1bcf612c39b7..d37fe01cd29e 100644 --- a/tests/components/input_text/test_init.py +++ b/tests/components/input_text/test_init.py @@ -100,8 +100,7 @@ async def test_mode(hass): assert "password" == state.attributes["mode"] -@asyncio.coroutine -def test_restore_state(hass): +async def test_restore_state(hass): """Ensure states are restored on startup.""" mock_restore_cache( hass, @@ -110,10 +109,8 @@ def test_restore_state(hass): hass.state = CoreState.starting - yield from async_setup_component( - hass, - DOMAIN, - {DOMAIN: {"b1": {"min": 0, "max": 10}, "b2": {"min": 0, "max": 10}}}, + assert await async_setup_component( + hass, DOMAIN, {DOMAIN: {"b1": None, "b2": {"min": 0, "max": 10}}}, ) state = hass.states.get("input_text.b1")