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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GPS position verification #646

Merged
merged 1 commit into from
Aug 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bimmer_connected/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def __post_init__(self):
value = getattr(self, field_name)
if value is not None and not isinstance(value, (float, int)):
raise TypeError(f"'{field_name}' not of type '{Optional[Union[float, int]]}'")
if field_name == "latitude" and not (-90 <= value <= 90):
raise ValueError(f"'latitude' must be between -90 and 90, but got '{value}'")
elif field_name == "longitude" and not (-180 <= value <= 180):
raise ValueError(f"'longitude' must be between -180 and 180, but got '{value}'")

def __iter__(self):
yield from self.__dict__.values()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"positionData": {
"status": "OK",
"position": {
"latitude": 123.456,
"latitude": 12.345,
"longitude": 34.5678,
"formattedAddress": "some_formatted_address",
"heading": 121
Expand Down
4 changes: 2 additions & 2 deletions bimmer_connected/tests/test_remote_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ async def test_get_remote_position(bmw_fixture: respx.Router):

# Check updated position
await vehicle.remote_services.trigger_remote_vehicle_finder()
assert location.location == (123.456, 34.5678)
assert location.location == (12.345, 34.5678)
assert location.heading == 121

# Position should still be from vehicle finder after status update
await account.get_vehicles()
assert location.location == (123.456, 34.5678)
assert location.location == (12.345, 34.5678)
assert location.heading == 121


Expand Down
12 changes: 12 additions & 0 deletions bimmer_connected/tests/test_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ def test_gpsposition():
assert pos != "(1, 2)"
assert pos[0] == 1

with pytest.raises(TypeError, match="Either none or all arguments must be 'None'."):
GPSPosition(1, None)

with pytest.raises(TypeError, match="'longitude' not of type"):
GPSPosition(0, "49.7")

with pytest.raises(ValueError, match="'latitude' must be between -90 and 90"):
GPSPosition(91, 0)

with pytest.raises(ValueError, match="'longitude' must be between -180 and 180"):
GPSPosition(90, 181)


@pytest.mark.asyncio
async def test_headunit_data(caplog, bmw_fixture: respx.Router):
Expand Down
Loading