2016-03-09 09:25:50 +00:00
|
|
|
"""The tests for the Proximity component."""
|
2016-02-07 08:51:21 +00:00
|
|
|
from homeassistant.components import proximity
|
|
|
|
|
2016-02-14 23:08:23 +00:00
|
|
|
from tests.common import get_test_home_assistant
|
|
|
|
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
class TestProximity:
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the Proximity component."""
|
2016-02-07 08:51:21 +00:00
|
|
|
|
|
|
|
def setup_method(self, method):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Setup things to be run when tests are started."""
|
2016-02-14 23:08:23 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'zone.home', 'zoning',
|
|
|
|
{
|
|
|
|
'name': 'home',
|
|
|
|
'latitude': 2.1,
|
|
|
|
'longitude': 1.1,
|
|
|
|
'radius': 10
|
|
|
|
})
|
|
|
|
|
|
|
|
def teardown_method(self, method):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Stop everything that was started."""
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.stop()
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_proximity(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the proximity."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
},
|
|
|
|
'tolerance': '1'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.state == 'not set'
|
|
|
|
assert state.attributes.get('nearest') == 'not set'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'not set'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set('proximity.home', '0')
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.state == '0'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_no_devices_in_config(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for missing devices in configuration."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert not proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'tolerance': '1'
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_no_tolerance_in_config(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for missing tolerance in configuration ."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_no_ignored_zones_in_config(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for ignored zones in configuration."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
},
|
|
|
|
'tolerance': '1'
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_no_zone_in_config(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for missing zone in configuration."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
},
|
|
|
|
'tolerance': '1'
|
|
|
|
}
|
2016-02-13 13:19:11 +00:00
|
|
|
})
|
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_in_zone(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker in zone."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1'
|
|
|
|
},
|
|
|
|
'tolerance': '1'
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 2.1,
|
|
|
|
'longitude': 1.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.state == '0'
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'arrived'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_trackers_in_zone(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for trackers in zone."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
},
|
|
|
|
'tolerance': '1'
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 2.1,
|
|
|
|
'longitude': 1.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2',
|
|
|
|
'latitude': 2.1,
|
|
|
|
'longitude': 1.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.state == '0'
|
2016-02-14 21:07:21 +00:00
|
|
|
assert ((state.attributes.get('nearest') == 'test1, test2') or
|
|
|
|
(state.attributes.get('nearest') == 'test2, test1'))
|
2016-02-07 08:51:21 +00:00
|
|
|
assert state.attributes.get('dir_of_travel') == 'arrived'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_away(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker state away."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1'
|
|
|
|
},
|
|
|
|
'tolerance': '1'
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 20.1,
|
|
|
|
'longitude': 10.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_awayfurther(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker state away further."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 20.1,
|
|
|
|
'longitude': 10.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 40.1,
|
|
|
|
'longitude': 20.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'away_from'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_awaycloser(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker state away closer."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 40.1,
|
|
|
|
'longitude': 20.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 20.1,
|
|
|
|
'longitude': 10.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'towards'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_all_device_trackers_in_ignored_zone(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker in ignored zone."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'work',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.state == 'not set'
|
|
|
|
assert state.attributes.get('nearest') == 'not set'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'not set'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_no_coordinates(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker with no coordinates."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1'
|
|
|
|
},
|
|
|
|
'tolerance': '1'
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'not set'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'not set'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_awayfurther_than_test2_first_test1(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker ordering."""
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 20.1,
|
|
|
|
'longitude': 10.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2',
|
|
|
|
'latitude': 40.1,
|
|
|
|
'longitude': 20.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_awayfurther_than_test2_first_test2(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker ordering."""
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2',
|
|
|
|
'latitude': 40.1,
|
|
|
|
'longitude': 20.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test2'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 20.1,
|
|
|
|
'longitude': 10.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_awayfurther_test2_in_ignored_zone(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker states."""
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'work',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 20.1,
|
|
|
|
'longitude': 10.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-14 21:07:21 +00:00
|
|
|
def test_device_tracker_test1_awayfurther_test2_first(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker state."""
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 10.1,
|
|
|
|
'longitude': 5.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2',
|
|
|
|
'latitude': 20.1,
|
|
|
|
'longitude': 10.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 40.1,
|
|
|
|
'longitude': 20.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 35.1,
|
|
|
|
'longitude': 15.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'work',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test2'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_awayfurther_a_bit(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker states."""
|
2016-02-07 08:51:21 +00:00
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1'
|
|
|
|
},
|
|
|
|
'tolerance': 1000
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 20.1000001,
|
|
|
|
'longitude': 10.1000001
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 20.1000002,
|
|
|
|
'longitude': 10.1000002
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'stationary'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
def test_device_tracker_test1_nearest_after_test2_in_ignored_zone(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for tracker states."""
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2'
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
assert proximity.setup(self.hass, {
|
|
|
|
'proximity': {
|
|
|
|
'zone': 'home',
|
|
|
|
'ignored_zones': {
|
|
|
|
'work'
|
|
|
|
},
|
|
|
|
'devices': {
|
|
|
|
'device_tracker.test1',
|
|
|
|
'device_tracker.test2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test1', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test1',
|
|
|
|
'latitude': 20.1,
|
|
|
|
'longitude': 10.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'not_home',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2',
|
|
|
|
'latitude': 10.1,
|
|
|
|
'longitude': 5.1
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test2'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|
2016-02-13 13:19:11 +00:00
|
|
|
|
2016-02-07 08:51:21 +00:00
|
|
|
self.hass.states.set(
|
|
|
|
'device_tracker.test2', 'work',
|
|
|
|
{
|
|
|
|
'friendly_name': 'test2',
|
|
|
|
'latitude': 12.6,
|
|
|
|
'longitude': 7.6
|
|
|
|
})
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
state = self.hass.states.get('proximity.home')
|
|
|
|
assert state.attributes.get('nearest') == 'test1'
|
|
|
|
assert state.attributes.get('dir_of_travel') == 'unknown'
|