Owntracks: Use bluetooth_le as source_type if beacon was used for location change. (#11615)
* Use bluetooth_le source_type, if location was changed by beacon * No reason to do nested ifs * Added tests for source_type on owntracks * Fixed The Hound * Added test and fixed bug surfaced by test
This commit is contained in:
parent
0859e38bd5
commit
536424b0c8
2 changed files with 40 additions and 1 deletions
|
@ -15,7 +15,10 @@ import voluptuous as vol
|
|||
import homeassistant.components.mqtt as mqtt
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components import zone as zone_comp
|
||||
from homeassistant.components.device_tracker import PLATFORM_SCHEMA
|
||||
from homeassistant.components.device_tracker import (
|
||||
PLATFORM_SCHEMA, ATTR_SOURCE_TYPE, SOURCE_TYPE_BLUETOOTH_LE,
|
||||
SOURCE_TYPE_GPS
|
||||
)
|
||||
from homeassistant.const import STATE_HOME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.util import slugify, decorator
|
||||
|
@ -140,6 +143,11 @@ def _parse_see_args(message, subscribe_topic):
|
|||
kwargs['attributes']['tid'] = message['tid']
|
||||
if 'addr' in message:
|
||||
kwargs['attributes']['address'] = message['addr']
|
||||
if 't' in message:
|
||||
if message['t'] == 'c':
|
||||
kwargs['attributes'][ATTR_SOURCE_TYPE] = SOURCE_TYPE_GPS
|
||||
if message['t'] == 'b':
|
||||
kwargs['attributes'][ATTR_SOURCE_TYPE] = SOURCE_TYPE_BLUETOOTH_LE
|
||||
|
||||
return dev_id, kwargs
|
||||
|
||||
|
|
|
@ -316,6 +316,11 @@ class BaseMQTT(unittest.TestCase):
|
|||
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
||||
self.assertEqual(state.attributes.get('gps_accuracy'), accuracy)
|
||||
|
||||
def assert_location_source_type(self, source_type):
|
||||
"""Test the assertion of source_type."""
|
||||
state = self.hass.states.get(DEVICE_TRACKER_STATE)
|
||||
self.assertEqual(state.attributes.get('source_type'), source_type)
|
||||
|
||||
|
||||
class TestDeviceTrackerOwnTracks(BaseMQTT):
|
||||
"""Test the OwnTrack sensor."""
|
||||
|
@ -666,6 +671,32 @@ class TestDeviceTrackerOwnTracks(BaseMQTT):
|
|||
# Location update processed
|
||||
self.assert_location_state('outer')
|
||||
|
||||
def test_event_source_type_entry_exit(self):
|
||||
"""Test the entry and exit events of source type."""
|
||||
# Entering the owntrack circular region named "inner"
|
||||
self.send_message(EVENT_TOPIC, REGION_GPS_ENTER_MESSAGE)
|
||||
|
||||
# source_type should be gps when enterings using gps.
|
||||
self.assert_location_source_type('gps')
|
||||
|
||||
# owntracks shouldn't send beacon events with acc = 0
|
||||
self.send_message(EVENT_TOPIC, build_message(
|
||||
{'acc': 1}, REGION_BEACON_ENTER_MESSAGE))
|
||||
|
||||
# We should be able to enter a beacon zone even inside a gps zone
|
||||
self.assert_location_source_type('bluetooth_le')
|
||||
|
||||
self.send_message(EVENT_TOPIC, REGION_GPS_LEAVE_MESSAGE)
|
||||
|
||||
# source_type should be gps when leaving using gps.
|
||||
self.assert_location_source_type('gps')
|
||||
|
||||
# owntracks shouldn't send beacon events with acc = 0
|
||||
self.send_message(EVENT_TOPIC, build_message(
|
||||
{'acc': 1}, REGION_BEACON_LEAVE_MESSAGE))
|
||||
|
||||
self.assert_location_source_type('bluetooth_le')
|
||||
|
||||
# Region Beacon based event entry / exit testing
|
||||
|
||||
def test_event_region_entry_exit(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue