Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow negative altitude in location updates #29381

Merged
merged 1 commit into from Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/mobile_app/const.py
Expand Up @@ -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,
}
Expand Down
4 changes: 3 additions & 1 deletion tests/components/mobile_app/conftest.py
Expand Up @@ -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
Expand All @@ -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)


Expand Down
20 changes: 20 additions & 0 deletions tests/components/mobile_app/test_webhook.py
Expand Up @@ -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