예제 #1
0
async def system_health_info(hass):
    """Get info for the info page."""
    cloud: Cloud = hass.data[DOMAIN]
    client: CloudClient = cloud.client

    data = {
        "logged_in": cloud.is_logged_in,
    }

    if cloud.is_logged_in:
        data["subscription_expiration"] = cloud.expiration_date
        data["relayer_connected"] = cloud.is_connected
        data["remote_enabled"] = client.prefs.remote_enabled
        data["remote_connected"] = cloud.remote.is_connected
        data["alexa_enabled"] = client.prefs.alexa_enabled
        data["google_enabled"] = client.prefs.google_enabled

    data["can_reach_cert_server"] = system_health.async_check_can_reach_url(
        hass, cloud.acme_directory_server)
    data["can_reach_cloud_auth"] = system_health.async_check_can_reach_url(
        hass,
        f"https://cognito-idp.{cloud.region}.amazonaws.com/{cloud.user_pool_id}/.well-known/jwks.json",
    )
    data["can_reach_cloud"] = system_health.async_check_can_reach_url(
        hass,
        URL(cloud.relayer).with_scheme("https").with_path("/status"))

    return data
예제 #2
0
async def system_health_info(hass):
    """Get info for the info page."""
    mic = None
    uds = {}
    all_devices = {}
    for v in hass.data[DOMAIN].values():
        if isinstance(v, dict):
            v = v.get(CONF_XIAOMI_CLOUD)
        if isinstance(v, MiotCloud):
            mic = v
            if mic.user_id not in uds:
                uds[mic.user_id] = await mic.async_get_devices_by_key('did') or {}
                all_devices.update(uds[mic.user_id])

    api = mic.get_api_url('') if mic else 'https://api.io.mi.com'
    api_spec = 'https://miot-spec.org/miot-spec-v2/spec/services'

    data = {
        'component_version': get_manifest('version', 'unknown'),
        'can_reach_server': system_health.async_check_can_reach_url(hass, api),
        'can_reach_spec': system_health.async_check_can_reach_url(
            hass, api_spec, 'https://home.miot-spec.com/?cant-reach',
        ),
        'logged_accounts': len(uds),
        'total_devices': len(all_devices),
    }

    return data
async def system_health_info(hass):
    """Get info for the info page."""
    hacs: HacsBase = hass.data[DOMAIN]
    response = await hacs.githubapi.rate_limit()

    data = {
        "GitHub API":
        system_health.async_check_can_reach_url(hass, BASE_API_URL,
                                                GITHUB_STATUS),
        "GitHub Content":
        system_health.async_check_can_reach_url(
            hass,
            "https://raw.githubusercontent.com/hacs/integration/main/hacs.json"
        ),
        "GitHub Web":
        system_health.async_check_can_reach_url(hass, "https://github.com/",
                                                GITHUB_STATUS),
        "GitHub API Calls Remaining":
        response.data.resources.core.remaining,
        "Installed Version":
        hacs.version,
        "Stage":
        hacs.stage,
        "Available Repositories":
        len(hacs.repositories.list_all),
        "Downloaded Repositories":
        len(hacs.repositories.list_downloaded),
    }

    if hacs.system.disabled:
        data["Disabled"] = hacs.system.disabled_reason

    return data
예제 #4
0
async def system_health_info(hass: HomeAssistant):
    """Get info for the info page."""
    info = get_info(hass)
    host_info = get_host_info(hass)
    supervisor_info = get_supervisor_info(hass)

    healthy: bool | dict[str, str]
    if supervisor_info.get("healthy"):
        healthy = True
    else:
        healthy = {
            "type": "failed",
            "error": "Unhealthy",
        }

    supported: bool | dict[str, str]
    if supervisor_info.get("supported"):
        supported = True
    else:
        supported = {
            "type": "failed",
            "error": "Unsupported",
        }

    information = {
        "host_os": host_info.get("operating_system"),
        "update_channel": info.get("channel"),
        "supervisor_version": f"supervisor-{info.get('supervisor')}",
        "agent_version": host_info.get("agent_version"),
        "docker_version": info.get("docker"),
        "disk_total": f"{host_info.get('disk_total')} GB",
        "disk_used": f"{host_info.get('disk_used')} GB",
        "healthy": healthy,
        "supported": supported,
    }

    if info.get("hassos") is not None:
        os_info = get_os_info(hass)
        information["board"] = os_info.get("board")

    information["supervisor_api"] = system_health.async_check_can_reach_url(
        hass, SUPERVISOR_PING, OBSERVER_URL
    )
    information["version_api"] = system_health.async_check_can_reach_url(
        hass,
        f"https://version.home-assistant.io/{info.get('channel')}.json",
    )

    information["installed_addons"] = ", ".join(
        f"{addon['name']} ({addon['version']})"
        for addon in supervisor_info.get("addons", [])
    )

    return information
예제 #5
0
async def test_platform_loading(hass, hass_ws_client, aioclient_mock):
    """Test registering via platform."""
    aioclient_mock.get("http://example.com/status", text="")
    aioclient_mock.get("http://example.com/status_fail", exc=ClientError)
    hass.config.components.add("fake_integration")
    mock_platform(
        hass,
        "fake_integration.system_health",
        Mock(
            async_register=lambda hass, register: register.async_register_info(
                AsyncMock(
                    return_value={
                        "hello":
                        "info",
                        "server_reachable":
                        system_health.async_check_can_reach_url(
                            hass, "http://example.com/status"),
                        "server_fail_reachable":
                        system_health.async_check_can_reach_url(
                            hass,
                            "http://example.com/status_fail",
                            more_info="http://more-info-url.com",
                        ),
                        "async_crash":
                        AsyncMock(side_effect=ValueError)(),
                    }),
                "/config/fake_integration",
            )),
    )

    assert await async_setup_component(hass, "system_health", {})
    data = await gather_system_health_info(hass, hass_ws_client)

    assert data["fake_integration"] == {
        "info": {
            "hello": "info",
            "server_reachable": "ok",
            "server_fail_reachable": {
                "type": "failed",
                "error": "unreachable",
                "more_info": "http://more-info-url.com",
            },
            "async_crash": {
                "type": "failed",
                "error": "unknown",
            },
        },
        "manage_url": "/config/fake_integration",
    }
예제 #6
0
async def system_health_info(hass):
    """Get info for the info page."""
    hacs: HacsBase = hass.data[DOMAIN]
    response = await hacs.githubapi.rate_limit()

    data = {
        "GitHub API":
        system_health.async_check_can_reach_url(hass, BASE_API_URL,
                                                GITHUB_STATUS),
        "Github API Calls Remaining":
        response.data.resources.core.remaining,
        "Installed Version":
        hacs.version,
        "Stage":
        hacs.stage,
        "Available Repositories":
        len(hacs.repositories),
        "Installed Repositories":
        len([repo for repo in hacs.repositories if repo.data.installed]),
    }

    if hacs.system.disabled:
        data["Disabled"] = hacs.system.disabled_reason

    return data
async def system_health_info(hass):
    """Get info for the info page."""
    return {
        "api_endpoint_reachable": system_health.async_check_can_reach_url(
            hass, IPMA_API_URL
        )
    }
async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
    """Get info for the info page."""
    return {
        "api_endpoint_reachable":
        system_health.async_check_can_reach_url(
            hass, "https://www.victorsmartkill.com/traps")
    }
예제 #9
0
async def system_health_info(hass):
    """Get info for the info page."""
    return {
        "api_endpoint_reachable":
        system_health.async_check_can_reach_url(hass,
                                                "https://api.spotify.com")
    }
예제 #10
0
async def system_health_info(hass):
    """Get info for the info page."""
    remaining_requests = list(hass.data[DOMAIN].values())[0][
        COORDINATOR
    ].accuweather.requests_remaining

    return {
        "can_reach_server": system_health.async_check_can_reach_url(hass, ENDPOINT),
        "remaining_requests": remaining_requests,
    }
예제 #11
0
async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
    """Get info for the info page."""
    remaining_requests = list(
        hass.data[DOMAIN].values())[0].accuweather.requests_remaining

    return {
        "can_reach_server":
        system_health.async_check_can_reach_url(hass, ENDPOINT),
        "remaining_requests": remaining_requests,
    }
예제 #12
0
async def system_health_info(hass):
    """Get info for the info page."""
    client = hass.data[DOMAIN]

    return {
        "websocket_connection_state":
        client.client.websocket.connection_state,
        "api_endpoint_reachable":
        system_health.async_check_can_reach_url(hass, WEBSOCKET_API_BASE)
    }
예제 #13
0
async def system_health_info(hass):
    """Get info for the info page."""
    client = hass.data[DOMAIN]

    return {
        "component_version":
        VERSION,
        "reach_easee_cloud":
        system_health.async_check_can_reach_url(
            hass, client["controller"].easee.base_uri()),
        "connected2stream":
        client["controller"].easee.sr_is_connected(),
    }
예제 #14
0
async def system_health_info(hass):
    """Get info for the info page."""
    is_logged_in = hass.data[DOMAIN].get('cloud_instance') is not None

    data = {
        "logged_in": is_logged_in,
    }

    if is_logged_in:
        data[
            "can_reach_micloud_server"] = system_health.async_check_can_reach_url(
                hass, "https://api.io.mi.com")

    return data
예제 #15
0
async def system_health_info(hass):
    """Get info for the info page."""
    requests_remaining = list(
        hass.data[DOMAIN].values())[0].airly.requests_remaining
    requests_per_day = list(
        hass.data[DOMAIN].values())[0].airly.requests_per_day

    return {
        "can_reach_server":
        system_health.async_check_can_reach_url(hass, Airly.AIRLY_API_URL),
        "requests_remaining":
        requests_remaining,
        "requests_per_day":
        requests_per_day,
    }
예제 #16
0
async def system_health_info(hass):
    """Get info for the info page."""
    is_logged_in = hass.data[DOMAIN].get('cloud_instance') is not None

    data = {
        "logged_in": is_logged_in,
    }

    if is_logged_in:
        data[
            "can_reach_micloud_server"] = system_health.async_check_can_reach_url(
                hass, "https://api.io.mi.com")
        data["account_devices_count"] = len(
            hass.data[DOMAIN]['micloud_devices'])

    if hass.data[DOMAIN].get('configs'):
        data["added_devices"] = len(
            hass.data[DOMAIN]['configs']) - (1 if is_logged_in else 0)

    return data
예제 #17
0
async def system_health_info(hass):
    """Get info for the info page."""
    client: HacsBase = hass.data[DOMAIN]
    rate_limit = await client.github.get_rate_limit()

    return {
        "GitHub API":
        system_health.async_check_can_reach_url(hass, BASE_API_URL,
                                                GITHUB_STATUS),
        "Github API Calls Remaining":
        rate_limit.get("remaining", "0"),
        "Installed Version":
        client.version,
        "Stage":
        client.stage,
        "Available Repositories":
        len(client.repositories),
        "Installed Repositories":
        len([repo for repo in client.repositories if repo.data.installed]),
    }
예제 #18
0
async def system_health_info(hass):
    """Get info for the info page."""
    return {
        "Reach API endpoint":
        system_health.async_check_can_reach_url(hass, METEOALARMEU_SERVER_URL)
    }
예제 #19
0
async def system_health_info(hass):
    """Get info for the info page."""
    return {
        "can_reach_server":
        system_health.async_check_can_reach_url(hass, API_ENDPOINT)
    }
예제 #20
0
async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
    """Get info for the info page."""
    return {
        "can_reach_server":
        system_health.async_check_can_reach_url(hass, API_ENDPOINT)
    }
예제 #21
0
async def system_health_info(hass):
    """Get info for the info page."""
    return {
        "can_reach_server":
        system_health.async_check_can_reach_url(hass, Airly.AIRLY_API_URL)
    }