def vehicle(websession: aiohttp.ClientSession) -> RenaultVehicle: """Fixture for testing RenaultVehicle.""" return RenaultVehicle( account_id=TEST_ACCOUNT_ID, vin=TEST_VIN, session=get_logged_in_session(websession), )
def test_init(websession: aiohttp.ClientSession) -> None: """Test RenaultVehicle initialisation.""" assert RenaultVehicle( account_id=TEST_ACCOUNT_ID, vin=TEST_VIN, session=get_logged_in_session(websession), ) assert RenaultVehicle( account_id=TEST_ACCOUNT_ID, vin=TEST_VIN, websession=websession, country=TEST_COUNTRY, locale_details=TEST_LOCALE_DETAILS, credential_store=get_logged_in_credential_store(), )
async def create_unavailable_vehicle_proxy( hass: HomeAssistant, vehicle_type: str ) -> RenaultVehicleProxy: """Create a vehicle proxy for testing unavailable entities.""" mock_vehicle = MOCK_VEHICLES[vehicle_type] vehicles_response: models.KamereonVehiclesResponse = ( schemas.KamereonVehiclesResponseSchema.loads( load_fixture(f"vehicle_{vehicle_type}.json") ) ) vehicle_details = vehicles_response.vehicleLinks[0].vehicleDetails vehicle = RenaultVehicle( vehicles_response.accountId, vehicle_details.vin, websession=aiohttp_client.async_get_clientsession(hass), ) invalid_upstream_exception = exceptions.InvalidUpstreamException( "err.tech.500", "Invalid response from the upstream server (The request sent to the GDC is erroneous) ; 502 Bad Gateway", ) vehicle_proxy = RenaultVehicleProxy( hass, vehicle, vehicle_details, timedelta(seconds=300), False ) with patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.endpoint_available", side_effect=mock_vehicle["endpoints_available"], ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_cockpit", side_effect=invalid_upstream_exception, ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_hvac_status", side_effect=invalid_upstream_exception, ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_battery_status", side_effect=invalid_upstream_exception, ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_charge_mode", side_effect=invalid_upstream_exception, ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_location", side_effect=invalid_upstream_exception, ): await vehicle_proxy.async_initialise() return vehicle_proxy
async def create_vehicle_proxy(hass: HomeAssistant, vehicle_type: str) -> RenaultVehicleProxy: """Create a vehicle proxy for testing.""" mock_vehicle = MOCK_VEHICLES[vehicle_type] mock_fixtures = get_fixtures(vehicle_type) vehicles_response: models.KamereonVehiclesResponse = ( schemas.KamereonVehiclesResponseSchema.loads( load_fixture(f"renault/vehicle_{vehicle_type}.json"))) vehicle_details = vehicles_response.vehicleLinks[0].vehicleDetails vehicle = RenaultVehicle( vehicles_response.accountId, vehicle_details.vin, websession=aiohttp_client.async_get_clientsession(hass), ) vehicle_proxy = RenaultVehicleProxy(hass, vehicle, vehicle_details, timedelta(seconds=300)) with patch( "homeassistant.components.renault.renault_vehicle.RenaultVehicleProxy.endpoint_available", side_effect=mock_vehicle["endpoints_available"], ), patch( "homeassistant.components.renault.renault_vehicle.RenaultVehicleProxy.get_battery_status", return_value=mock_fixtures["battery_status"], ), patch( "homeassistant.components.renault.renault_vehicle.RenaultVehicleProxy.get_charge_mode", return_value=mock_fixtures["charge_mode"], ), patch( "homeassistant.components.renault.renault_vehicle.RenaultVehicleProxy.get_cockpit", return_value=mock_fixtures["cockpit"], ), patch( "homeassistant.components.renault.renault_vehicle.RenaultVehicleProxy.get_hvac_status", return_value=mock_fixtures["hvac_status"], ): await vehicle_proxy.async_initialise() return vehicle_proxy
async def create_vehicle_proxy( hass: HomeAssistant, vehicle_type: str ) -> RenaultVehicleProxy: """Create a vehicle proxy for testing.""" mock_vehicle = MOCK_VEHICLES[vehicle_type] mock_get_cockpit = schemas.KamereonVehicleDataResponseSchema.loads( load_fixture(mock_vehicle["endpoints"]["cockpit"]) if "cockpit" in mock_vehicle["endpoints"] else "{}" ).get_attributes(schemas.KamereonVehicleCockpitDataSchema) mock_get_hvac_status = schemas.KamereonVehicleDataResponseSchema.loads( load_fixture(mock_vehicle["endpoints"]["hvac_status"]) if "hvac_status" in mock_vehicle["endpoints"] else "{}" ).get_attributes(schemas.KamereonVehicleHvacStatusDataSchema) mock_get_battery_status = schemas.KamereonVehicleDataResponseSchema.loads( load_fixture(mock_vehicle["endpoints"]["battery_status"]) if "battery_status" in mock_vehicle["endpoints"] else "{}" ).get_attributes(schemas.KamereonVehicleBatteryStatusDataSchema) mock_get_charge_mode = schemas.KamereonVehicleDataResponseSchema.loads( load_fixture(mock_vehicle["endpoints"]["charge_mode"]) if "charge_mode" in mock_vehicle["endpoints"] else "{}" ).get_attributes(schemas.KamereonVehicleChargeModeDataSchema) mock_get_location = schemas.KamereonVehicleDataResponseSchema.loads( load_fixture(mock_vehicle["endpoints"]["location"]) if "location" in mock_vehicle["endpoints"] else "{}" ).get_attributes(schemas.KamereonVehicleLocationDataSchema) vehicles_response: models.KamereonVehiclesResponse = ( schemas.KamereonVehiclesResponseSchema.loads( load_fixture(f"vehicle_{vehicle_type}.json") ) ) vehicle_details = vehicles_response.vehicleLinks[0].vehicleDetails vehicle = RenaultVehicle( vehicles_response.accountId, vehicle_details.vin, websession=aiohttp_client.async_get_clientsession(hass), ) vehicle_proxy = RenaultVehicleProxy( hass, vehicle, vehicle_details, timedelta(seconds=300), False ) with patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.endpoint_available", side_effect=mock_vehicle["endpoints_available"], ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_cockpit", return_value=mock_get_cockpit, ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_hvac_status", return_value=mock_get_hvac_status, ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_battery_status", return_value=mock_get_battery_status, ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_charge_mode", return_value=mock_get_charge_mode, ), patch( "custom_components.renault.renault_vehicle.RenaultVehicleProxy.get_location", return_value=mock_get_location, ): await vehicle_proxy.async_initialise() return vehicle_proxy