Fix owntracks source_type for location messages with default trigger (#24503)

Some location update messages do not contain the 't' (trigger) key. Before the change in 0.94 to
entity based trackers, these would default to source_type of 'gps' (due to default parameter
value in async_see method.) To mirror this behavior in the new entity based tracker, the
source_type property should default to SOURCE_TYPE_GPS under the same conditions.
This commit is contained in:
Phil Bruckner 2019-06-12 13:40:01 -05:00 committed by Paulus Schoutsen
parent 7260cada90
commit 3da0f5e384
2 changed files with 15 additions and 2 deletions

View file

@ -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):

View file

@ -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')