From 88fc64c8a0c7a759f0a09b20b7fb3feec235153c Mon Sep 17 00:00:00 2001 From: Danijel Stojnic Date: Sat, 5 Nov 2016 21:05:15 +0100 Subject: [PATCH] Add Map support for Locative component (#4174) * Add Map support for Locative component The Locative App on the mobile is sending an HTTP request to the server where also the GPS location is sent. But the GPS location was not passed to the event device_tracker.see. Use the passed GPS location from Locative and pass it to the device_tracker.see event. With this the device is then also shown on the HA Map component. * Use existing constants for latitude and longitude Use the existing constants from homeassistant.consts: ATTR_LATITUDE for 'latitude' ATTR_LONGITUDE for 'longitude' * Reuse the "yield from self.hass.loop.run_in_executor" again * Use variable gps_location --- homeassistant/components/device_tracker/locative.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/device_tracker/locative.py b/homeassistant/components/device_tracker/locative.py index f6419ae2490..e6bd74e57c9 100644 --- a/homeassistant/components/device_tracker/locative.py +++ b/homeassistant/components/device_tracker/locative.py @@ -8,7 +8,9 @@ import asyncio from functools import partial import logging -from homeassistant.const import HTTP_UNPROCESSABLE_ENTITY, STATE_NOT_HOME +from homeassistant.const import (ATTR_LATITUDE, ATTR_LONGITUDE, + STATE_NOT_HOME, + HTTP_UNPROCESSABLE_ENTITY) from homeassistant.components.http import HomeAssistantView # pylint: disable=unused-import from homeassistant.components.device_tracker import ( # NOQA @@ -76,11 +78,13 @@ class LocativeView(HomeAssistantView): device = data['device'].replace('-', '') location_name = data['id'].lower() direction = data['trigger'] + gps_location = (data[ATTR_LATITUDE], data[ATTR_LONGITUDE]) if direction == 'enter': yield from self.hass.loop.run_in_executor( None, partial(self.see, dev_id=device, - location_name=location_name)) + location_name=location_name, + gps=gps_location)) return 'Setting location to {}'.format(location_name) elif direction == 'exit': @@ -88,9 +92,11 @@ class LocativeView(HomeAssistantView): '{}.{}'.format(DOMAIN, device)) if current_state is None or current_state.state == location_name: + location_name = STATE_NOT_HOME yield from self.hass.loop.run_in_executor( None, partial(self.see, dev_id=device, - location_name=STATE_NOT_HOME)) + location_name=location_name, + gps=gps_location)) return 'Setting location to not home' else: # Ignore the message if it is telling us to exit a zone that we