async def test_ssdp_not_successful_2(hass: HomeAssistant, no_mac_address: Mock): """Test starting a flow from discovery but no device found.""" with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "homeassistant.components.samsungtv.bridge.SamsungTVWS", side_effect=ConnectionFailure("Boom"), ), patch( "homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.device_info", return_value=MOCK_DEVICE_INFO, ): # confirm to add the entry result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA) assert result["type"] == "form" assert result["step_id"] == "confirm" # device not found result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input="whatever") assert result["type"] == "abort" assert result["reason"] == RESULT_CANNOT_CONNECT
async def test_ssdp_not_successful_2(hass): """Test starting a flow from discovery but no device found.""" with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "homeassistant.components.samsungtv.bridge.SamsungTVWS", side_effect=ConnectionFailure("Boom"), ), patch( "homeassistant.components.samsungtv.config_flow.socket" ): # confirm to add the entry result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA ) assert result["type"] == "form" assert result["step_id"] == "confirm" # device not found result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input="whatever" ) assert result["type"] == "abort" assert result["reason"] == "not_successful"
async def test_update_connection_failure(hass, remotews, mock_now): """Testing update tv connection failure exception.""" with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=[OSError("Boom"), DEFAULT_MOCK], ): await setup_samsungtv(hass, MOCK_CONFIGWS) with patch( "homeassistant.components.samsungtv.bridge.SamsungTVWS", side_effect=ConnectionFailure("Boom"), ): next_update = mock_now + timedelta(minutes=5) with patch("homeassistant.util.dt.utcnow", return_value=next_update): async_fire_time_changed(hass, next_update) await hass.async_block_till_done() next_update = mock_now + timedelta(minutes=10) with patch("homeassistant.util.dt.utcnow", return_value=next_update): async_fire_time_changed(hass, next_update) await hass.async_block_till_done() assert [ flow for flow in hass.config_entries.flow.async_progress() if flow["context"]["source"] == "reauth" ] state = hass.states.get(ENTITY_ID) assert state.state == STATE_UNAVAILABLE
async def test_update_ws_connection_failure( hass: HomeAssistant, mock_now: datetime, remotews: Mock, caplog: pytest.LogCaptureFixture, ) -> None: """Testing update tv connection failure exception.""" await setup_samsungtv(hass, MOCK_CONFIGWS) with patch.object( remotews, "start_listening", side_effect=ConnectionFailure('{"event": "ms.voiceApp.hide"}'), ), patch.object(remotews, "is_alive", return_value=False): next_update = mock_now + timedelta(minutes=5) with patch("homeassistant.util.dt.utcnow", return_value=next_update): async_fire_time_changed(hass, next_update) await hass.async_block_till_done() assert ( "Unexpected ConnectionFailure trying to get remote for fake_host, please " 'report this issue: ConnectionFailure(\'{"event": "ms.voiceApp.hide"}\')' in caplog.text) state = hass.states.get(ENTITY_ID) assert state.state == STATE_OFF
async def test_user_not_successful_2(hass): """Test starting a flow by user but no connection found.""" with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "homeassistant.components.samsungtv.bridge.SamsungTVWS", side_effect=ConnectionFailure("Boom"), ), patch("homeassistant.components.samsungtv.config_flow.socket"): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA) assert result["type"] == "abort" assert result["reason"] == "not_successful"
async def test_user_not_successful_2(hass: HomeAssistant) -> None: """Test starting a flow by user but no connection found.""" with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "homeassistant.components.samsungtv.bridge.SamsungTVWS.open", side_effect=ConnectionFailure("Boom"), ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA) assert result["type"] == "abort" assert result["reason"] == RESULT_CANNOT_CONNECT
async def test_user_not_successful_2(opp: OpenPeerPower, remotews: Mock): """Test starting a flow by user but no connection found.""" with patch( "openpeerpower.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "openpeerpower.components.samsungtv.bridge.SamsungTVWS", side_effect=ConnectionFailure("Boom"), ): result = await opp.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA) assert result["type"] == "abort" assert result["reason"] == RESULT_CANNOT_CONNECT
async def test_ssdp_not_successful_2(opp: OpenPeerPower, remote: Mock): """Test starting a flow from discovery but no device found.""" with patch( "openpeerpower.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "openpeerpower.components.samsungtv.bridge.SamsungTVWS", side_effect=ConnectionFailure("Boom"), ): # confirm to add the entry result = await opp.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA) assert result["type"] == "form" assert result["step_id"] == "confirm" # device not found result = await opp.config_entries.flow.async_configure( result["flow_id"], user_input="whatever") assert result["type"] == "abort" assert result["reason"] == RESULT_CANNOT_CONNECT