mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix bug in locative logic
This commit is contained in:
parent
c07a096e57
commit
f96c5aa62f
@ -49,10 +49,9 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
|||||||
handler.write_text("Setting location to {}".format(location_name))
|
handler.write_text("Setting location to {}".format(location_name))
|
||||||
|
|
||||||
elif direction == 'exit':
|
elif direction == 'exit':
|
||||||
current_state = hass.states.get(
|
current_state = hass.states.get("{}.{}".format(DOMAIN, device))
|
||||||
"{}.{}".format(DOMAIN, device)).state
|
|
||||||
|
|
||||||
if current_state == location_name:
|
if current_state is None or current_state.state == location_name:
|
||||||
see(dev_id=device, location_name=STATE_NOT_HOME)
|
see(dev_id=device, location_name=STATE_NOT_HOME)
|
||||||
handler.write_text("Setting location to not home")
|
handler.write_text("Setting location to not home")
|
||||||
else:
|
else:
|
||||||
|
@ -203,3 +203,21 @@ class TestLocative(unittest.TestCase):
|
|||||||
|
|
||||||
state = hass.states.get('{}.{}'.format('device_tracker', data['device']))
|
state = hass.states.get('{}.{}'.format('device_tracker', data['device']))
|
||||||
self.assertEqual(state.state, 'work')
|
self.assertEqual(state.state, 'work')
|
||||||
|
|
||||||
|
def test_exit_first(self, update_config):
|
||||||
|
""" Test when an exit message is sent first on a new device """
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'latitude': 40.7855,
|
||||||
|
'longitude': -111.7367,
|
||||||
|
'device': 'new_device',
|
||||||
|
'id': 'Home',
|
||||||
|
'trigger': 'exit'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Exit Home
|
||||||
|
req = requests.get(_url(data))
|
||||||
|
self.assertEqual(200, req.status_code)
|
||||||
|
|
||||||
|
state = hass.states.get('{}.{}'.format('device_tracker', data['device']))
|
||||||
|
self.assertEqual(state.state, 'not_home')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user