Add restore state to Geofency (#24268)
* Add restore state to Geofency * Lint
This commit is contained in:
parent
411e36b0f8
commit
6a693546a3
2 changed files with 55 additions and 15 deletions
|
@ -5,13 +5,12 @@ from unittest.mock import patch, Mock
|
|||
import pytest
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components import zone, geofency
|
||||
from homeassistant.components import zone
|
||||
from homeassistant.components.geofency import (
|
||||
CONF_MOBILE_BEACONS, DOMAIN, TRACKER_UPDATE)
|
||||
CONF_MOBILE_BEACONS, DOMAIN)
|
||||
from homeassistant.const import (
|
||||
HTTP_OK, HTTP_UNPROCESSABLE_ENTITY, STATE_HOME,
|
||||
STATE_NOT_HOME)
|
||||
from homeassistant.helpers.dispatcher import DATA_DISPATCHER
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import slugify
|
||||
|
||||
|
@ -291,9 +290,6 @@ async def test_beacon_enter_and_exit_car(hass, geofency_client, webhook_id):
|
|||
assert STATE_HOME == state_name
|
||||
|
||||
|
||||
@pytest.mark.xfail(
|
||||
reason='The device_tracker component does not support unloading yet.'
|
||||
)
|
||||
async def test_load_unload_entry(hass, geofency_client, webhook_id):
|
||||
"""Test that the appropriate dispatch signals are added and removed."""
|
||||
url = '/api/webhook/{}'.format(webhook_id)
|
||||
|
@ -303,13 +299,23 @@ async def test_load_unload_entry(hass, geofency_client, webhook_id):
|
|||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify(GPS_ENTER_HOME['device'])
|
||||
state_name = hass.states.get('{}.{}'.format(
|
||||
'device_tracker', device_name)).state
|
||||
assert STATE_HOME == state_name
|
||||
assert len(hass.data[DATA_DISPATCHER][TRACKER_UPDATE]) == 1
|
||||
state_1 = hass.states.get('{}.{}'.format('device_tracker', device_name))
|
||||
assert STATE_HOME == state_1.state
|
||||
|
||||
assert len(hass.data[DOMAIN]['devices']) == 1
|
||||
entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
|
||||
assert await geofency.async_unload_entry(hass, entry)
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert not hass.data[DATA_DISPATCHER][TRACKER_UPDATE]
|
||||
assert len(hass.data[DOMAIN]['devices']) == 0
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state_2 = hass.states.get('{}.{}'.format('device_tracker', device_name))
|
||||
assert state_2 is not None
|
||||
assert state_1 is not state_2
|
||||
|
||||
assert STATE_HOME == state_2.state
|
||||
assert state_2.attributes['latitude'] == HOME_LATITUDE
|
||||
assert state_2.attributes['longitude'] == HOME_LONGITUDE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue