mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
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:
parent
7260cada90
commit
3da0f5e384
@ -9,7 +9,7 @@ from homeassistant.const import (
|
|||||||
ATTR_BATTERY_LEVEL,
|
ATTR_BATTERY_LEVEL,
|
||||||
)
|
)
|
||||||
from homeassistant.components.device_tracker.const import (
|
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 (
|
from homeassistant.components.device_tracker.config_entry import (
|
||||||
DeviceTrackerEntity
|
DeviceTrackerEntity
|
||||||
)
|
)
|
||||||
@ -127,7 +127,7 @@ class OwnTracksEntity(DeviceTrackerEntity, RestoreEntity):
|
|||||||
@property
|
@property
|
||||||
def source_type(self):
|
def source_type(self):
|
||||||
"""Return the source type, eg gps or router, of the device."""
|
"""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
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
|
@ -411,6 +411,19 @@ async def test_location_update(hass, context):
|
|||||||
"""Test the update of a location."""
|
"""Test the update of a location."""
|
||||||
await send_message(hass, LOCATION_TOPIC, LOCATION_MESSAGE)
|
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_latitude(hass, LOCATION_MESSAGE['lat'])
|
||||||
assert_location_accuracy(hass, LOCATION_MESSAGE['acc'])
|
assert_location_accuracy(hass, LOCATION_MESSAGE['acc'])
|
||||||
assert_location_state(hass, 'outer')
|
assert_location_state(hass, 'outer')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user