mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Person ble_trackers for non-home zones not processed correctly (#138475)
Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
7fbf25e862
commit
ee8830cc77
@ -27,7 +27,6 @@ from homeassistant.const import (
|
|||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
STATE_HOME,
|
STATE_HOME,
|
||||||
STATE_NOT_HOME,
|
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
@ -526,7 +525,7 @@ class Person(
|
|||||||
latest_gps = _get_latest(latest_gps, state)
|
latest_gps = _get_latest(latest_gps, state)
|
||||||
elif state.state == STATE_HOME:
|
elif state.state == STATE_HOME:
|
||||||
latest_non_gps_home = _get_latest(latest_non_gps_home, state)
|
latest_non_gps_home = _get_latest(latest_non_gps_home, state)
|
||||||
elif state.state == STATE_NOT_HOME:
|
else:
|
||||||
latest_not_home = _get_latest(latest_not_home, state)
|
latest_not_home = _get_latest(latest_not_home, state)
|
||||||
|
|
||||||
if latest_non_gps_home:
|
if latest_non_gps_home:
|
||||||
|
@ -244,6 +244,81 @@ async def test_setup_two_trackers(
|
|||||||
assert state.attributes.get(ATTR_SOURCE) == DEVICE_TRACKER
|
assert state.attributes.get(ATTR_SOURCE) == DEVICE_TRACKER
|
||||||
|
|
||||||
|
|
||||||
|
async def test_setup_router_ble_trackers(
|
||||||
|
hass: HomeAssistant, hass_admin_user: MockUser
|
||||||
|
) -> None:
|
||||||
|
"""Test router and BLE trackers."""
|
||||||
|
# BLE trackers are considered stationary trackers; however unlike a router based tracker
|
||||||
|
# whose states are home and not_home, a BLE tracker may have the value of any zone that the
|
||||||
|
# beacon is configured for.
|
||||||
|
hass.set_state(CoreState.not_running)
|
||||||
|
user_id = hass_admin_user.id
|
||||||
|
config = {
|
||||||
|
DOMAIN: {
|
||||||
|
"id": "1234",
|
||||||
|
"name": "tracked person",
|
||||||
|
"user_id": user_id,
|
||||||
|
"device_trackers": [DEVICE_TRACKER, DEVICE_TRACKER_2],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert await async_setup_component(hass, DOMAIN, config)
|
||||||
|
|
||||||
|
state = hass.states.get("person.tracked_person")
|
||||||
|
assert state.state == STATE_UNKNOWN
|
||||||
|
assert state.attributes.get(ATTR_ID) == "1234"
|
||||||
|
assert state.attributes.get(ATTR_LATITUDE) is None
|
||||||
|
assert state.attributes.get(ATTR_LONGITUDE) is None
|
||||||
|
assert state.attributes.get(ATTR_SOURCE) is None
|
||||||
|
assert state.attributes.get(ATTR_USER_ID) == user_id
|
||||||
|
|
||||||
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
hass.states.async_set(
|
||||||
|
DEVICE_TRACKER, "not_home", {ATTR_SOURCE_TYPE: SourceType.ROUTER}
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get("person.tracked_person")
|
||||||
|
assert state.state == "not_home"
|
||||||
|
assert state.attributes.get(ATTR_ID) == "1234"
|
||||||
|
assert state.attributes.get(ATTR_LATITUDE) is None
|
||||||
|
assert state.attributes.get(ATTR_LONGITUDE) is None
|
||||||
|
assert state.attributes.get(ATTR_GPS_ACCURACY) is None
|
||||||
|
assert state.attributes.get(ATTR_SOURCE) == DEVICE_TRACKER
|
||||||
|
assert state.attributes.get(ATTR_USER_ID) == user_id
|
||||||
|
assert state.attributes.get(ATTR_DEVICE_TRACKERS) == [
|
||||||
|
DEVICE_TRACKER,
|
||||||
|
DEVICE_TRACKER_2,
|
||||||
|
]
|
||||||
|
|
||||||
|
# Set the BLE tracker to the "office" zone.
|
||||||
|
hass.states.async_set(
|
||||||
|
DEVICE_TRACKER_2,
|
||||||
|
"office",
|
||||||
|
{
|
||||||
|
ATTR_LATITUDE: 12.123456,
|
||||||
|
ATTR_LONGITUDE: 13.123456,
|
||||||
|
ATTR_GPS_ACCURACY: 12,
|
||||||
|
ATTR_SOURCE_TYPE: SourceType.BLUETOOTH_LE,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# The person should be in the office.
|
||||||
|
state = hass.states.get("person.tracked_person")
|
||||||
|
assert state.state == "office"
|
||||||
|
assert state.attributes.get(ATTR_ID) == "1234"
|
||||||
|
assert state.attributes.get(ATTR_LATITUDE) == 12.123456
|
||||||
|
assert state.attributes.get(ATTR_LONGITUDE) == 13.123456
|
||||||
|
assert state.attributes.get(ATTR_GPS_ACCURACY) == 12
|
||||||
|
assert state.attributes.get(ATTR_SOURCE) == DEVICE_TRACKER_2
|
||||||
|
assert state.attributes.get(ATTR_USER_ID) == user_id
|
||||||
|
assert state.attributes.get(ATTR_DEVICE_TRACKERS) == [
|
||||||
|
DEVICE_TRACKER,
|
||||||
|
DEVICE_TRACKER_2,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_ignore_unavailable_states(
|
async def test_ignore_unavailable_states(
|
||||||
hass: HomeAssistant, hass_admin_user: MockUser
|
hass: HomeAssistant, hass_admin_user: MockUser
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user