diff --git a/homeassistant/components/device_tracker/geofency.py b/homeassistant/components/device_tracker/geofency.py index d4e576bad74..58d69f39a1d 100755 --- a/homeassistant/components/device_tracker/geofency.py +++ b/homeassistant/components/device_tracker/geofency.py @@ -21,6 +21,9 @@ _LOGGER = logging.getLogger(__name__) DEPENDENCIES = ['http'] +ATTR_CURRENT_LATITUDE = 'currentLatitude' +ATTR_CURRENT_LONGITUDE = 'currentLongitude' + BEACON_DEV_PREFIX = 'beacon' CONF_MOBILE_BEACONS = 'mobile_beacons' @@ -72,6 +75,9 @@ class GeofencyView(HomeAssistantView): location_name = data['name'] else: location_name = STATE_NOT_HOME + if ATTR_CURRENT_LATITUDE in data: + data[ATTR_LATITUDE] = data[ATTR_CURRENT_LATITUDE] + data[ATTR_LONGITUDE] = data[ATTR_CURRENT_LONGITUDE] return (yield from self._set_location(hass, data, location_name)) @@ -96,8 +102,12 @@ class GeofencyView(HomeAssistantView): data['device'] = slugify(data['device']) data['name'] = slugify(data['name']) - data[ATTR_LATITUDE] = float(data[ATTR_LATITUDE]) - data[ATTR_LONGITUDE] = float(data[ATTR_LONGITUDE]) + gps_attributes = [ATTR_LATITUDE, ATTR_LONGITUDE, + ATTR_CURRENT_LATITUDE, ATTR_CURRENT_LONGITUDE] + + for attribute in gps_attributes: + if attribute in data: + data[attribute] = float(data[attribute]) return data diff --git a/tests/components/device_tracker/test_geofency.py b/tests/components/device_tracker/test_geofency.py index e8aa44cb0e5..5def6a217f4 100644 --- a/tests/components/device_tracker/test_geofency.py +++ b/tests/components/device_tracker/test_geofency.py @@ -170,6 +170,21 @@ def test_gps_enter_and_exit_home(hass, geofency_client): 'device_tracker', device_name)).state assert STATE_NOT_HOME == state_name + # Exit the Home zone with "Send Current Position" enabled + data = GPS_EXIT_HOME.copy() + data['currentLatitude'] = NOT_HOME_LATITUDE + data['currentLongitude'] = NOT_HOME_LONGITUDE + + req = yield from geofency_client.post(URL, data=data) + assert req.status == HTTP_OK + device_name = slugify(GPS_EXIT_HOME['device']) + current_latitude = hass.states.get('{}.{}'.format( + 'device_tracker', device_name)).attributes['latitude'] + assert NOT_HOME_LATITUDE == current_latitude + current_longitude = hass.states.get('{}.{}'.format( + 'device_tracker', device_name)).attributes['longitude'] + assert NOT_HOME_LONGITUDE == current_longitude + @asyncio.coroutine def test_beacon_enter_and_exit_home(hass, geofency_client):