Add support for 'Send Current Position' feature in Geofency 5.1 (#10012)
This commit is contained in:
parent
c0eaf0386c
commit
25a25dde7a
2 changed files with 27 additions and 2 deletions
|
@ -21,6 +21,9 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['http']
|
DEPENDENCIES = ['http']
|
||||||
|
|
||||||
|
ATTR_CURRENT_LATITUDE = 'currentLatitude'
|
||||||
|
ATTR_CURRENT_LONGITUDE = 'currentLongitude'
|
||||||
|
|
||||||
BEACON_DEV_PREFIX = 'beacon'
|
BEACON_DEV_PREFIX = 'beacon'
|
||||||
CONF_MOBILE_BEACONS = 'mobile_beacons'
|
CONF_MOBILE_BEACONS = 'mobile_beacons'
|
||||||
|
|
||||||
|
@ -72,6 +75,9 @@ class GeofencyView(HomeAssistantView):
|
||||||
location_name = data['name']
|
location_name = data['name']
|
||||||
else:
|
else:
|
||||||
location_name = STATE_NOT_HOME
|
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))
|
return (yield from self._set_location(hass, data, location_name))
|
||||||
|
|
||||||
|
@ -96,8 +102,12 @@ class GeofencyView(HomeAssistantView):
|
||||||
data['device'] = slugify(data['device'])
|
data['device'] = slugify(data['device'])
|
||||||
data['name'] = slugify(data['name'])
|
data['name'] = slugify(data['name'])
|
||||||
|
|
||||||
data[ATTR_LATITUDE] = float(data[ATTR_LATITUDE])
|
gps_attributes = [ATTR_LATITUDE, ATTR_LONGITUDE,
|
||||||
data[ATTR_LONGITUDE] = float(data[ATTR_LONGITUDE])
|
ATTR_CURRENT_LATITUDE, ATTR_CURRENT_LONGITUDE]
|
||||||
|
|
||||||
|
for attribute in gps_attributes:
|
||||||
|
if attribute in data:
|
||||||
|
data[attribute] = float(data[attribute])
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
|
@ -170,6 +170,21 @@ def test_gps_enter_and_exit_home(hass, geofency_client):
|
||||||
'device_tracker', device_name)).state
|
'device_tracker', device_name)).state
|
||||||
assert STATE_NOT_HOME == state_name
|
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
|
@asyncio.coroutine
|
||||||
def test_beacon_enter_and_exit_home(hass, geofency_client):
|
def test_beacon_enter_and_exit_home(hass, geofency_client):
|
||||||
|
|
Loading…
Add table
Reference in a new issue