Allow negative altitude in location updates (#29381)
parent
a1a131334a
commit
f6780c1fa2
|
@ -160,7 +160,7 @@ UPDATE_LOCATION_SCHEMA = vol.Schema(
|
|||
vol.Required(ATTR_GPS_ACCURACY): cv.positive_int,
|
||||
vol.Optional(ATTR_BATTERY): cv.positive_int,
|
||||
vol.Optional(ATTR_SPEED): cv.positive_int,
|
||||
vol.Optional(ATTR_ALTITUDE): cv.positive_int,
|
||||
vol.Optional(ATTR_ALTITUDE): vol.Coerce(float),
|
||||
vol.Optional(ATTR_COURSE): cv.positive_int,
|
||||
vol.Optional(ATTR_VERTICAL_ACCURACY): cv.positive_int,
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ def registry(hass):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
async def create_registrations(authed_api_client):
|
||||
async def create_registrations(hass, authed_api_client):
|
||||
"""Return two new registrations."""
|
||||
enc_reg = await authed_api_client.post(
|
||||
"/api/mobile_app/registrations", json=REGISTER
|
||||
|
@ -34,6 +34,8 @@ async def create_registrations(authed_api_client):
|
|||
assert clear_reg.status == 201
|
||||
clear_reg_json = await clear_reg.json()
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return (enc_reg_json, clear_reg_json)
|
||||
|
||||
|
||||
|
|
|
@ -216,3 +216,23 @@ async def test_webhook_requires_encryption(webhook_client, create_registrations)
|
|||
assert "error" in webhook_json
|
||||
assert webhook_json["success"] is False
|
||||
assert webhook_json["error"]["code"] == "encryption_required"
|
||||
|
||||
|
||||
async def test_webhook_update_location(hass, webhook_client, create_registrations):
|
||||
"""Test that encrypted registrations only accept encrypted data."""
|
||||
resp = await webhook_client.post(
|
||||
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
|
||||
json={
|
||||
"type": "update_location",
|
||||
"data": {"gps": [1, 2], "gps_accuracy": 10, "altitude": -10},
|
||||
},
|
||||
)
|
||||
|
||||
assert resp.status == 200
|
||||
|
||||
state = hass.states.get("device_tracker.test_1_2")
|
||||
assert state is not None
|
||||
assert state.attributes["latitude"] == 1.0
|
||||
assert state.attributes["longitude"] == 2.0
|
||||
assert state.attributes["gps_accuracy"] == 10
|
||||
assert state.attributes["altitude"] == -10
|
||||
|
|
Loading…
Reference in New Issue