mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 05:26:47 +00:00
Proximity unit of measure (#2659)
* Allow multiple proximities * Distance conversion * Add unit of measurement and conversion to proximity * Shorten attribute name * Fix get unit of measurement * Fix the km <-> m conversion * Add type check and errors * first path unit test around distance utility * Fix numeric type check * Fix conversion type-os * Actually set the exception thrown flag * Test for exact conversion * More descriptive variable names * Update method invocation to match change in method name * Missed a couple variables * Line continuation * Fix linting too many return issue * Break out proximity setup for list of proximity and for single proximity device * Pass hass to setup function * Check if setup succeeded for each proximity component * Change variable name * Break out branches in convert to avoid too many branches linting error * Remove disable lint line * Variables for default properties * Combine logic * Test loading multiple proximities for 100% code coverage on proximity component * Unit test to reach 100% Fail to configure proximities missing devices * Fail first before processing * Combine return statements * lstrip = bad Teagan * Utilize string formating instead of concatenation * Fix variable reference * Typeo * Clean up conversion to reduce complexity * Update unit tests to match code changes on distance util * Test non numeric value * Private methods, value type has already been checked.
This commit is contained in:
committed by
Paulus Schoutsen
parent
de7e27c92c
commit
122581da7f
@@ -18,11 +18,73 @@ class TestProximity:
|
||||
'longitude': 1.1,
|
||||
'radius': 10
|
||||
})
|
||||
self.hass.states.set(
|
||||
'zone.work', 'zoning',
|
||||
{
|
||||
'name': 'work',
|
||||
'latitude': 2.3,
|
||||
'longitude': 1.3,
|
||||
'radius': 10
|
||||
})
|
||||
|
||||
def teardown_method(self, method):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_proximities(self):
|
||||
"""Test a list of proximities."""
|
||||
assert proximity.setup(self.hass, {
|
||||
'proximity': [{
|
||||
'zone': 'home',
|
||||
'ignored_zones': {
|
||||
'work'
|
||||
},
|
||||
'devices': {
|
||||
'device_tracker.test1',
|
||||
'device_tracker.test2'
|
||||
},
|
||||
'tolerance': '1'
|
||||
}, {
|
||||
'zone': 'work',
|
||||
'devices': {
|
||||
'device_tracker.test1'
|
||||
},
|
||||
'tolerance': '1'
|
||||
}]
|
||||
})
|
||||
|
||||
proximities = ['home', 'work']
|
||||
|
||||
for prox in proximities:
|
||||
state = self.hass.states.get('proximity.' + prox)
|
||||
assert state.state == 'not set'
|
||||
assert state.attributes.get('nearest') == 'not set'
|
||||
assert state.attributes.get('dir_of_travel') == 'not set'
|
||||
|
||||
self.hass.states.set('proximity.' + prox, '0')
|
||||
self.hass.pool.block_till_done()
|
||||
state = self.hass.states.get('proximity.' + prox)
|
||||
assert state.state == '0'
|
||||
|
||||
def test_proximities_missing_devices(self):
|
||||
"""Test a list of proximities with one missing devices."""
|
||||
assert not proximity.setup(self.hass, {
|
||||
'proximity': [{
|
||||
'zone': 'home',
|
||||
'ignored_zones': {
|
||||
'work'
|
||||
},
|
||||
'devices': {
|
||||
'device_tracker.test1',
|
||||
'device_tracker.test2'
|
||||
},
|
||||
'tolerance': '1'
|
||||
}, {
|
||||
'zone': 'work',
|
||||
'tolerance': '1'
|
||||
}]
|
||||
})
|
||||
|
||||
def test_proximity(self):
|
||||
"""Test the proximity."""
|
||||
assert proximity.setup(self.hass, {
|
||||
|
||||
Reference in New Issue
Block a user