diff --git a/homeassistant/components/owntracks/device_tracker.py b/homeassistant/components/owntracks/device_tracker.py index 742b7c34435..b573e390a12 100644 --- a/homeassistant/components/owntracks/device_tracker.py +++ b/homeassistant/components/owntracks/device_tracker.py @@ -9,7 +9,7 @@ from homeassistant.const import ( ATTR_BATTERY_LEVEL, ) from homeassistant.components.device_tracker.const import ( - ENTITY_ID_FORMAT, ATTR_SOURCE_TYPE) + ENTITY_ID_FORMAT, ATTR_SOURCE_TYPE, SOURCE_TYPE_GPS) from homeassistant.components.device_tracker.config_entry import ( DeviceTrackerEntity ) @@ -127,7 +127,7 @@ class OwnTracksEntity(DeviceTrackerEntity, RestoreEntity): @property def source_type(self): """Return the source type, eg gps or router, of the device.""" - return self._data.get('source_type') + return self._data.get('source_type', SOURCE_TYPE_GPS) @property def device_info(self): diff --git a/tests/components/owntracks/test_device_tracker.py b/tests/components/owntracks/test_device_tracker.py index 7d8d48de586..5f2bda5957a 100644 --- a/tests/components/owntracks/test_device_tracker.py +++ b/tests/components/owntracks/test_device_tracker.py @@ -411,6 +411,19 @@ async def test_location_update(hass, context): """Test the update of a location.""" await send_message(hass, LOCATION_TOPIC, LOCATION_MESSAGE) + assert_location_source_type(hass, 'gps') + assert_location_latitude(hass, LOCATION_MESSAGE['lat']) + assert_location_accuracy(hass, LOCATION_MESSAGE['acc']) + assert_location_state(hass, 'outer') + + +async def test_location_update_no_t_key(hass, context): + """Test the update of a location when message does not contain 't'.""" + message = LOCATION_MESSAGE.copy() + message.pop('t') + await send_message(hass, LOCATION_TOPIC, message) + + assert_location_source_type(hass, 'gps') assert_location_latitude(hass, LOCATION_MESSAGE['lat']) assert_location_accuracy(hass, LOCATION_MESSAGE['acc']) assert_location_state(hass, 'outer')