def tests_init(websession: aiohttp.ClientSession) -> None: """Test RenaultAccount initialisation.""" assert RenaultAccount( account_id=TEST_ACCOUNT_ID, session=get_logged_in_session(websession), ) assert RenaultAccount( account_id=TEST_ACCOUNT_ID, websession=websession, country=TEST_COUNTRY, locale_details=TEST_LOCALE_DETAILS, credential_store=get_logged_in_credential_store(), )
async def test_config_flow_multiple_accounts(hass: HomeAssistant): """Test what happens if multiple Kamereon accounts are available.""" with patch( "homeassistant.components.renault.async_setup_entry", return_value=True, ) as mock_setup_entry: result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"] == {} renault_account_1 = RenaultAccount( "account_id_1", websession=aiohttp_client.async_get_clientsession(hass), ) renault_account_2 = RenaultAccount( "account_id_2", websession=aiohttp_client.async_get_clientsession(hass), ) # Multiple accounts with patch("renault_api.renault_session.RenaultSession.login"), patch( "renault_api.renault_client.RenaultClient.get_api_accounts", return_value=[renault_account_1, renault_account_2], ), patch("renault_api.renault_account.RenaultAccount.get_vehicles"): result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={ CONF_LOCALE: "fr_FR", CONF_USERNAME: "******", CONF_PASSWORD: "******", }, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "kamereon" # Account selected result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={CONF_KAMEREON_ACCOUNT_ID: "account_id_2"}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "account_id_2" assert result["data"][CONF_USERNAME] == "*****@*****.**" assert result["data"][CONF_PASSWORD] == "test" assert result["data"][CONF_KAMEREON_ACCOUNT_ID] == "account_id_2" assert result["data"][CONF_LOCALE] == "fr_FR" assert len(mock_setup_entry.mock_calls) == 1
async def test_config_flow_duplicate(hass: HomeAssistant, mock_setup_entry: AsyncMock): """Test abort if unique_id configured.""" assert len(hass.config_entries.async_entries(DOMAIN)) == 1 result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"] == {} renault_account = RenaultAccount( "account_id_1", websession=aiohttp_client.async_get_clientsession(hass), ) with patch("renault_api.renault_session.RenaultSession.login"), patch( "renault_api.renault_client.RenaultClient.get_api_accounts", return_value=[renault_account], ), patch("renault_api.renault_account.RenaultAccount.get_vehicles"): result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={ CONF_LOCALE: "fr_FR", CONF_USERNAME: "******", CONF_PASSWORD: "******", }, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" await hass.async_block_till_done() assert len(mock_setup_entry.mock_calls) == 0
async def patch_renault_account(hass: HomeAssistant) -> RenaultAccount: """Create a Renault account.""" renault_account = RenaultAccount( MOCK_ACCOUNT_ID, websession=aiohttp_client.async_get_clientsession(hass), ) with patch("renault_api.renault_session.RenaultSession.login"), patch( "renault_api.renault_client.RenaultClient.get_api_account", return_value=renault_account, ): yield renault_account
async def setup_renault_integration_vehicle_with_no_data( hass: HomeAssistant, vehicle_type: str ): """Create the Renault integration.""" config_entry = get_mock_config_entry() config_entry.add_to_hass(hass) renault_account = RenaultAccount( config_entry.unique_id, websession=aiohttp_client.async_get_clientsession(hass), ) mock_vehicle = MOCK_VEHICLES[vehicle_type] mock_fixtures = get_fixtures("") with patch("renault_api.renault_session.RenaultSession.login"), patch( "renault_api.renault_client.RenaultClient.get_api_account", return_value=renault_account, ), patch( "renault_api.renault_account.RenaultAccount.get_vehicles", return_value=( schemas.KamereonVehiclesResponseSchema.loads( load_fixture(f"renault/vehicle_{vehicle_type}.json") ) ), ), patch( "renault_api.renault_vehicle.RenaultVehicle.supports_endpoint", side_effect=mock_vehicle["endpoints_available"], ), patch( "renault_api.renault_vehicle.RenaultVehicle.has_contract_for_endpoint", return_value=True, ), patch( "renault_api.renault_vehicle.RenaultVehicle.get_battery_status", return_value=mock_fixtures["battery_status"], ), patch( "renault_api.renault_vehicle.RenaultVehicle.get_charge_mode", return_value=mock_fixtures["charge_mode"], ), patch( "renault_api.renault_vehicle.RenaultVehicle.get_cockpit", return_value=mock_fixtures["cockpit"], ), patch( "renault_api.renault_vehicle.RenaultVehicle.get_hvac_status", return_value=mock_fixtures["hvac_status"], ), patch( "renault_api.renault_vehicle.RenaultVehicle.get_location", return_value=mock_fixtures["location"], ): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() return config_entry
async def setup_renault_integration_simple(hass: HomeAssistant): """Create the Renault integration.""" config_entry = get_mock_config_entry() config_entry.add_to_hass(hass) renault_account = RenaultAccount( config_entry.unique_id, websession=aiohttp_client.async_get_clientsession(hass), ) with patch("renault_api.renault_session.RenaultSession.login"), patch( "renault_api.renault_client.RenaultClient.get_api_account", return_value=renault_account, ), patch("renault_api.renault_account.RenaultAccount.get_vehicles"): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() return config_entry
def account(websession: aiohttp.ClientSession) -> RenaultAccount: """Fixture for testing RenaultAccount.""" return RenaultAccount( account_id=TEST_ACCOUNT_ID, session=get_logged_in_session(websession), )