mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
remote.set_state would log error even if not
This commit is contained in:
parent
a391bc3d3f
commit
2866437a1f
@ -351,7 +351,10 @@ def get_states(api):
|
|||||||
|
|
||||||
|
|
||||||
def set_state(api, entity_id, new_state, attributes=None):
|
def set_state(api, entity_id, new_state, attributes=None):
|
||||||
""" Tells API to update state for entity_id. """
|
"""
|
||||||
|
Tells API to update state for entity_id.
|
||||||
|
Returns True if success.
|
||||||
|
"""
|
||||||
|
|
||||||
attributes = attributes or {}
|
attributes = attributes or {}
|
||||||
|
|
||||||
@ -363,13 +366,18 @@ def set_state(api, entity_id, new_state, attributes=None):
|
|||||||
URL_API_STATES_ENTITY.format(entity_id),
|
URL_API_STATES_ENTITY.format(entity_id),
|
||||||
data)
|
data)
|
||||||
|
|
||||||
if req.status_code != 201:
|
if req.status_code not in (200, 201):
|
||||||
_LOGGER.error("Error changing state: %d - %s",
|
_LOGGER.error("Error changing state: %d - %s",
|
||||||
req.status_code, req.text)
|
req.status_code, req.text)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
except ha.HomeAssistantError:
|
except ha.HomeAssistantError:
|
||||||
_LOGGER.exception("Error setting state")
|
_LOGGER.exception("Error setting state")
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_state(api, entity_id, state):
|
def is_state(api, entity_id, state):
|
||||||
""" Queries API to see if entity_id is specified state. """
|
""" Queries API to see if entity_id is specified state. """
|
||||||
|
@ -217,10 +217,10 @@ class TestHTTP(unittest.TestCase):
|
|||||||
""" Helper method that will verify our event got called. """
|
""" Helper method that will verify our event got called. """
|
||||||
test_value.append(1)
|
test_value.append(1)
|
||||||
|
|
||||||
self.hass.listen_once_event("test_event_with_bad_data", listener)
|
self.hass.listen_once_event("test_event_bad_data", listener)
|
||||||
|
|
||||||
req = requests.post(
|
req = requests.post(
|
||||||
_url(remote.URL_API_EVENTS_EVENT.format("test_event")),
|
_url(remote.URL_API_EVENTS_EVENT.format("test_event_bad_data")),
|
||||||
data=json.dumps('not an object'),
|
data=json.dumps('not an object'),
|
||||||
headers=HA_HEADERS)
|
headers=HA_HEADERS)
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ class TestRemoteMethods(unittest.TestCase):
|
|||||||
|
|
||||||
def test_set_state(self):
|
def test_set_state(self):
|
||||||
""" Test Python API set_state. """
|
""" Test Python API set_state. """
|
||||||
remote.set_state(self.api, 'test.test', 'set_test')
|
self.assertTrue(remote.set_state(self.api, 'test.test', 'set_test'))
|
||||||
|
|
||||||
self.assertEqual(self.hass.states.get('test.test').state, 'set_test')
|
self.assertEqual(self.hass.states.get('test.test').state, 'set_test')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user