Esempio n. 1
0
async def test_zeroconf_confirm_connection_error(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test we abort zeroconf flow on WLED connection error."""
    aioclient_mock.get("http://example.com/json/", exc=aiohttp.ClientError)

    flow = config_flow.WLEDFlowHandler()
    flow.hass = hass
    flow.context = {
        "source": SOURCE_ZEROCONF,
        CONF_HOST: "example.com",
        CONF_NAME: "test",
    }
    result = await flow.async_step_zeroconf_confirm(
        user_input={CONF_HOST: "example.com"})

    assert result["reason"] == "connection_error"
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
Esempio n. 2
0
async def test_bad_json(
    hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, caplog
):
    """Test if it raises an error when there is bad JSON."""
    aioclient_mock.get(
        "https://kubra.io/stormcenter/api/v1/stormcenters/39e6d9f3-fdea-4539-848f-b8631945da6f/views/74de8a50-3f45-4f6a-9483-fd618bb9165d/currentState?preview=false",
        json={"data": {}},
    )

    config_entry = MockConfigEntry(domain=DOMAIN, data=COUNTY_ENTRY_DATA)
    config_entry.add_to_hass(hass)

    assert await hass.config_entries.async_setup(config_entry.entry_id)
    await hass.async_block_till_done()
    assert hass.data[DOMAIN]

    assert "ConfigEntryNotReady" in caplog.text
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.get(
        "http://127.0.0.1:9123/elgato/accessory-info",
        text=load_fixture("elgato/info.json"),
        headers={"Content-Type": CONTENT_TYPE_JSON},
    )

    # Start a discovered configuration flow, to guarantee a user flow doesn't abort
    await hass.config_entries.flow.async_init(
        DOMAIN,
        context={CONF_SOURCE: SOURCE_ZEROCONF},
        data=zeroconf.ZeroconfServiceInfo(
            host="127.0.0.1",
            hostname="example.local.",
            name="mock_name",
            port=9123,
            properties={},
            type="mock_type",
        ),
    )

    result = await hass.config_entries.flow.async_init(
        DOMAIN,
        context={CONF_SOURCE: SOURCE_USER},
    )

    assert result["step_id"] == "user"
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM

    result = await hass.config_entries.flow.async_configure(result["flow_id"],
                                                            user_input={
                                                                CONF_HOST:
                                                                "127.0.0.1",
                                                                CONF_PORT: 9123
                                                            })

    assert result["data"][CONF_HOST] == "127.0.0.1"
    assert result["data"][CONF_PORT] == 9123
    assert result["data"][CONF_SERIAL_NUMBER] == "CN11A1A00001"
    assert result["title"] == "CN11A1A00001"
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY

    entries = hass.config_entries.async_entries(DOMAIN)
    assert entries[0].unique_id == "CN11A1A00001"
Esempio n. 4
0
async def test_connection_error(hass: HomeAssistant,
                                aioclient_mock: AiohttpClientMocker) -> None:
    """Test we show user form on AdGuard Home connection error."""
    aioclient_mock.get(
        f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}"
        f"://{FIXTURE_USER_INPUT[CONF_HOST]}"
        f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status",
        exc=aiohttp.ClientError,
    )

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_USER}, data=FIXTURE_USER_INPUT)

    assert result
    assert result.get("type") == data_entry_flow.FlowResultType.FORM
    assert result.get("step_id") == "user"
    assert result.get("errors") == {"base": "cannot_connect"}
async def test_zeroconf_connection_error(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test we abort zeroconf flow on Elgato Key Light connection error."""
    aioclient_mock.get("http://1.2.3.4/elgato/accessory-info",
                       exc=aiohttp.ClientError)

    result = await hass.config_entries.flow.async_init(
        config_flow.DOMAIN,
        context={"source": SOURCE_ZEROCONF},
        data={
            "host": "1.2.3.4",
            "port": 9123
        },
    )

    assert result["reason"] == "cannot_connect"
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
Esempio n. 6
0
async def test_connection_error(hass: HomeAssistant,
                                aioclient_mock: AiohttpClientMocker) -> None:
    """Test we show user form on AdGuard Home connection error."""
    aioclient_mock.get(
        f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}"
        f"://{FIXTURE_USER_INPUT[CONF_HOST]}"
        f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status",
        exc=aiohttp.ClientError,
    )

    flow = config_flow.AdGuardHomeFlowHandler()
    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"}
async def test_connection_error(hass: HomeAssistant,
                                aioclient_mock: AiohttpClientMocker) -> None:
    """Test we show user form on Elgato Key Light connection error."""
    aioclient_mock.get("http://example.local/elgato/accessory-info",
                       exc=aiohttp.ClientError)

    flow = config_flow.ElgatoFlowHandler()
    flow.hass = hass
    flow.context = {"source": SOURCE_USER}
    result = await flow.async_step_user(user_input={
        CONF_HOST: "example.local",
        CONF_PORT: 9123
    })

    assert result["errors"] == {"base": "connection_error"}
    assert result["step_id"] == "user"
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
Esempio n. 8
0
async def test_total_update_timeout(
    hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, caplog
):
    """Test if it raises an error when there is a timeout."""
    aioclient_mock.get(
        "https://kubra.io/stormcenter/api/v1/stormcenters/39e6d9f3-fdea-4539-848f-b8631945da6f/views/74de8a50-3f45-4f6a-9483-fd618bb9165d/currentState?preview=false",
        exc=asyncio.TimeoutError(),
    )

    config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_ENTRY_DATA)
    config_entry.add_to_hass(hass)

    assert await hass.config_entries.async_setup(config_entry.entry_id)
    await hass.async_block_till_done()
    assert hass.data[DOMAIN]

    assert "Timeout fetching data" in caplog.text
Esempio n. 9
0
async def test_entry_diagnostics(
    hass: HomeAssistant,
    hass_client: ClientSession,
    mock_config_entry: MockConfigEntry,
    aioclient_mock: AiohttpClientMocker,
) -> None:
    """Test config entry diagnostics."""
    mock_config_entry.options = {CONF_REPOSITORIES: ["home-assistant/core"]}
    response_json = json.loads(load_fixture("graphql.json", DOMAIN))
    response_json["data"]["repository"]["full_name"] = "home-assistant/core"

    aioclient_mock.post(
        "https://api.github.com/graphql",
        json=response_json,
        headers=json.loads(load_fixture("base_headers.json", DOMAIN)),
    )
    aioclient_mock.get(
        "https://api.github.com/rate_limit",
        json={"resources": {
            "core": {
                "remaining": 100,
                "limit": 100
            }
        }},
        headers={"Content-Type": "application/json"},
    )

    await setup_github_integration(hass, mock_config_entry, aioclient_mock)
    result = await get_diagnostics_for_config_entry(
        hass,
        hass_client,
        mock_config_entry,
    )

    assert result["options"]["repositories"] == ["home-assistant/core"]
    assert result["rate_limit"] == {
        "resources": {
            "core": {
                "remaining": 100,
                "limit": 100
            }
        }
    }
    assert (result["repositories"]["home-assistant/core"]["full_name"] ==
            "home-assistant/core")
Esempio n. 10
0
async def test_connection_error(hass: HomeAssistant,
                                aioclient_mock: AiohttpClientMocker) -> None:
    """Test we show user form on Elgato Key Light connection error."""
    aioclient_mock.get("http://1.2.3.4/elgato/accessory-info",
                       exc=aiohttp.ClientError)

    result = await hass.config_entries.flow.async_init(
        config_flow.DOMAIN,
        context={"source": SOURCE_USER},
        data={
            CONF_HOST: "1.2.3.4",
            CONF_PORT: 9123
        },
    )

    assert result["errors"] == {"base": "connection_error"}
    assert result["step_id"] == "user"
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
Esempio n. 11
0
def mock_connection_error(
    aioclient_mock: AiohttpClientMocker,
    device: str = "roku3",
    app: str = "roku",
    host: str = HOST,
) -> None:
    """Mock the Roku connection error."""
    roku_url = f"http://{host}:8060"

    aioclient_mock.get(f"{roku_url}/query/device-info", exc=SocketGIAError)
    aioclient_mock.get(f"{roku_url}/query/apps", exc=SocketGIAError)
    aioclient_mock.get(f"{roku_url}/query/active-app", exc=SocketGIAError)
    aioclient_mock.get(f"{roku_url}/query/tv-active-channel", exc=SocketGIAError)
    aioclient_mock.get(f"{roku_url}/query/tv-channels", exc=SocketGIAError)

    aioclient_mock.post(re.compile(f"{roku_url}/keypress/.*"), exc=SocketGIAError)
    aioclient_mock.post(re.compile(f"{roku_url}/launch/.*"), exc=SocketGIAError)
    aioclient_mock.post(f"{roku_url}/search", exc=SocketGIAError)
Esempio n. 12
0
async def test_zeroconf_confirm_connection_error(
    hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
    """Test we abort zeroconf flow on WLED connection error."""
    aioclient_mock.get("http://example.com/json/", exc=aiohttp.ClientError)

    result = await hass.config_entries.flow.async_init(
        config_flow.DOMAIN,
        context={
            "source": SOURCE_ZEROCONF,
            CONF_HOST: "example.com",
            CONF_NAME: "test",
        },
        data={"hostname": "example.com."},
    )

    assert result["reason"] == "connection_error"
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
Esempio n. 13
0
async def test_zeroconf_connection_error(
        update_mock: MagicMock, opp: OpenPeerPower,
        aioclient_mock: AiohttpClientMocker) -> None:
    """Test we abort zeroconf flow on WLED connection error."""
    aioclient_mock.get("http://192.168.1.123/json/", exc=aiohttp.ClientError)

    result = await opp.config_entries.flow.async_init(
        DOMAIN,
        context={"source": SOURCE_ZEROCONF},
        data={
            "host": "192.168.1.123",
            "hostname": "example.local.",
            "properties": {}
        },
    )

    assert result.get("type") == RESULT_TYPE_ABORT
    assert result.get("reason") == "cannot_connect"
Esempio n. 14
0
async def test_zeroconf_connection_error(
        update_mock: MagicMock, hass: HomeAssistant,
        aioclient_mock: AiohttpClientMocker) -> None:
    """Test we abort zeroconf flow on WLED connection error."""
    aioclient_mock.get("http://192.168.1.123/json/", exc=aiohttp.ClientError)

    result = await hass.config_entries.flow.async_init(
        config_flow.DOMAIN,
        context={"source": SOURCE_ZEROCONF},
        data={
            "host": "192.168.1.123",
            "hostname": "example.local.",
            "properties": {}
        },
    )

    assert result["reason"] == "connection_error"
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
Esempio n. 15
0
async def test_form_cannot_connect(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test we handle cannot connect error."""
    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": config_entries.SOURCE_USER})

    aioclient_mock.get(
        "http://1.1.1.1:8080/status.json?show_avail=1",
        exc=aiohttp.ClientError,
    )
    result2 = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {
            "host": "1.1.1.1",
        },
    )

    assert result2["type"] == FlowResultType.FORM
    assert result2["errors"] == {"base": "cannot_connect"}
Esempio n. 16
0
async def test_migrate_entry_failed(hass: HomeAssistant,
                                    aioclient_mock: AiohttpClientMocker,
                                    api_response: str) -> None:
    """Test migrate entry data that fails."""
    uri = APIURL_TEMPLATE.format(TEST_CONFIG_MIGRATE["longitude"],
                                 TEST_CONFIG_MIGRATE["latitude"])
    aioclient_mock.get(uri, text=api_response)
    entry = MockConfigEntry(domain=DOMAIN, data=TEST_CONFIG_MIGRATE)
    entry.add_to_hass(hass)
    assert entry.version == 1

    with patch(
            "homeassistant.config_entries.ConfigEntries.async_update_entry",
            return_value=False,
    ):
        await hass.config_entries.async_setup(entry.entry_id)
        await hass.async_block_till_done()

    assert entry.version == 1
Esempio n. 17
0
async def test_nextdns_system_health_fail(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test NextDNS system health."""
    aioclient_mock.get(API_ENDPOINT, exc=ClientError)
    hass.config.components.add(DOMAIN)
    assert await async_setup_component(hass, "system_health", {})

    info = await get_system_health_info(hass, DOMAIN)

    for key, val in info.items():
        if asyncio.iscoroutine(val):
            info[key] = await val

    assert info == {
        "can_reach_server": {
            "type": "failed",
            "error": "unreachable"
        }
    }
Esempio n. 18
0
async def test_full_flow_implementation(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test registering an integration and finishing flow works."""
    aioclient_mock.get(
        "http://127.0.0.1:10000/retrieve",
        json=RECEIVE_REPLY,
    )
    aioclient_mock.post(
        "http://127.0.0.1:10000/pair",
        json=PAIR_REPLY,
    )
    result = await hass.config_entries.flow.async_init(
        DOMAIN,
        context={"source": config_entries.SOURCE_USER},
        data=USER_INPUT,
    )
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == UID
    assert result["result"].unique_id == UID
Esempio n. 19
0
async def test_show_zerconf_form(hass: HomeAssistant,
                                 aioclient_mock: AiohttpClientMocker) -> None:
    """Test that the zeroconf confirmation form is served."""
    aioclient_mock.get(
        "http://example.local:80/json/",
        text=load_fixture("wled/rgb.json"),
        headers={"Content-Type": "application/json"},
    )

    flow = config_flow.WLEDFlowHandler()
    flow.hass = hass
    flow.context = {"source": SOURCE_ZEROCONF}
    result = await flow.async_step_zeroconf({"hostname": "example.local."})

    assert flow.context[CONF_HOST] == "example.local"
    assert flow.context[CONF_NAME] == "example"
    assert result["description_placeholders"] == {CONF_NAME: "example"}
    assert result["step_id"] == "zeroconf_confirm"
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
Esempio n. 20
0
async def test_ssdp_confirm_cannot_connect(
        hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker) -> None:
    """Test we abort SSDP flow on connection error."""
    aioclient_mock.get("http://127.0.0.1:8080/info/getVersion",
                       exc=HTTPClientError)

    discovery_info = MOCK_SSDP_DISCOVERY_INFO.copy()
    result = await hass.config_entries.flow.async_init(
        DOMAIN,
        context={
            CONF_SOURCE: SOURCE_SSDP,
            CONF_HOST: HOST,
            CONF_NAME: HOST
        },
        data=discovery_info,
    )

    assert result["type"] == RESULT_TYPE_ABORT
    assert result["reason"] == "cannot_connect"
async def test_connection_error(hass: HomeAssistant,
                                aioclient_mock: AiohttpClientMocker) -> None:
    """Test we show user form on Agent connection error."""

    aioclient_mock.get("http://example.local:8090/command.cgi?cmd=getStatus",
                       text="")

    result = await hass.config_entries.flow.async_init(
        config_flow.DOMAIN,
        context={"source": SOURCE_USER},
        data={
            CONF_HOST: "example.local",
            CONF_PORT: 8090
        },
    )

    assert result["errors"]["base"] == "cannot_connect"
    assert result["step_id"] == "user"
    assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
Esempio n. 22
0
async def test_setup_hass(hass: HomeAssistant,
                          aioclient_mock: AiohttpClientMocker,
                          api_response: str) -> None:
    """Test for successfully setting up the smhi integration."""
    uri = APIURL_TEMPLATE.format(TEST_CONFIG["location"]["longitude"],
                                 TEST_CONFIG["location"]["latitude"])
    aioclient_mock.get(uri, text=api_response)

    entry = MockConfigEntry(domain="smhi", data=TEST_CONFIG, version=2)
    entry.add_to_hass(hass)

    await hass.config_entries.async_setup(entry.entry_id)
    await hass.async_block_till_done()
    assert aioclient_mock.call_count == 1

    #  Testing the actual entity state for
    #  deeper testing than normal unity test
    state = hass.states.get(ENTITY_ID)

    assert state
    assert state.state == "sunny"
    assert state.attributes[ATTR_SMHI_CLOUDINESS] == 50
    assert state.attributes[ATTR_SMHI_THUNDER_PROBABILITY] == 33
    assert state.attributes[ATTR_SMHI_WIND_GUST_SPEED] == 16.92
    assert state.attributes[ATTR_ATTRIBUTION].find("SMHI") >= 0
    assert state.attributes[ATTR_WEATHER_HUMIDITY] == 55
    assert state.attributes[ATTR_WEATHER_PRESSURE] == 1024
    assert state.attributes[ATTR_WEATHER_TEMPERATURE] == 17
    assert state.attributes[ATTR_WEATHER_VISIBILITY] == 50
    assert state.attributes[ATTR_WEATHER_WIND_SPEED] == 6.84
    assert state.attributes[ATTR_WEATHER_WIND_BEARING] == 134
    assert len(state.attributes["forecast"]) == 4

    forecast = state.attributes["forecast"][1]
    assert forecast[ATTR_FORECAST_TIME] == "2018-09-02T12:00:00"
    assert forecast[ATTR_FORECAST_TEMP] == 21
    assert forecast[ATTR_FORECAST_TEMP_LOW] == 6
    assert forecast[ATTR_FORECAST_PRECIPITATION] == 0
    assert forecast[ATTR_FORECAST_CONDITION] == "partlycloudy"
    assert forecast[ATTR_FORECAST_PRESSURE] == 1026
    assert forecast[ATTR_FORECAST_WIND_BEARING] == 203
    assert forecast[ATTR_FORECAST_WIND_SPEED] == 6.12
Esempio n. 23
0
async def init_integration(
    hass: HomeAssistant,
    aioclient_mock: AiohttpClientMocker,
    skip_setup: bool = False,
) -> MockConfigEntry:
    """Set up the Elgato Key Light integration in Home Assistant."""

    aioclient_mock.get(
        "http://example.local:9123/elgato/accessory-info",
        text=load_fixture("elgato/info.json"),
        headers={"Content-Type": "application/json"},
    )

    aioclient_mock.put(
        "http://example.local:9123/elgato/lights",
        text=load_fixture("elgato/state.json"),
        headers={"Content-Type": "application/json"},
    )

    aioclient_mock.get(
        "http://example.local:9123/elgato/lights",
        text=load_fixture("elgato/state.json"),
        headers={"Content-Type": "application/json"},
    )

    entry = MockConfigEntry(
        domain=DOMAIN,
        unique_id="CN11A1A00001",
        data={
            CONF_HOST: "example.local",
            CONF_PORT: 9123,
            CONF_SERIAL_NUMBER: "CN11A1A00001",
        },
    )

    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
Esempio n. 24
0
def pvpc_aioclient_mock(aioclient_mock: AiohttpClientMocker):
    """Create a mock config entry."""
    mask_url = "https://apidatos.ree.es/es/datos/mercados/precios-mercados-tiempo-real"
    mask_url += "?time_trunc=hour&geo_ids={0}&start_date={1}T00:00&end_date={1}T23:59"
    # new format for prices >= 2021-06-01
    sample_data = load_fixture(f"{DOMAIN}/{FIXTURE_JSON_DATA_2021_06_01}")

    # tariff variant with different geo_ids=8744
    aioclient_mock.get(mask_url.format(8741, "2021-06-01"), text=sample_data)
    aioclient_mock.get(mask_url.format(8744, "2021-06-01"), text=sample_data)
    # simulate missing day
    aioclient_mock.get(
        mask_url.format(8741, "2021-06-02"),
        status=HTTPStatus.BAD_GATEWAY,
        text=
        ('{"errors":[{"code":502,"status":"502","title":"Bad response from ESIOS",'
         '"detail":"There are no data for the selected filters."}]}'),
    )

    return aioclient_mock
Esempio n. 25
0
async def test_zeroconf_confirm_connection_error(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test we abort zeroconf flow on Elgato Key Light connection error."""
    aioclient_mock.get("http://1.2.3.4/elgato/accessory-info",
                       exc=aiohttp.ClientError)

    flow = config_flow.ElgatoFlowHandler()
    flow.hass = hass
    flow.context = {
        "source": SOURCE_ZEROCONF,
        CONF_HOST: "1.2.3.4",
        CONF_PORT: 9123,
    }
    result = await flow.async_step_zeroconf_confirm(user_input={
        CONF_HOST: "1.2.3.4",
        CONF_PORT: 9123
    })

    assert result["reason"] == "connection_error"
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
Esempio n. 26
0
async def test_full_zeroconf_flow_implementation(
        opp: OpenPeerPower, aioclient_mock: AiohttpClientMocker) -> None:
    """Test the full manual user flow from start to finish."""
    aioclient_mock.get(
        "http://192.168.1.123:80/json/",
        text=load_fixture("wled/rgb.json"),
        headers={"Content-Type": CONTENT_TYPE_JSON},
    )

    result = await opp.config_entries.flow.async_init(
        DOMAIN,
        context={"source": SOURCE_ZEROCONF},
        data={
            "host": "192.168.1.123",
            "hostname": "example.local.",
            "properties": {}
        },
    )

    flows = opp.config_entries.flow.async_progress()
    assert len(flows) == 1

    assert result.get("description_placeholders") == {CONF_NAME: "example"}
    assert result.get("step_id") == "zeroconf_confirm"
    assert result.get("type") == RESULT_TYPE_FORM
    assert "flow_id" in result

    flow = flows[0]
    assert "context" in flow
    assert flow["context"][CONF_HOST] == "192.168.1.123"
    assert flow["context"][CONF_NAME] == "example"

    result2 = await opp.config_entries.flow.async_configure(result["flow_id"],
                                                            user_input={})

    assert result2.get("title") == "example"
    assert result2.get("type") == RESULT_TYPE_CREATE_ENTRY

    assert "data" in result2
    assert result2["data"][CONF_HOST] == "192.168.1.123"
    assert result2["data"][CONF_MAC] == "aabbccddeeff"
async def test_zeroconf_connection_error(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test we abort zeroconf flow on Elgato Key Light connection error."""
    aioclient_mock.get("http://127.0.0.1/elgato/accessory-info",
                       exc=aiohttp.ClientError)

    result = await hass.config_entries.flow.async_init(
        DOMAIN,
        context={"source": SOURCE_ZEROCONF},
        data=zeroconf.ZeroconfServiceInfo(
            host="127.0.0.1",
            hostname="mock_hostname",
            name="mock_name",
            port=9123,
            properties={},
            type="mock_type",
        ),
    )

    assert result["reason"] == "cannot_connect"
    assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
Esempio n. 28
0
async def test_remove_entry(hass: HomeAssistant,
                            aioclient_mock: AiohttpClientMocker,
                            api_response: str) -> None:
    """Test remove entry."""
    uri = APIURL_TEMPLATE.format(TEST_CONFIG["location"]["longitude"],
                                 TEST_CONFIG["location"]["latitude"])
    aioclient_mock.get(uri, text=api_response)
    entry = MockConfigEntry(domain=DOMAIN, data=TEST_CONFIG, version=2)
    entry.add_to_hass(hass)

    await hass.config_entries.async_setup(entry.entry_id)
    await hass.async_block_till_done()

    state = hass.states.get(ENTITY_ID)
    assert state

    await hass.config_entries.async_remove(entry.entry_id)
    await hass.async_block_till_done()

    state = hass.states.get(ENTITY_ID)
    assert not state
Esempio n. 29
0
async def test_no_alerts(
    hass: HomeAssistant,
    hass_ws_client,
    aioclient_mock: AiohttpClientMocker,
) -> None:
    """Test creating issues based on alerts."""

    aioclient_mock.clear_requests()
    aioclient_mock.get(
        "https://alerts.home-assistant.io/alerts.json",
        text="",
    )

    assert await async_setup_component(hass, DOMAIN, {})

    client = await hass_ws_client(hass)

    await client.send_json({"id": 1, "type": "repairs/list_issues"})
    msg = await client.receive_json()
    assert msg["success"]
    assert msg["result"] == {"issues": []}
Esempio n. 30
0
async def test_hassio_confirm(hass: HomeAssistant,
                              aioclient_mock: AiohttpClientMocker) -> None:
    """Test we can finish a config flow."""
    aioclient_mock.get(
        "http://mock-adguard:3000/control/status",
        json={"version": "v0.99.0"},
        headers={"Content-Type": CONTENT_TYPE_JSON},
    )

    result = await hass.config_entries.flow.async_init(
        DOMAIN,
        data=HassioServiceInfo(config={
            "addon": "AdGuard Home Addon",
            "host": "mock-adguard",
            "port": 3000
        }),
        context={"source": config_entries.SOURCE_HASSIO},
    )
    assert result
    assert result.get("type") == data_entry_flow.FlowResultType.FORM
    assert result.get("step_id") == "hassio_confirm"
    assert result.get("description_placeholders") == {
        "addon": "AdGuard Home Addon"
    }

    result2 = await hass.config_entries.flow.async_configure(
        result["flow_id"], {})

    assert result2
    assert result2.get("type") == data_entry_flow.FlowResultType.CREATE_ENTRY
    assert result2.get("title") == "AdGuard Home Addon"

    data = result2.get("data")
    assert data
    assert data[CONF_HOST] == "mock-adguard"
    assert data[CONF_PASSWORD] is None
    assert data[CONF_PORT] == 3000
    assert data[CONF_SSL] is False
    assert data[CONF_USERNAME] is None
    assert data[CONF_VERIFY_SSL]