diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py index b722fc6ebb4..8205029bd21 100644 --- a/homeassistant/components/api.py +++ b/homeassistant/components/api.py @@ -213,7 +213,7 @@ class APIEntityStateView(HomeAssistantView): new_state = data.get('state') - if not new_state: + if new_state is None: return self.json_message('No state specified', HTTP_BAD_REQUEST) attributes = data.get('attributes') diff --git a/tests/components/test_api.py b/tests/components/test_api.py index 2d4842d7290..69b9bfa69de 100644 --- a/tests/components/test_api.py +++ b/tests/components/test_api.py @@ -96,6 +96,23 @@ def test_api_state_change_with_bad_data(hass, mock_api_client): assert resp.status == 400 +# pylint: disable=invalid-name +@asyncio.coroutine +def test_api_state_change_to_zero_value(hass, mock_api_client): + """Test if changing a state to a zero value is possible.""" + resp = yield from mock_api_client.post( + const.URL_API_STATES_ENTITY.format("test_entity.with_zero_state"), + json={'state': 0}) + + assert resp.status == 201 + + resp = yield from mock_api_client.post( + const.URL_API_STATES_ENTITY.format("test_entity.with_zero_state"), + json={'state': 0.}) + + assert resp.status == 200 + + # pylint: disable=invalid-name @asyncio.coroutine def test_api_state_change_push(hass, mock_api_client):