From 497a1c84b508eecb7d55ecaa2d0a8e7e1416b205 Mon Sep 17 00:00:00 2001 From: Sander de Leeuw Date: Thu, 5 Jan 2017 09:05:39 +0100 Subject: [PATCH] Fixed invalid response when sending a test-request from Locative iOS app (#5179) --- homeassistant/components/device_tracker/locative.py | 12 ++++++------ tests/components/device_tracker/test_locative.py | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/device_tracker/locative.py b/homeassistant/components/device_tracker/locative.py index 40d1ab8a12f..32eb033a284 100644 --- a/homeassistant/components/device_tracker/locative.py +++ b/homeassistant/components/device_tracker/locative.py @@ -63,18 +63,18 @@ class LocativeView(HomeAssistantView): return ('Device id not specified.', HTTP_UNPROCESSABLE_ENTITY) - if 'id' not in data: - _LOGGER.error('Location id not specified.') - return ('Location id not specified.', - HTTP_UNPROCESSABLE_ENTITY) - if 'trigger' not in data: _LOGGER.error('Trigger is not specified.') return ('Trigger is not specified.', HTTP_UNPROCESSABLE_ENTITY) + if 'id' not in data and data['trigger'] != 'test': + _LOGGER.error('Location id not specified.') + return ('Location id not specified.', + HTTP_UNPROCESSABLE_ENTITY) + device = data['device'].replace('-', '') - location_name = data['id'].lower() + location_name = data.get('id', data['trigger']).lower() direction = data['trigger'] gps_location = (data[ATTR_LATITUDE], data[ATTR_LONGITUDE]) diff --git a/tests/components/device_tracker/test_locative.py b/tests/components/device_tracker/test_locative.py index 20257d5d1f5..33f1b078166 100644 --- a/tests/components/device_tracker/test_locative.py +++ b/tests/components/device_tracker/test_locative.py @@ -108,6 +108,13 @@ class TestLocative(unittest.TestCase): req = requests.get(_url(copy)) self.assertEqual(200, req.status_code) + # Test message, no location + copy = data.copy() + copy['trigger'] = 'test' + del copy['id'] + req = requests.get(_url(copy)) + self.assertEqual(200, req.status_code) + # Unknown trigger copy = data.copy() copy['trigger'] = 'foobar'