Skip to content

Commit

Permalink
Update GPS position verification
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe committed Aug 3, 2024
1 parent 812aa5a commit d145816
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
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

0 comments on commit d145816

Please sign in to comment.