Fix bug in locative logic
This commit is contained in:
parent
c07a096e57
commit
f96c5aa62f
2 changed files with 20 additions and 3 deletions
|
@ -49,10 +49,9 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
|||
handler.write_text("Setting location to {}".format(location_name))
|
||||
|
||||
elif direction == 'exit':
|
||||
current_state = hass.states.get(
|
||||
"{}.{}".format(DOMAIN, device)).state
|
||||
current_state = hass.states.get("{}.{}".format(DOMAIN, device))
|
||||
|
||||
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)
|
||||
handler.write_text("Setting location to not home")
|
||||
else:
|
||||
|
|
|
@ -203,3 +203,21 @@ class TestLocative(unittest.TestCase):
|
|||
|
||||
state = hass.states.get('{}.{}'.format('device_tracker', data['device']))
|
||||
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…
Add table
Reference in a new issue