mirror of
https://github.com/elisspace/core.git
synced 2026-09-29 13:59:54 +00:00
Mobile app device tracker to restore state (#24266)
This commit is contained in:
committed by
Pascal Vizeli
parent
d2d3f27f85
commit
5f3bcedbba
@@ -22,7 +22,7 @@ async def test_sending_location(hass, create_registrations, webhook_client):
|
||||
|
||||
assert resp.status == 200
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('device_tracker.test_1')
|
||||
state = hass.states.get('device_tracker.test_1_2')
|
||||
assert state is not None
|
||||
assert state.name == 'Test 1'
|
||||
assert state.state == 'bar'
|
||||
@@ -54,7 +54,7 @@ async def test_sending_location(hass, create_registrations, webhook_client):
|
||||
|
||||
assert resp.status == 200
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('device_tracker.test_1')
|
||||
state = hass.states.get('device_tracker.test_1_2')
|
||||
assert state is not None
|
||||
assert state.state == 'not_home'
|
||||
assert state.attributes['source_type'] == 'gps'
|
||||
@@ -66,3 +66,51 @@ async def test_sending_location(hass, create_registrations, webhook_client):
|
||||
assert state.attributes['course'] == 6
|
||||
assert state.attributes['speed'] == 7
|
||||
assert state.attributes['vertical_accuracy'] == 8
|
||||
|
||||
|
||||
async def test_restoring_location(hass, create_registrations, webhook_client):
|
||||
"""Test sending a location via a webhook."""
|
||||
resp = await webhook_client.post(
|
||||
'/api/webhook/{}'.format(create_registrations[1]['webhook_id']),
|
||||
json={
|
||||
'type': 'update_location',
|
||||
'data': {
|
||||
'gps': [10, 20],
|
||||
'gps_accuracy': 30,
|
||||
'battery': 40,
|
||||
'altitude': 50,
|
||||
'course': 60,
|
||||
'speed': 70,
|
||||
'vertical_accuracy': 80,
|
||||
'location_name': 'bar',
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
assert resp.status == 200
|
||||
await hass.async_block_till_done()
|
||||
state_1 = hass.states.get('device_tracker.test_1_2')
|
||||
assert state_1 is not None
|
||||
|
||||
config_entry = hass.config_entries.async_entries('mobile_app')[1]
|
||||
|
||||
# mobile app doesn't support unloading, so we just reload device tracker
|
||||
await hass.config_entries.async_forward_entry_unload(config_entry,
|
||||
'device_tracker')
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry,
|
||||
'device_tracker')
|
||||
|
||||
state_2 = hass.states.get('device_tracker.test_1_2')
|
||||
assert state_2 is not None
|
||||
|
||||
assert state_1 is not state_2
|
||||
assert state_2.name == 'Test 1'
|
||||
assert state_2.attributes['source_type'] == 'gps'
|
||||
assert state_2.attributes['latitude'] == 10
|
||||
assert state_2.attributes['longitude'] == 20
|
||||
assert state_2.attributes['gps_accuracy'] == 30
|
||||
assert state_2.attributes['battery_level'] == 40
|
||||
assert state_2.attributes['altitude'] == 50
|
||||
assert state_2.attributes['course'] == 60
|
||||
assert state_2.attributes['speed'] == 70
|
||||
assert state_2.attributes['vertical_accuracy'] == 80
|
||||
|
||||
Reference in New Issue
Block a user