예제 #1
0
파일: test_api.py 프로젝트: akfc58/pyopenuv
def main() -> None:
    """Create the aiohttp session and run the example."""
    logging.basicConfig(level=logging.DEBUG)

    client = Client(API_KEY, LATITUDE, LONGITUDE, altitude=ALTITUDE)

    start = time.time()

    try:
        # Get current UV info:
        _LOGGER.info("CURRENT UV DATA:")
        _LOGGER.info(client.uv_index())

        # Get forecasted UV info:
        _LOGGER.info("FORECASTED UV DATA:")
        _LOGGER.info(client.uv_forecast())

        # Get UV protection window:
        _LOGGER.info("UV PROTECTION WINDOW:")
        _LOGGER.info(client.uv_protection_window())
    except OpenUvError as err:
        _LOGGER.info(err)

    end = time.time()

    _LOGGER.info("Execution time: %s seconds", end - start)
예제 #2
0
def test_uv_index_sync(aresponses, event_loop):
    """Test successfully retrieving UV index info (sync)."""
    aresponses.add(
        "api.openuv.io",
        "/api/v1/uv",
        "get",
        aresponses.Response(
            text=load_fixture("uv_index_response.json"),
            status=200,
            headers={"Content-Type": "application/json"},
        ),
    )

    client = Client(
        TEST_API_KEY,
        TEST_LATITUDE,
        TEST_LONGITUDE,
        altitude=TEST_ALTITUDE,
        event_loop=event_loop,
    )
    data = client.uv_index()
    assert data["result"]["uv"] == 8.2342