diff --git a/bimmer_connected/models.py b/bimmer_connected/models.py index 4a6adaf6..f9506b2e 100644 --- a/bimmer_connected/models.py +++ b/bimmer_connected/models.py @@ -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() diff --git a/bimmer_connected/tests/responses/remote_services/eadrax_service_eventposition.json b/bimmer_connected/tests/responses/remote_services/eadrax_service_eventposition.json index c737d608..3d58948f 100644 --- a/bimmer_connected/tests/responses/remote_services/eadrax_service_eventposition.json +++ b/bimmer_connected/tests/responses/remote_services/eadrax_service_eventposition.json @@ -2,7 +2,7 @@ "positionData": { "status": "OK", "position": { - "latitude": 123.456, + "latitude": 12.345, "longitude": 34.5678, "formattedAddress": "some_formatted_address", "heading": 121 diff --git a/bimmer_connected/tests/test_remote_services.py b/bimmer_connected/tests/test_remote_services.py index 7f563b3a..b377b88a 100644 --- a/bimmer_connected/tests/test_remote_services.py +++ b/bimmer_connected/tests/test_remote_services.py @@ -320,12 +320,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 diff --git a/bimmer_connected/tests/test_vehicle.py b/bimmer_connected/tests/test_vehicle.py index c1f3d53e..9897a94c 100644 --- a/bimmer_connected/tests/test_vehicle.py +++ b/bimmer_connected/tests/test_vehicle.py @@ -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):