async def test_autodetect_websocket_ssl(hass, remote, remotews): """Test for send key with autodetection of protocol.""" with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "homeassistant.components.samsungtv.bridge.SamsungTVWS", side_effect=[WebSocketProtocolException("Boom"), DEFAULT_MOCK], ) as remotews: enter = Mock() type(enter).token = PropertyMock(return_value="123456789") remote = Mock() remote.__enter__ = Mock(return_value=enter) remote.__exit__ = Mock(return_value=False) remotews.return_value = remote result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA ) assert result["type"] == "create_entry" assert result["data"][CONF_METHOD] == "websocket" assert result["data"][CONF_TOKEN] == "123456789" assert remotews.call_count == 2 assert remotews.call_args_list == [ call(**AUTODETECT_WEBSOCKET_PLAIN), call(**AUTODETECT_WEBSOCKET_SSL), ]
async def test_user_websocket_not_supported(hass): """Test starting a flow by user for not supported device.""" with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "homeassistant.components.samsungtv.bridge.SamsungTVWS", side_effect=WebSocketProtocolException("Boom"), ), patch("homeassistant.components.samsungtv.config_flow.socket"): # websocket device not supported result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA) assert result["type"] == "abort" assert result["reason"] == "not_supported"
async def test_ssdp_websocket_not_supported(hass: HomeAssistant, remote: Mock): """Test starting a flow from discovery for not supported device.""" with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "homeassistant.components.samsungtv.bridge.SamsungTVWS", side_effect=WebSocketProtocolException("Boom"), ): # device not supported result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result["type"] == "abort" assert result["reason"] == RESULT_NOT_SUPPORTED
async def test_user_websocket_not_supported(opp: OpenPeerPower, remotews: Mock): """Test starting a flow by user for not supported device.""" with patch( "openpeerpower.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "openpeerpower.components.samsungtv.bridge.SamsungTVWS", side_effect=WebSocketProtocolException("Boom"), ): # websocket device not supported 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_NOT_SUPPORTED
async def test_ssdp_not_supported_2(hass): """Test starting a flow from discovery for not supported device.""" with patch( "homeassistant.components.samsungtv.config_flow.Remote", side_effect=WebSocketProtocolException("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 supported result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input="whatever") assert result["type"] == "abort" assert result["reason"] == "not_supported"
async def test_ssdp_websocket_not_supported(opp: OpenPeerPower, remote: Mock): """Test starting a flow from discovery for not supported device.""" with patch( "openpeerpower.components.samsungtv.bridge.Remote", side_effect=OSError("Boom"), ), patch( "openpeerpower.components.samsungtv.bridge.SamsungTVWS", side_effect=WebSocketProtocolException("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 supported result = await opp.config_entries.flow.async_configure( result["flow_id"], user_input="whatever") assert result["type"] == "abort" assert result["reason"] == RESULT_NOT_SUPPORTED