Push State (#2365)

* Add ability to push state changes

* Add tests for push state changes

* Fix style issues

* Use better name to force an update
This commit is contained in:
Philip Lundrigan 2016-06-26 01:33:23 -06:00 committed by Paulus Schoutsen
parent 446f998759
commit d13cc227cc
7 changed files with 72 additions and 9 deletions

View file

@ -136,6 +136,27 @@ class TestAPI(unittest.TestCase):
self.assertEqual(400, req.status_code)
# pylint: disable=invalid-name
def test_api_state_change_push(self):
"""Test if we can push a change the state of an entity."""
hass.states.set("test.test", "not_to_be_set")
events = []
hass.bus.listen(const.EVENT_STATE_CHANGED, events.append)
requests.post(_url(const.URL_API_STATES_ENTITY.format("test.test")),
data=json.dumps({"state": "not_to_be_set"}),
headers=HA_HEADERS)
hass.bus._pool.block_till_done()
self.assertEqual(0, len(events))
requests.post(_url(const.URL_API_STATES_ENTITY.format("test.test")),
data=json.dumps({"state": "not_to_be_set",
"force_update": True}),
headers=HA_HEADERS)
hass.bus._pool.block_till_done()
self.assertEqual(1, len(events))
# pylint: disable=invalid-name
def test_api_fire_event_with_no_data(self):
"""Test if the API allows us to fire an event."""