Added test for Owntracks waypoints import
This commit is contained in:
parent
75e6ed87d6
commit
2bea5a484f
2 changed files with 38 additions and 2 deletions
|
@ -32,6 +32,7 @@ LOCK = threading.Lock()
|
|||
CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy'
|
||||
CONF_WAYPOINT_IMPORT_USER = 'waypoint_import_user'
|
||||
|
||||
|
||||
def setup_scanner(hass, config, see):
|
||||
"""Setup an OwnTracks tracker."""
|
||||
max_gps_accuracy = config.get(CONF_MAX_GPS_ACCURACY)
|
||||
|
@ -203,7 +204,7 @@ def setup_scanner(hass, config, see):
|
|||
|
||||
if waypoint_import_user is not None:
|
||||
mqtt.subscribe(hass, WAYPOINT_TOPIC.format(waypoint_import_user),
|
||||
owntracks_waypoint_update, 1)
|
||||
owntracks_waypoint_update, 1)
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ DEVICE = 'phone'
|
|||
|
||||
LOCATION_TOPIC = "owntracks/{}/{}".format(USER, DEVICE)
|
||||
EVENT_TOPIC = "owntracks/{}/{}/event".format(USER, DEVICE)
|
||||
WAYPOINT_TOPIC = 'owntracks/{}/{}/waypoint'.format(USER, DEVICE)
|
||||
|
||||
DEVICE_TRACKER_STATE = "device_tracker.{}_{}".format(USER, DEVICE)
|
||||
|
||||
|
@ -24,6 +25,7 @@ IBEACON_DEVICE = 'keys'
|
|||
REGION_TRACKER_STATE = "device_tracker.beacon_{}".format(IBEACON_DEVICE)
|
||||
|
||||
CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy'
|
||||
CONF_WAYPOINT_IMPORT_USER = 'waypoint_import_user'
|
||||
|
||||
LOCATION_MESSAGE = {
|
||||
'batt': 92,
|
||||
|
@ -107,6 +109,28 @@ REGION_LEAVE_INACCURATE_MESSAGE = {
|
|||
'lat': 20.0,
|
||||
'_type': 'transition'}
|
||||
|
||||
WAYPOINTS_EXPORTED_MESSAGE = {
|
||||
"_type": "waypoints",
|
||||
"_creator": "test",
|
||||
"waypoints": [
|
||||
{
|
||||
"_type": "waypoint",
|
||||
"tst": 3,
|
||||
"lat": 47,
|
||||
"lon": 9,
|
||||
"rad": 10,
|
||||
"desc": "exp_wayp1"
|
||||
},
|
||||
{
|
||||
"_type": "waypoint",
|
||||
"tst": 4,
|
||||
"lat": 3,
|
||||
"lon": 9,
|
||||
"rad": 500,
|
||||
"desc": "exp_wayp2"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
class TestDeviceTrackerOwnTracks(unittest.TestCase):
|
||||
"""Test the OwnTrack sensor."""
|
||||
|
@ -118,7 +142,8 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
|
|||
self.assertTrue(device_tracker.setup(self.hass, {
|
||||
device_tracker.DOMAIN: {
|
||||
CONF_PLATFORM: 'owntracks',
|
||||
CONF_MAX_GPS_ACCURACY: 200
|
||||
CONF_MAX_GPS_ACCURACY: 200,
|
||||
CONF_WAYPOINT_IMPORT_USER: USER
|
||||
}}))
|
||||
|
||||
self.hass.states.set(
|
||||
|
@ -486,3 +511,13 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
|
|||
self.send_message(EVENT_TOPIC, exit_message)
|
||||
|
||||
self.assertEqual(owntracks.MOBILE_BEACONS_ACTIVE['greg_phone'], [])
|
||||
|
||||
def test_waypoint_import_simple(self):
|
||||
"""Test a simple import of list of waypoints."""
|
||||
waypoints_message = WAYPOINTS_EXPORTED_MESSAGE.copy()
|
||||
self.send_message(WAYPOINT_TOPIC, waypoints_message)
|
||||
# Check if it made it into states
|
||||
wayp = self.hass.states.get('zone.exp_wayp1')
|
||||
self.assertTrue(wayp != None)
|
||||
wayp = self.hass.states.get('zone.exp_wayp2')
|
||||
self.assertTrue(wayp != None)
|
||||
|
|
Loading…
Add table
Reference in a new issue