async def init_integration( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, rgbw: bool = False, skip_setup: bool = False, ) -> MockConfigEntry: """Set up the Atag integration in Home Assistant.""" aioclient_mock.get( "http://127.0.0.1:10000/retrieve", json=RECEIVE_REPLY, headers={"Content-Type": "application/json"}, ) aioclient_mock.post( "http://127.0.0.1:10000/update", json=UPDATE_REPLY, headers={"Content-Type": "application/json"}, ) aioclient_mock.post( "http://127.0.0.1:10000/pair", json=PAIR_REPLY, headers={"Content-Type": "application/json"}, ) entry = MockConfigEntry(domain=DOMAIN, data=USER_INPUT) entry.add_to_hass(hass) if not skip_setup: await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() return entry
async def test_offer_failure( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, hass_ws_client: Callable[[...], Awaitable[aiohttp.ClientWebSocketResponse]], mock_camera: Any, rtsp_to_webrtc_client: Any, setup_integration: ComponentSetup, ) -> None: """Test a transient failure talking to RTSPtoWebRTC server.""" await setup_integration() aioclient_mock.post( f"{SERVER_URL}/stream", exc=aiohttp.ClientError, ) client = await hass_ws_client(hass) await client.send_json( { "id": 2, "type": "camera/web_rtc_offer", "entity_id": "camera.demo_camera", "offer": OFFER_SDP, } ) response = await client.receive_json() assert response.get("id") == 2 assert response.get("type") == TYPE_RESULT assert "success" in response assert not response.get("success") assert "error" in response assert response["error"].get("code") == "web_rtc_offer_failed" assert "message" in response["error"] assert "RTSPtoWebRTC server communication failure" in response["error"]["message"]
async def test_full_flow_implementation( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test registering an integration and finishing flow works.""" aioclient_mock.post( "https://twentemilieuapi.ximmio.com/api/FetchAdress", json={"dataList": [{ "UniqueId": "12345" }]}, headers={"Content-Type": CONTENT_TYPE_JSON}, ) flow = config_flow.TwenteMilieuFlowHandler() flow.hass = hass result = await flow.async_step_user(user_input=None) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "12345" assert result["data"][CONF_POST_CODE] == FIXTURE_USER_INPUT[CONF_POST_CODE] assert result["data"][CONF_HOUSE_NUMBER] == FIXTURE_USER_INPUT[ CONF_HOUSE_NUMBER] assert result["data"][CONF_HOUSE_LETTER] == FIXTURE_USER_INPUT[ CONF_HOUSE_LETTER]
async def init_integration( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, skip_setup: bool = False, uuid: str = "cfe92100-67c4-11d4-a45f-f8d027761251", unique_id: str = "cfe92100-67c4-11d4-a45f-f8d027761251", ) -> MockConfigEntry: """Set up the IPP integration in Home Assistant.""" fixture = "ipp/get-printer-attributes.bin" aioclient_mock.post( "http://192.168.1.31:631/ipp/print", content=load_fixture_binary(fixture), headers={"Content-Type": "application/ipp"}, ) entry = MockConfigEntry( domain=DOMAIN, unique_id=unique_id, data={ CONF_HOST: "192.168.1.31", CONF_PORT: 631, CONF_SSL: False, CONF_VERIFY_SSL: True, CONF_BASE_PATH: "/ipp/print", CONF_UUID: uuid, }, ) entry.add_to_hass(hass) if not skip_setup: await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() return entry
async def init_integration( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, rgbw: bool = False, skip_setup: bool = False, ) -> MockConfigEntry: """Set up the WLED integration in Home Assistant.""" fixture = "wled/rgb.json" if not rgbw else "wled/rgbw.json" aioclient_mock.get( "http://example.local:80/json/", text=load_fixture(fixture), headers={"Content-Type": "application/json"}, ) aioclient_mock.post( "http://example.local:80/json/state", json={"success": True}, headers={"Content-Type": "application/json"}, ) entry = MockConfigEntry(domain=DOMAIN, data={ CONF_HOST: "example.local", CONF_MAC: "aabbccddeeff" }) entry.add_to_hass(hass) if not skip_setup: await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() return entry
async def test_full_user_flow_implementation( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test the full manual user flow from start to finish.""" aioclient_mock.post( "http://192.168.1.123:80/mf", text=load_fixture("modern_forms/device_info.json"), headers={"Content-Type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, ) assert result.get("step_id") == "user" assert result.get("type") == RESULT_TYPE_FORM assert "flow_id" in result with patch( "homeassistant.components.modern_forms.async_setup_entry", return_value=True, ) as mock_setup_entry: result2 = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={CONF_HOST: "192.168.1.123"} ) assert result2.get("title") == "ModernFormsFan" assert "data" in result2 assert result2.get("type") == RESULT_TYPE_CREATE_ENTRY assert result2["data"][CONF_HOST] == "192.168.1.123" assert result2["data"][CONF_MAC] == "AA:BB:CC:DD:EE:FF" assert len(mock_setup_entry.mock_calls) == 1
async def test_user_device_exists_abort( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test we abort zeroconf flow if Modern Forms device already configured.""" aioclient_mock.post( "http://192.168.1.123:80/mf", text=load_fixture("modern_forms/device_info.json"), headers={"Content-Type": CONTENT_TYPE_JSON}, ) await init_integration(hass, aioclient_mock, skip_setup=True) await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data={ "host": "192.168.1.123", "hostname": "example.local.", "properties": {CONF_MAC: "AA:BB:CC:DD:EE:FF"}, }, ) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data={ "host": "192.168.1.123", "hostname": "example.local.", "properties": {CONF_MAC: "AA:BB:CC:DD:EE:FF"}, }, ) assert result.get("type") == RESULT_TYPE_ABORT assert result.get("reason") == "already_configured"
async def test_zeroconf_confirm_connection_error( update_mock: MagicMock, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test we abort zeroconf flow on Modern Forms connection error.""" aioclient_mock.post("http://192.168.1.123:80/mf", exc=aiohttp.ClientError) result = await hass.config_entries.flow.async_init( DOMAIN, context={ "source": SOURCE_ZEROCONF, CONF_HOST: "example.com", CONF_NAME: "test", }, data=zeroconf.ZeroconfServiceInfo( host="192.168.1.123", addresses=["192.168.1.123"], hostname="example.com.", name="mock_name", port=None, properties={}, type="mock_type", ), ) assert result.get("type") == RESULT_TYPE_ABORT assert result.get("reason") == "cannot_connect"
async def setup_github_integration( hass: HomeAssistant, mock_config_entry: MockConfigEntry, aioclient_mock: AiohttpClientMocker, ) -> None: """Mock setting up the integration.""" headers = json.loads(load_fixture("base_headers.json", DOMAIN)) for idx, repository in enumerate( mock_config_entry.options[CONF_REPOSITORIES]): aioclient_mock.get( f"https://api.github.com/repos/{repository}", json={ **json.loads(load_fixture("repository.json", DOMAIN)), "full_name": repository, "id": idx, }, headers=headers, ) aioclient_mock.post( "https://api.github.com/graphql", json=json.loads(load_fixture("graphql.json", DOMAIN)), headers=headers, ) mock_config_entry.add_to_hass(hass) setup_result = await hass.config_entries.async_setup( mock_config_entry.entry_id) await hass.async_block_till_done() assert setup_result assert mock_config_entry.state == config_entries.ConfigEntryState.LOADED
async def test_config_entry_not_ready( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test configuration entry not ready on library error.""" aioclient_mock.post("http://127.0.0.1:10000/retrieve", exc=aiohttp.ClientError) entry = await init_integration(hass, aioclient_mock) assert entry.state == ENTRY_STATE_SETUP_RETRY
async def test_light_error(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test error handling of the WLED switches.""" aioclient_mock.post("http://example.local:80/json/state", exc=aiohttp.ClientError) await init_integration(hass, aioclient_mock) await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "light.wled_rgb_light"}, blocking=True, ) await hass.async_block_till_done() state = hass.states.get("light.wled_rgb_light") assert state.state == STATE_UNAVAILABLE await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: "light.wled_rgb_light_1"}, blocking=True, ) await hass.async_block_till_done() state = hass.states.get("light.wled_rgb_light_1") assert state.state == STATE_UNAVAILABLE
async def test_full_user_flow_implementation( hass: HomeAssistant, mock_setup_entry: None, aioclient_mock: AiohttpClientMocker, ) -> None: """Test the full manual user flow from start to finish.""" aioclient_mock.post( "https://github.com/login/device/code", json={ "device_code": "3584d83530557fdd1f46af8289938c8ef79f9dc5", "user_code": "WDJB-MJHT", "verification_uri": "https://github.com/login/device", "expires_in": 900, "interval": 5, }, headers={"Content-Type": "application/json"}, ) aioclient_mock.post( "https://github.com/login/oauth/access_token", json={ CONF_ACCESS_TOKEN: MOCK_ACCESS_TOKEN, "token_type": "bearer", "scope": "", }, headers={"Content-Type": "application/json"}, ) aioclient_mock.get( "https://api.github.com/user/starred", json=[{ "full_name": "home-assistant/core" }, { "full_name": "esphome/esphome" }], headers={"Content-Type": "application/json"}, ) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, ) assert result["step_id"] == "device" assert result["type"] == FlowResultType.SHOW_PROGRESS assert "flow_id" in result result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={ CONF_REPOSITORIES: DEFAULT_REPOSITORIES, }, ) assert result["title"] == "" assert result["type"] == FlowResultType.CREATE_ENTRY assert "data" in result assert result["data"][CONF_ACCESS_TOKEN] == MOCK_ACCESS_TOKEN assert "options" in result assert result["options"][CONF_REPOSITORIES] == DEFAULT_REPOSITORIES
async def init_integration( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, skip_setup: bool = False, ) -> MockConfigEntry: """Set up the BSBLan integration in Home Assistant.""" aioclient_mock.post( "http://example.local:80/1234/JQ?Parameter=6224,6225,6226", params={"Parameter": "6224,6225,6226"}, text=load_fixture("bsblan/info.json"), headers={"Content-Type": CONTENT_TYPE_JSON}, ) entry = MockConfigEntry( domain=DOMAIN, unique_id="RVS21.831F/127", data={ CONF_HOST: "example.local", CONF_PASSKEY: "1234", CONF_PORT: 80, CONF_DEVICE_IDENT: "RVS21.831F/127", }, ) entry.add_to_hass(hass) if not skip_setup: await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() return entry
def mock_connection(aioclient_mock: AiohttpClientMocker, authorized=True, conn_error=False) -> None: """Mock the requests to Atag endpoint.""" if conn_error: aioclient_mock.post( "http://127.0.0.1:10000/pair", exc=AtagException, ) aioclient_mock.post( "http://127.0.0.1:10000/retrieve", exc=AtagException, ) return PAIR_REPLY["pair_reply"].update( {"acc_status": AUTHORIZED if authorized else UNAUTHORIZED}) RECEIVE_REPLY["retrieve_reply"].update( {"acc_status": AUTHORIZED if authorized else UNAUTHORIZED}) aioclient_mock.post( "http://127.0.0.1:10000/retrieve", json=RECEIVE_REPLY, ) aioclient_mock.post( "http://127.0.0.1:10000/update", json=UPDATE_REPLY, ) aioclient_mock.post( "http://127.0.0.1:10000/pair", json=PAIR_REPLY, )
async def init_integration( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, rgbw: bool = False, skip_setup: bool = False, mock_type: Callable = modern_forms_call_mock, ) -> MockConfigEntry: """Set up the Modern Forms integration in Home Assistant.""" aioclient_mock.post( "http://192.168.1.123:80/mf", side_effect=mock_type, headers={"Content-Type": CONTENT_TYPE_JSON}, ) entry = MockConfigEntry(domain=DOMAIN, data={ CONF_HOST: "192.168.1.123", CONF_MAC: "AA:BB:CC:DD:EE:FF" }) entry.add_to_hass(hass) if not skip_setup: await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() return entry
async def test_full_flow_implementation( opp: OpenPeerPower, aioclient_mock: AiohttpClientMocker) -> None: """Test registering an integration and finishing flow works.""" aioclient_mock.post( "https://twentemilieuapi.ximmio.com/api/FetchAdress", json={"dataList": [{ "UniqueId": "12345" }]}, headers={"Content-Type": CONTENT_TYPE_JSON}, ) result = await opp.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" result = await opp.config_entries.flow.async_configure( result["flow_id"], FIXTURE_USER_INPUT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "12345" assert result["data"][CONF_POST_CODE] == FIXTURE_USER_INPUT[CONF_POST_CODE] assert result["data"][CONF_HOUSE_NUMBER] == FIXTURE_USER_INPUT[ CONF_HOUSE_NUMBER] assert result["data"][CONF_HOUSE_LETTER] == FIXTURE_USER_INPUT[ CONF_HOUSE_LETTER]
async def test_effect_service_error(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, caplog) -> None: """Test error handling of the WLED effect service.""" aioclient_mock.post("http://192.168.1.123:80/json/state", text="", status=400) await init_integration(hass, aioclient_mock) with patch( "homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh" ): await hass.services.async_call( DOMAIN, SERVICE_EFFECT, { ATTR_ENTITY_ID: "light.wled_rgb_light", ATTR_EFFECT: 9 }, blocking=True, ) await hass.async_block_till_done() state = hass.states.get("light.wled_rgb_light") assert state.state == STATE_ON assert "Invalid response from API" in caplog.text
async def test_sensor_updates_with_empty_release_array( hass: HomeAssistant, init_integration: MockConfigEntry, aioclient_mock: AiohttpClientMocker, ) -> None: """Test the sensor updates by default GitHub sensors.""" state = hass.states.get(TEST_SENSOR_ENTITY) assert state.state == "v1.0.0" response_json = json.loads(load_fixture("graphql.json", DOMAIN)) response_json["data"]["repository"]["release"] = None headers = json.loads(load_fixture("base_headers.json", DOMAIN)) aioclient_mock.clear_requests() aioclient_mock.get( f"https://api.github.com/repos/{TEST_REPOSITORY}/events", json=[], headers=headers, ) aioclient_mock.post( "https://api.github.com/graphql", json=response_json, headers=headers, ) async_fire_time_changed(hass, dt.utcnow() + FALLBACK_UPDATE_INTERVAL) await hass.async_block_till_done() new_state = hass.states.get(TEST_SENSOR_ENTITY) assert new_state.state == "unavailable"
async def test_switches_states(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker): """Test we get sensor data.""" await async_setup_platform(hass, aioclient_mock, DOMAIN) assert hass.states.get( f"switch.{DEFAULT_NAME}_usb_port_status").state == STATE_OFF assert hass.states.get( f"switch.{DEFAULT_NAME}_ac_port_status").state == STATE_ON entity_id = f"switch.{DEFAULT_NAME}_12v_port_status" assert hass.states.get(entity_id).state == STATE_OFF aioclient_mock.post( "http://1.2.3.4/state", text=load_fixture("goalzero/state_change.json"), ) await hass.services.async_call( DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: [entity_id]}, blocking=True, ) assert hass.states.get(entity_id).state == STATE_ON aioclient_mock.clear_requests() aioclient_mock.post( "http://1.2.3.4/state", text=load_fixture("goalzero/state_data.json"), ) await hass.services.async_call( DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: [entity_id]}, blocking=True, ) assert hass.states.get(entity_id).state == STATE_OFF
async def test_address_already_set_up( opp: OpenPeerPower, aioclient_mock: AiohttpClientMocker) -> None: """Test we abort if address has already been set up.""" MockConfigEntry(domain=DOMAIN, data={ **FIXTURE_USER_INPUT, CONF_ID: "12345" }, title="12345").add_to_opp(opp) aioclient_mock.post( "https://twentemilieuapi.ximmio.com/api/FetchAdress", json={"dataList": [{ "UniqueId": "12345" }]}, headers={"Content-Type": CONTENT_TYPE_JSON}, ) result = await opp.config_entries.flow.async_init( config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER}, data=FIXTURE_USER_INPUT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured"
async def test_invalid_token_expiry_in_config_entry( hass: HomeAssistant, component_setup: ComponentSetup, setup_config_entry: MockConfigEntry, aioclient_mock: AiohttpClientMocker, ) -> None: """Exercise case in issue #69623 with invalid token expiration persisted.""" # The token is refreshed and new expiration values are returned expires_in = 86400 expires_at = time.time() + expires_in aioclient_mock.post( "https://oauth2.googleapis.com/token", json={ "refresh_token": "some-refresh-token", "access_token": "some-updated-token", "expires_at": expires_at, "expires_in": expires_in, }, ) assert await component_setup() # Verify token expiration values are updated entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert entries[0].state is ConfigEntryState.LOADED assert entries[0].data["token"]["access_token"] == "some-updated-token" assert entries[0].data["token"]["expires_in"] == expires_in
async def test_flow_with_activation_failure( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, ) -> None: """Test flow with activation failure of the device.""" aioclient_mock.post( "https://github.com/login/device/code", json={ "device_code": "3584d83530557fdd1f46af8289938c8ef79f9dc5", "user_code": "WDJB-MJHT", "verification_uri": "https://github.com/login/device", "expires_in": 900, "interval": 5, }, headers={"Content-Type": "application/json"}, ) aioclient_mock.post( "https://github.com/login/oauth/access_token", exc=GitHubException("Activation failed"), ) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, ) assert result["step_id"] == "device" assert result["type"] == RESULT_TYPE_SHOW_PROGRESS result = await hass.config_entries.flow.async_configure(result["flow_id"]) assert result["type"] == RESULT_TYPE_SHOW_PROGRESS_DONE assert result["step_id"] == "could_not_register"
async def test_full_zeroconf_tls_flow_implementation( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test the full manual user flow from start to finish.""" aioclient_mock.post( "https://192.168.1.31:631/ipp/print", content=load_fixture_binary("ipp/get-printer-attributes.bin"), headers={"Content-Type": "application/ipp"}, ) discovery_info = MOCK_ZEROCONF_IPPS_SERVICE_INFO.copy() result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info, ) assert result["step_id"] == "zeroconf_confirm" assert result["type"] == RESULT_TYPE_FORM assert result["description_placeholders"] == {CONF_NAME: "EPSON123456"} result = await hass.config_entries.flow.async_configure(result["flow_id"], user_input={}) assert result["type"] == RESULT_TYPE_CREATE_ENTRY assert result["title"] == "EPSON123456" assert result["data"] assert result["data"][CONF_HOST] == "192.168.1.31" assert result["data"][CONF_NAME] == "EPSON123456" assert result["data"][CONF_UUID] == "cfe92100-67c4-11d4-a45f-f8d027761251" assert result["data"][CONF_SSL]
async def test_config_entry_not_ready( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test the IPP configuration entry not ready.""" aioclient_mock.post("http://EPSON123456.local:631/ipp/print", exc=aiohttp.ClientError) entry = await init_integration(hass, aioclient_mock) assert entry.state == ENTRY_STATE_SETUP_RETRY
async def test_cloud_import_updates_existing_entry( hass: HomeAssistant, hass_client_no_auth: Callable[[], Awaitable[TestClient]], aioclient_mock: AiohttpClientMocker, current_request_with_host: None, mock_lametric_cloud_config_flow: MagicMock, mock_lametric_config_flow: MagicMock, mock_config_entry: MockConfigEntry, ) -> None: """Test cloud importing existing device updates existing entry.""" mock_config_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER} ) assert "flow_id" in result flow_id = result["flow_id"] await hass.config_entries.flow.async_configure( flow_id, user_input={"next_step_id": "pick_implementation"} ) # pylint: disable=protected-access state = config_entry_oauth2_flow._encode_jwt( hass, { "flow_id": flow_id, "redirect_uri": "https://example.com/auth/external/callback", }, ) client = await hass_client_no_auth() await client.get(f"/auth/external/callback?code=abcd&state={state}") aioclient_mock.post( "https://developer.lametric.com/api/v2/oauth2/token", json={ "refresh_token": "mock-refresh-token", "access_token": "mock-access-token", "type": "Bearer", "expires_in": 60, }, ) await hass.config_entries.flow.async_configure(flow_id) result2 = await hass.config_entries.flow.async_configure( flow_id, user_input={CONF_DEVICE: "SA110405124500W00BS9"} ) assert result2.get("type") == FlowResultType.ABORT assert result2.get("reason") == "already_configured" assert mock_config_entry.data == { CONF_HOST: "127.0.0.1", CONF_API_KEY: "mock-api-key", CONF_MAC: "AA:BB:CC:DD:EE:FF", } assert len(mock_lametric_cloud_config_flow.devices.mock_calls) == 1 assert len(mock_lametric_config_flow.device.mock_calls) == 1 assert len(mock_lametric_config_flow.notify.mock_calls) == 0
async def test_config_entry_not_ready( opp: OpenPeerPower, aioclient_mock: AiohttpClientMocker) -> None: """Test the BSBLan configuration entry not ready.""" aioclient_mock.post( "http://example.local:80/1234/JQ?Parameter=6224,6225,6226", exc=aiohttp.ClientError, ) entry = await init_integration(opp, aioclient_mock) assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_config_entry_no_authentication( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test the BSBLan configuration entry not ready.""" aioclient_mock.post( "http://example.local:80/1234/JQ?Parameter=6224,6225,6226", exc=aiohttp.ClientError, ) entry = await init_integration_without_auth(hass, aioclient_mock) assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_zeroconf_confirm_connection_error( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test we abort zeroconf flow on IPP connection error.""" aioclient_mock.post("http://192.168.1.31:631/ipp/print", exc=aiohttp.ClientError) discovery_info = MOCK_ZEROCONF_IPP_SERVICE_INFO.copy() result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info) assert result["type"] == RESULT_TYPE_ABORT assert result["reason"] == "connection_error"
async def test_connection_error(opp: OpenPeerPower, aioclient_mock: AiohttpClientMocker) -> None: """Test we show user form on Twente Milieu connection error.""" aioclient_mock.post("https://twentemilieuapi.ximmio.com/api/FetchAdress", exc=aiohttp.ClientError) result = await opp.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=FIXTURE_USER_INPUT) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" assert result["errors"] == {"base": "cannot_connect"}
async def test_connection_error(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test we show user form on Twente Milieu connection error.""" aioclient_mock.post("https://twentemilieuapi.ximmio.com/api/FetchAdress", exc=aiohttp.ClientError) flow = config_flow.TwenteMilieuFlowHandler() flow.hass = hass result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" assert result["errors"] == {"base": "cannot_connect"}