Allow entry into passive zones.
This commit is contained in:
parent
7d23a5f7e4
commit
fc455a1047
2 changed files with 4 additions and 54 deletions
|
@ -99,14 +99,11 @@ def setup_scanner(hass, config, see):
|
|||
_LOGGER.info("Added beacon %s", location)
|
||||
else:
|
||||
# Normal region
|
||||
if not zone.attributes.get('passive'):
|
||||
kwargs['location_name'] = location
|
||||
|
||||
regions = REGIONS_ENTERED[dev_id]
|
||||
if location not in regions:
|
||||
regions.append(location)
|
||||
_LOGGER.info("Enter region %s", location)
|
||||
_set_gps_from_zone(kwargs, zone)
|
||||
_set_gps_from_zone(kwargs, location, zone)
|
||||
|
||||
see(**kwargs)
|
||||
see_beacons(dev_id, kwargs)
|
||||
|
@ -121,9 +118,7 @@ def setup_scanner(hass, config, see):
|
|||
if new_region:
|
||||
# Exit to previous region
|
||||
zone = hass.states.get("zone.{}".format(new_region))
|
||||
if not zone.attributes.get('passive'):
|
||||
kwargs['location_name'] = new_region
|
||||
_set_gps_from_zone(kwargs, zone)
|
||||
_set_gps_from_zone(kwargs, new_region, zone)
|
||||
_LOGGER.info("Exit to %s", new_region)
|
||||
see(**kwargs)
|
||||
see_beacons(dev_id, kwargs)
|
||||
|
@ -184,11 +179,12 @@ def _parse_see_args(topic, data):
|
|||
return dev_id, kwargs
|
||||
|
||||
|
||||
def _set_gps_from_zone(kwargs, zone):
|
||||
def _set_gps_from_zone(kwargs, location, zone):
|
||||
"""Set the see parameters from the zone parameters."""
|
||||
if zone is not None:
|
||||
kwargs['gps'] = (
|
||||
zone.attributes['latitude'],
|
||||
zone.attributes['longitude'])
|
||||
kwargs['gps_accuracy'] = zone.attributes['radius']
|
||||
kwargs['location_name'] = location
|
||||
return kwargs
|
||||
|
|
|
@ -133,15 +133,6 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
|
|||
'radius': 100000
|
||||
})
|
||||
|
||||
self.hass.states.set(
|
||||
'zone.passive', 'zoning',
|
||||
{
|
||||
'name': 'zone',
|
||||
'latitude': 3.0,
|
||||
'longitude': 1.0,
|
||||
'radius': 10,
|
||||
'passive': True
|
||||
})
|
||||
# Clear state between teste
|
||||
self.hass.states.set(DEVICE_TRACKER_STATE, None)
|
||||
owntracks.REGIONS_ENTERED = defaultdict(list)
|
||||
|
@ -325,43 +316,6 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
|
|||
self.send_message(EVENT_TOPIC, message)
|
||||
self.assert_location_state('outer')
|
||||
|
||||
def test_event_entry_exit_passive_zone(self):
|
||||
"""Test the event for passive zone exits."""
|
||||
# Enter passive zone
|
||||
message = REGION_ENTER_MESSAGE.copy()
|
||||
message['desc'] = "passive"
|
||||
self.send_message(EVENT_TOPIC, message)
|
||||
|
||||
# Should pick up gps put not zone
|
||||
self.assert_location_state('not_home')
|
||||
self.assert_location_latitude(3.0)
|
||||
self.assert_location_accuracy(10.0)
|
||||
|
||||
# Enter inner2 zone
|
||||
message = REGION_ENTER_MESSAGE.copy()
|
||||
message['desc'] = "inner_2"
|
||||
self.send_message(EVENT_TOPIC, message)
|
||||
self.assert_location_state('inner_2')
|
||||
self.assert_location_latitude(2.1)
|
||||
self.assert_location_accuracy(10.0)
|
||||
|
||||
# Exit inner_2 - should be in 'passive'
|
||||
# ie gps co-ords - but not zone
|
||||
message = REGION_LEAVE_MESSAGE.copy()
|
||||
message['desc'] = "inner_2"
|
||||
self.send_message(EVENT_TOPIC, message)
|
||||
self.assert_location_state('not_home')
|
||||
self.assert_location_latitude(3.0)
|
||||
self.assert_location_accuracy(10.0)
|
||||
|
||||
# Exit passive - should be in 'outer'
|
||||
message = REGION_LEAVE_MESSAGE.copy()
|
||||
message['desc'] = "passive"
|
||||
self.send_message(EVENT_TOPIC, message)
|
||||
self.assert_location_state('outer')
|
||||
self.assert_location_latitude(2.0)
|
||||
self.assert_location_accuracy(60.0)
|
||||
|
||||
def test_event_entry_unknown_zone(self):
|
||||
"""Test the event for unknown zone."""
|
||||
# Just treat as location update
|
||||
|
|
Loading…
Add table
Reference in a new issue