Example #1
0
async def system_health_info(opp):
    """Get info for the info page."""
    cloud: Cloud = opp.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(
        opp, cloud.acme_directory_server
    )
    data["can_reach_cloud_auth"] = system_health.async_check_can_reach_url(
        opp,
        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(
        opp, URL(cloud.relayer).with_scheme("https").with_path("/status")
    )

    return data
Example #2
0
async def test_platform_loading(opp, opp_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)
    aioclient_mock.get("http://example.com/timeout", exc=asyncio.TimeoutError)
    opp.config.components.add("fake_integration")
    mock_platform(
        opp,
        "fake_integration.system_health",
        Mock(async_register=lambda opp, register: register.async_register_info(
            AsyncMock(
                return_value={
                    "hello":
                    "info",
                    "server_reachable":
                    system_health.async_check_can_reach_url(
                        opp, "http://example.com/status"),
                    "server_fail_reachable":
                    system_health.async_check_can_reach_url(
                        opp,
                        "http://example.com/status_fail",
                        more_info="http://more-info-url.com",
                    ),
                    "server_timeout":
                    system_health.async_check_can_reach_url(
                        opp,
                        "http://example.com/timeout",
                        more_info="http://more-info-url.com",
                    ),
                    "async_crash":
                    AsyncMock(side_effect=ValueError)(),
                }),
            "/config/fake_integration",
        )),
    )

    assert await async_setup_component(opp, "system_health", {})
    data = await gather_system_health_info(opp, opp_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",
            },
            "server_timeout": {
                "type": "failed",
                "error": "timeout",
                "more_info": "http://more-info-url.com",
            },
            "async_crash": {
                "type": "failed",
                "error": "unknown",
            },
        },
        "manage_url": "/config/fake_integration",
    }
Example #3
0
async def system_health_info(opp: OpenPeerPower):
    """Get info for the info page."""
    info = opp.components.oppio.get_info()
    host_info = opp.components.oppio.get_host_info()
    supervisor_info = opp.components.oppio.get_supervisor_info()

    if supervisor_info.get("healthy"):
        healthy = True
    else:
        healthy = {
            "type": "failed",
            "error": "Unhealthy",
            "more_info": "/oppio/system",
        }

    if supervisor_info.get("supported"):
        supported = True
    else:
        supported = {
            "type": "failed",
            "error": "Unsupported",
            "more_info": "/oppio/system",
        }

    information = {
        "host_os": host_info.get("operating_system"),
        "update_channel": info.get("channel"),
        "supervisor_version": f"supervisor-{info.get('supervisor')}",
        "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("oppos") is not None:
        os_info = opp.components.oppio.get_os_info()
        information["board"] = os_info.get("board")

    information["supervisor_api"] = system_health.async_check_can_reach_url(
        opp, SUPERVISOR_PING, OBSERVER_URL)
    information["version_api"] = system_health.async_check_can_reach_url(
        opp,
        f"https://version.openpeerpower.io/{info.get('channel')}.json",
        "/oppio/system",
    )

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

    return information
Example #4
0
async def system_health_info(opp):
    """Get info for the info page."""
    return {
        "api_endpoint_reachable": system_health.async_check_can_reach_url(
            opp, "https://api.spotify.com"
        )
    }
Example #5
0
async def system_health_info(opp: OpenPeerPower) -> dict[str, Any]:
    """Get info for the info page."""
    remaining_requests = list(opp.data[DOMAIN].values()
                              )[0][COORDINATOR].accuweather.requests_remaining

    return {
        "can_reach_server":
        system_health.async_check_can_reach_url(opp, ENDPOINT),
        "remaining_requests": remaining_requests,
    }
Example #6
0
async def system_health_info(opp: OpenPeerPower) -> dict[str, Any]:
    """Get info for the info page."""
    requests_remaining = list(
        opp.data[DOMAIN].values())[0].airly.requests_remaining
    requests_per_day = list(
        opp.data[DOMAIN].values())[0].airly.requests_per_day

    return {
        "can_reach_server":
        system_health.async_check_can_reach_url(opp, Airly.AIRLY_API_URL),
        "requests_remaining":
        requests_remaining,
        "requests_per_day":
        requests_per_day,
    }
Example #7
0
async def system_health_info(opp: OpenPeerPower) -> dict[str, Any]:
    """Get info for the info page."""
    return {
        "can_reach_server":
        system_health.async_check_can_reach_url(opp, API_ENDPOINT)
    }
Example #8
0
async def system_health_info(opp):
    """Get info for the info page."""
    return {
        "api_endpoint_reachable":
        system_health.async_check_can_reach_url(opp, IPMA_API_URL)
    }