From 944a8c6d5271832a9fe6867fbf6e87be4d73f072 Mon Sep 17 00:00:00 2001 From: pvizeli Date: Tue, 11 Apr 2017 14:59:04 +0200 Subject: [PATCH 1/3] Bugfix slider --- homeassistant/components/input_slider.py | 2 +- tests/components/test_input_slider.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/input_slider.py b/homeassistant/components/input_slider.py index d10120e673be6f..04f1d5c3c99ee0 100644 --- a/homeassistant/components/input_slider.py +++ b/homeassistant/components/input_slider.py @@ -175,7 +175,7 @@ def async_added_to_hass(self): value = state and float(state.state) # Check against False because value can be 0 - if value is not False and self._minimum < value < self._maximum: + if value and self._minimum <= value <= self._maximum: self._current_value = value else: self._current_value = self._minimum diff --git a/tests/components/test_input_slider.py b/tests/components/test_input_slider.py index 7097e87e6463bd..f550091e31fb43 100644 --- a/tests/components/test_input_slider.py +++ b/tests/components/test_input_slider.py @@ -133,3 +133,21 @@ def test_initial_state_overrules_restore_state(hass): state = hass.states.get('input_slider.b2') assert state assert float(state.state) == 60 + + +@asyncio.coroutine +def test_no_initial_state_and_no_restore_state(hass): + """Ensure that entity is create without initial and restore feature.""" + hass.state = CoreState.starting + + yield from async_setup_component(hass, DOMAIN, { + DOMAIN: { + 'b1': { + 'min': 0, + 'max': 100, + }, + }}) + + state = hass.states.get('input_slider.b1') + assert state + assert float(state.state) == 0 From fc766fd2d6002b902eb871d1f1b5f134702e5b86 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 11 Apr 2017 09:21:43 -0700 Subject: [PATCH 2/3] Update input_slider.py --- homeassistant/components/input_slider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/input_slider.py b/homeassistant/components/input_slider.py index 04f1d5c3c99ee0..433be22c259318 100644 --- a/homeassistant/components/input_slider.py +++ b/homeassistant/components/input_slider.py @@ -175,7 +175,7 @@ def async_added_to_hass(self): value = state and float(state.state) # Check against False because value can be 0 - if value and self._minimum <= value <= self._maximum: + if value is not None and self._minimum <= value <= self._maximum: self._current_value = value else: self._current_value = self._minimum From 114c027fc3258c6d3125019da1c45479073ff1b2 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 11 Apr 2017 09:22:43 -0700 Subject: [PATCH 3/3] Update input_slider.py --- homeassistant/components/input_slider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/input_slider.py b/homeassistant/components/input_slider.py index 433be22c259318..c4976bb43e8c36 100644 --- a/homeassistant/components/input_slider.py +++ b/homeassistant/components/input_slider.py @@ -174,7 +174,7 @@ def async_added_to_hass(self): state = yield from async_get_last_state(self.hass, self.entity_id) value = state and float(state.state) - # Check against False because value can be 0 + # Check against None because value can be 0 if value is not None and self._minimum <= value <= self._maximum: self._current_value = value else: