Ejemplo n.º 1
0
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),
        ]
Ejemplo n.º 2
0
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"
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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"
Ejemplo n.º 6
0
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