diff --git a/homeassistant/components/mobile_app/const.py b/homeassistant/components/mobile_app/const.py index 0b6a93a39ea4cb..318076d5fd933d 100644 --- a/homeassistant/components/mobile_app/const.py +++ b/homeassistant/components/mobile_app/const.py @@ -160,7 +160,7 @@ 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, } diff --git a/tests/components/mobile_app/conftest.py b/tests/components/mobile_app/conftest.py index 33af3c2b4a76fd..1d653b73ba3a6c 100644 --- a/tests/components/mobile_app/conftest.py +++ b/tests/components/mobile_app/conftest.py @@ -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) diff --git a/tests/components/mobile_app/test_webhook.py b/tests/components/mobile_app/test_webhook.py index 1ea2d50d8d8208..6e8efe15dd0d2e 100644 --- a/tests/components/mobile_app/test_webhook.py +++ b/tests/components/mobile_app/test_webhook.py @@ -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