parent
e736521e9f
commit
f2941522ca
1 changed files with 27 additions and 16 deletions
|
@ -1,24 +1,26 @@
|
|||
"""The tests for the person component."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.device_tracker import (
|
||||
ATTR_SOURCE_TYPE, SOURCE_TYPE_GPS, SOURCE_TYPE_ROUTER)
|
||||
from homeassistant.components.person import (
|
||||
ATTR_SOURCE, ATTR_USER_ID, DOMAIN, PersonManager)
|
||||
from homeassistant.const import (
|
||||
ATTR_ID, ATTR_LATITUDE, ATTR_LONGITUDE, ATTR_GPS_ACCURACY,
|
||||
STATE_UNKNOWN, EVENT_HOMEASSISTANT_START)
|
||||
from homeassistant.components.device_tracker import (
|
||||
ATTR_SOURCE_TYPE, SOURCE_TYPE_GPS, SOURCE_TYPE_ROUTER)
|
||||
ATTR_GPS_ACCURACY, ATTR_ID, ATTR_LATITUDE, ATTR_LONGITUDE,
|
||||
EVENT_HOMEASSISTANT_START, STATE_UNKNOWN)
|
||||
from homeassistant.core import CoreState, State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.common import mock_component, mock_restore_cache, mock_coro_func
|
||||
from tests.common import (
|
||||
assert_setup_component, mock_component, mock_coro_func, mock_restore_cache)
|
||||
|
||||
DEVICE_TRACKER = 'device_tracker.test_tracker'
|
||||
DEVICE_TRACKER_2 = 'device_tracker.test_tracker_2'
|
||||
|
||||
|
||||
# pylint: disable=redefined-outer-name
|
||||
@pytest.fixture
|
||||
def storage_setup(hass, hass_storage, hass_admin_user):
|
||||
"""Storage setup."""
|
||||
|
@ -44,7 +46,8 @@ def storage_setup(hass, hass_storage, hass_admin_user):
|
|||
async def test_minimal_setup(hass):
|
||||
"""Test minimal config with only name."""
|
||||
config = {DOMAIN: {'id': '1234', 'name': 'test person'}}
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
with assert_setup_component(1):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
state = hass.states.get('person.test_person')
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -71,7 +74,8 @@ async def test_setup_user_id(hass, hass_admin_user):
|
|||
user_id = hass_admin_user.id
|
||||
config = {
|
||||
DOMAIN: {'id': '1234', 'name': 'test person', 'user_id': user_id}}
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
with assert_setup_component(1):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
state = hass.states.get('person.test_person')
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -88,7 +92,8 @@ async def test_valid_invalid_user_ids(hass, hass_admin_user):
|
|||
config = {DOMAIN: [
|
||||
{'id': '1234', 'name': 'test valid user', 'user_id': user_id},
|
||||
{'id': '5678', 'name': 'test bad user', 'user_id': 'bad_user_id'}]}
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
with assert_setup_component(2):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
state = hass.states.get('person.test_valid_user')
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -108,7 +113,8 @@ async def test_setup_tracker(hass, hass_admin_user):
|
|||
config = {DOMAIN: {
|
||||
'id': '1234', 'name': 'tracked person', 'user_id': user_id,
|
||||
'device_trackers': DEVICE_TRACKER}}
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
with assert_setup_component(1):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
state = hass.states.get('person.tracked_person')
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -159,7 +165,8 @@ async def test_setup_two_trackers(hass, hass_admin_user):
|
|||
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)
|
||||
with assert_setup_component(1):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
state = hass.states.get('person.tracked_person')
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -231,7 +238,8 @@ async def test_ignore_unavailable_states(hass, hass_admin_user):
|
|||
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)
|
||||
with assert_setup_component(1):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
state = hass.states.get('person.tracked_person')
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -275,7 +283,8 @@ async def test_restore_home_state(hass, hass_admin_user):
|
|||
config = {DOMAIN: {
|
||||
'id': '1234', 'name': 'tracked person', 'user_id': user_id,
|
||||
'device_trackers': DEVICE_TRACKER}}
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
with assert_setup_component(1):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
state = hass.states.get('person.tracked_person')
|
||||
assert state.state == 'home'
|
||||
|
@ -292,7 +301,8 @@ async def test_duplicate_ids(hass, hass_admin_user):
|
|||
config = {DOMAIN: [
|
||||
{'id': '1234', 'name': 'test user 1'},
|
||||
{'id': '1234', 'name': 'test user 2'}]}
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
with assert_setup_component(2):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
assert len(hass.states.async_entity_ids('person')) == 1
|
||||
assert hass.states.get('person.test_user_1') is not None
|
||||
|
@ -302,7 +312,8 @@ async def test_duplicate_ids(hass, hass_admin_user):
|
|||
async def test_create_person_during_run(hass):
|
||||
"""Test that person is updated if created while hass is running."""
|
||||
config = {DOMAIN: {}}
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
with assert_setup_component(0):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
hass.states.async_set(DEVICE_TRACKER, 'home')
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue