def test_proximity(self): assert proximity_zones.setup(self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': { 'work' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': { 'home' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 } } }) state = self.hass.states.get('proximity_zones.home') assert state.state != 'not set' assert state.attributes.get('nearest') != 'not set' assert state.attributes.get('dir_of_travel') != 'not set'
def test_all_device_trackers_in_ignored_zone_at_start(self): self.hass.states.set('device_tracker.test1', 'work', { 'friendly_name': 'test1', 'latitude': 100, 'longitude': 100 }) self.hass.pool.block_till_done() assert proximity_zones.setup( self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': {'work'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': {'home'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 } } }) state = self.hass.states.get('proximity_zones.home') assert state.attributes.get('nearest') == 'test2' assert state.attributes.get('dir_of_travel') == 'unknown'
def test_device_tracker_test1_away(self): assert proximity_zones.setup( self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': {'work'}, 'devices': {'test1'}, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': {'home'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 } } }) 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_zones.home') assert state.attributes.get('nearest') == 'test1' assert state.attributes.get('dir_of_travel') == 'towards'
def test_no_zone_in_config(self): assert proximity_zones.setup(self.hass, { 'proximity_zones': { 'home': { 'ignored_zones': { 'work' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 }, 'work': { 'ignored_zones': { 'home' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 } } })
def test_device_trackers_in_zone(self): assert proximity_zones.setup( self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': {'work'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': {'home'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 } } }) 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_zones.home') assert state.state == '0' assert ((state.attributes.get('nearest') == 'test1, test2') or (state.attributes.get('nearest') == 'test2, test1')) assert state.attributes.get('dir_of_travel') == 'arrived'
def test_device_tracker_test1_no_coordinates_at_start(self): self.hass.states.set('device_tracker.test1', 'not_home', {'friendly_name': 'test1'}) self.hass.pool.block_till_done() assert proximity_zones.setup( self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': {'work'}, 'devices': {'test1'}, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': {'home'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 } } }) state = self.hass.states.get('proximity_zones.home') assert state.attributes.get('nearest') == 'not set' assert state.attributes.get('dir_of_travel') == 'not set'
def test_device_tracker_test1_in_zone(self): assert proximity_zones.setup( self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': {'work'}, 'devices': {'test1'}, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': {'home'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 } } }) self.hass.states.set('device_tracker.test1', 'not_home', { 'friendly_name': 'test1', 'latitude': 50, 'longitude': 50 }) self.hass.pool.block_till_done() state = self.hass.states.get('device_tracker.test1') assert state.state == 'not_home' self.hass.states.set('device_tracker.test1', 'home', { 'friendly_name': 'test1', 'latitude': 2.1, 'longitude': 1.1 }) self.hass.pool.block_till_done() device_state = self.hass.states.get('device_tracker.test1') assert device_state.state == 'home' device_state_lat = device_state.attributes['latitude'] assert device_state_lat == 2.1 device_state_lon = device_state.attributes['longitude'] assert device_state_lon == 1.1 zone_state = self.hass.states.get('zone.home') assert zone_state.state == 'zoning' proximity_latitude = zone_state.attributes.get('latitude') assert proximity_latitude == 2.1 proximity_longitude = zone_state.attributes.get('longitude') assert proximity_longitude == 1.1 assert zone.in_zone(zone_state, device_state_lat, device_state_lon) state = self.hass.states.get('proximity_zones.home') assert state.state == '0' assert state.attributes.get('nearest') == 'test1' assert state.attributes.get('dir_of_travel') == 'arrived'
def test_device_tracker_test1_awayfurther_test2_in_ignored_zone(self): 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', 'latitude': 100, 'longitude': 100 }) self.hass.pool.block_till_done() assert proximity_zones.setup(self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': { 'work' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': { 'home' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 } } }) 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_zones.home') assert state.attributes.get('nearest') == 'test1' assert state.attributes.get('dir_of_travel') == 'unknown'
def test_device_trackers_in_zone_at_start(self): 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() assert proximity_zones.setup(self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': { 'work' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': { 'home' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 } } }) state = self.hass.states.get('proximity_zones.home') assert state.state == '0' assert ((state.attributes.get('nearest') == 'test1, test2') or (state.attributes.get('nearest') == 'test2, test1')) assert state.attributes.get('dir_of_travel') == 'arrived'
def test_no_zone_in_config(self): assert proximity_zones.setup( self.hass, { 'proximity_zones': { 'home': { 'ignored_zones': {'work'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 }, 'work': { 'ignored_zones': {'home'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 } } })
def test_no_devices_in_config(self): assert not proximity_zones.setup( self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': {'work'}, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': {'home'}, 'tolerance': 1 } } })
def test_no_devices_in_config(self): assert not proximity_zones.setup(self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': { 'work' }, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': { 'home' }, 'tolerance': 1 } } })
def test_proximity(self): assert proximity_zones.setup( self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': {'work'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': {'home'}, 'devices': {'test1', 'test2'}, 'tolerance': 1 } } }) state = self.hass.states.get('proximity_zones.home') assert state.state != 'not set' assert state.attributes.get('nearest') != 'not set' assert state.attributes.get('dir_of_travel') != 'not set'
def test_device_tracker_test1_no_coordinates_at_start(self): self.hass.states.set( 'device_tracker.test1', 'not_home', { 'friendly_name': 'test1' }) self.hass.pool.block_till_done() assert proximity_zones.setup(self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': { 'work' }, 'devices': { 'test1' }, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': { 'home' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 } } }) state = self.hass.states.get('proximity_zones.home') assert state.attributes.get('nearest') == 'not set' assert state.attributes.get('dir_of_travel') == 'not set'
def test_no_proximity_config(self): assert not proximity_zones.setup(self.hass, {'proximity_zones': { 'home': 'test' }})
def test_no_proximity_config(self): assert not proximity_zones.setup(self.hass, { 'proximity_zones': { 'home': 'test' } })
def test_device_tracker_test1_in_zone(self): assert proximity_zones.setup(self.hass, { 'proximity_zones': { 'home': { 'zone': 'home', 'ignored_zones': { 'work' }, 'devices': { 'test1' }, 'tolerance': 1 }, 'work': { 'zone': 'work', 'ignored_zones': { 'home' }, 'devices': { 'test1', 'test2' }, 'tolerance': 1 } } }) self.hass.states.set( 'device_tracker.test1', 'not_home', { 'friendly_name': 'test1', 'latitude': 50, 'longitude': 50 }) self.hass.pool.block_till_done() state = self.hass.states.get('device_tracker.test1') assert state.state == 'not_home' self.hass.states.set( 'device_tracker.test1', 'home', { 'friendly_name': 'test1', 'latitude': 2.1, 'longitude': 1.1 }) self.hass.pool.block_till_done() device_state = self.hass.states.get('device_tracker.test1') assert device_state.state == 'home' device_state_lat = device_state.attributes['latitude'] assert device_state_lat == 2.1 device_state_lon = device_state.attributes['longitude'] assert device_state_lon == 1.1 zone_state = self.hass.states.get('zone.home') assert zone_state.state == 'zoning' proximity_latitude = zone_state.attributes.get('latitude') assert proximity_latitude == 2.1 proximity_longitude = zone_state.attributes.get('longitude') assert proximity_longitude == 1.1 assert zone.in_zone(zone_state, device_state_lat, device_state_lon) state = self.hass.states.get('proximity_zones.home') assert state.state == '0' assert state.attributes.get('nearest') == 'test1' assert state.attributes.get('dir_of_travel') == 'arrived'
def test_no_config(self): assert not proximity_zones.setup(self.hass, {})
def test_no_config(self): assert not proximity_zones.setup(self.hass, { })