Added test for Owntracks waypoints import
This commit is contained in:
parent
1ada7d6211
commit
e6b7511e7d
2 changed files with 38 additions and 2 deletions
|
@ -36,6 +36,7 @@ VALIDATE_TRANSITION = 'transition'
|
||||||
|
|
||||||
CONF_WAYPOINT_IMPORT_USER = 'waypoint_import_user'
|
CONF_WAYPOINT_IMPORT_USER = 'waypoint_import_user'
|
||||||
|
|
||||||
|
|
||||||
def setup_scanner(hass, config, see):
|
def setup_scanner(hass, config, see):
|
||||||
"""Setup an OwnTracks tracker."""
|
"""Setup an OwnTracks tracker."""
|
||||||
max_gps_accuracy = config.get(CONF_MAX_GPS_ACCURACY)
|
max_gps_accuracy = config.get(CONF_MAX_GPS_ACCURACY)
|
||||||
|
@ -218,7 +219,7 @@ def setup_scanner(hass, config, see):
|
||||||
|
|
||||||
if waypoint_import_user is not None:
|
if waypoint_import_user is not None:
|
||||||
mqtt.subscribe(hass, WAYPOINT_TOPIC.format(waypoint_import_user),
|
mqtt.subscribe(hass, WAYPOINT_TOPIC.format(waypoint_import_user),
|
||||||
owntracks_waypoint_update, 1)
|
owntracks_waypoint_update, 1)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ DEVICE = 'phone'
|
||||||
|
|
||||||
LOCATION_TOPIC = "owntracks/{}/{}".format(USER, DEVICE)
|
LOCATION_TOPIC = "owntracks/{}/{}".format(USER, DEVICE)
|
||||||
EVENT_TOPIC = "owntracks/{}/{}/event".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)
|
DEVICE_TRACKER_STATE = "device_tracker.{}_{}".format(USER, DEVICE)
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ IBEACON_DEVICE = 'keys'
|
||||||
REGION_TRACKER_STATE = "device_tracker.beacon_{}".format(IBEACON_DEVICE)
|
REGION_TRACKER_STATE = "device_tracker.beacon_{}".format(IBEACON_DEVICE)
|
||||||
|
|
||||||
CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy'
|
CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy'
|
||||||
|
CONF_WAYPOINT_IMPORT_USER = 'waypoint_import_user'
|
||||||
|
|
||||||
LOCATION_MESSAGE = {
|
LOCATION_MESSAGE = {
|
||||||
'batt': 92,
|
'batt': 92,
|
||||||
|
@ -107,6 +109,28 @@ REGION_LEAVE_INACCURATE_MESSAGE = {
|
||||||
'lat': 20.0,
|
'lat': 20.0,
|
||||||
'_type': 'transition'}
|
'_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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
REGION_ENTER_ZERO_MESSAGE = {
|
REGION_ENTER_ZERO_MESSAGE = {
|
||||||
'lon': 1.0,
|
'lon': 1.0,
|
||||||
|
@ -143,7 +167,8 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
|
||||||
self.assertTrue(device_tracker.setup(self.hass, {
|
self.assertTrue(device_tracker.setup(self.hass, {
|
||||||
device_tracker.DOMAIN: {
|
device_tracker.DOMAIN: {
|
||||||
CONF_PLATFORM: 'owntracks',
|
CONF_PLATFORM: 'owntracks',
|
||||||
CONF_MAX_GPS_ACCURACY: 200
|
CONF_MAX_GPS_ACCURACY: 200,
|
||||||
|
CONF_WAYPOINT_IMPORT_USER: USER
|
||||||
}}))
|
}}))
|
||||||
|
|
||||||
self.hass.states.set(
|
self.hass.states.set(
|
||||||
|
@ -530,3 +555,13 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
|
||||||
self.send_message(EVENT_TOPIC, exit_message)
|
self.send_message(EVENT_TOPIC, exit_message)
|
||||||
|
|
||||||
self.assertEqual(owntracks.MOBILE_BEACONS_ACTIVE['greg_phone'], [])
|
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