mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
API POST has new state validation (fix for state = 0) (#8324)
* Fix validation of get new state * Add unittest to check posting a state with zero value
This commit is contained in:
parent
1e655eea74
commit
22681fbe08
@ -213,7 +213,7 @@ class APIEntityStateView(HomeAssistantView):
|
|||||||
|
|
||||||
new_state = data.get('state')
|
new_state = data.get('state')
|
||||||
|
|
||||||
if not new_state:
|
if new_state is None:
|
||||||
return self.json_message('No state specified', HTTP_BAD_REQUEST)
|
return self.json_message('No state specified', HTTP_BAD_REQUEST)
|
||||||
|
|
||||||
attributes = data.get('attributes')
|
attributes = data.get('attributes')
|
||||||
|
@ -96,6 +96,23 @@ def test_api_state_change_with_bad_data(hass, mock_api_client):
|
|||||||
assert resp.status == 400
|
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
|
# pylint: disable=invalid-name
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_api_state_change_push(hass, mock_api_client):
|
def test_api_state_change_push(hass, mock_api_client):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user