コード例 #1
0
async def test_request_error(aresponses, event_loop):
    """Test authenticating the device."""
    aresponses.add(
        "www.pollen.com",
        "/api/bad_endpoint/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text="", status=404),
    )
    aresponses.add(
        "www.pollen.com",
        "/api/forecast/outlook/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text="", status=500),
    )

    with pytest.raises(RequestError):
        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = Client(TEST_ZIP, websession)
            await client._request("get",
                                  "https://www.pollen.com/api/bad_endpoint")

    with pytest.raises(RequestError):
        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = Client(TEST_ZIP, websession)
            await client.allergens.outlook()
コード例 #2
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Configure the platform and add the sensors."""
    from pypollencom import Client

    _LOGGER.debug('Configuration data: %s', config)

    client = Client(config[CONF_ZIP_CODE])
    datas = {
        'allergy_average_data': AllergyAveragesData(client),
        'allergy_index_data': AllergyIndexData(client),
        'disease_average_data': DiseaseData(client)
    }

    for data in datas.values():
        data.update()

    sensors = []
    for condition in config[CONF_MONITORED_CONDITIONS]:
        name, sensor_class, data_key, params, icon = CONDITIONS[condition]
        sensors.append(globals()[sensor_class](
            datas[data_key],
            params,
            name,
            icon
        ))

    add_devices(sensors, True)
コード例 #3
0
ファイル: test_asthma.py プロジェクト: bachya/pypollencom
async def test_endpoints(aresponses, event_loop, fixture_current,
                         fixture_extended, fixture_historic):
    """Test all endpoints."""
    aresponses.add(
        "www.asthmaforecast.com",
        "/api/forecast/current/asthma/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text=json.dumps(fixture_current), status=200),
    )
    aresponses.add(
        "www.asthmaforecast.com",
        "/api/forecast/extended/asthma/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text=json.dumps(fixture_extended), status=200),
    )
    aresponses.add(
        "www.asthmaforecast.com",
        "/api/forecast/historic/asthma/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text=json.dumps(fixture_historic), status=200),
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        client = Client(TEST_ZIP, websession)

        current = await client.asthma.current()
        assert len(current["Location"]["periods"]) == 3

        extended = await client.asthma.extended()
        assert len(extended["Location"]["periods"]) == 5

        historic = await client.asthma.historic()
        assert len(historic["Location"]["periods"]) == 30
コード例 #4
0
async def test_endpoints(aresponses, event_loop, fixture_extended):
    """Test all endpoints."""
    aresponses.add(
        "www.pollen.com",
        "/api/forecast/extended/cold/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text=json.dumps(fixture_extended), status=200),
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        client = Client(TEST_ZIP, websession)

        extended = await client.disease.extended()
        assert len(extended["Location"]["periods"]) == 4
コード例 #5
0
ファイル: test_allergens.py プロジェクト: bachya/pypollencom
async def test_bad_zip(aresponses, event_loop, fixture_empty_response):
    """Test the cases that would arise from a bad ZIP code."""
    aresponses.add(
        "www.pollen.com",
        "/api/forecast/current/pollen/{0}".format(TEST_BAD_ZIP),
        "get",
        aresponses.Response(text=json.dumps(fixture_empty_response), status=200),
    )
    aresponses.add(
        "www.pollen.com",
        "/api/forecast/outlook/{0}".format(TEST_BAD_ZIP),
        "get",
        aresponses.Response(text="", status=404),
    )

    with pytest.raises(InvalidZipError):
        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = Client(TEST_BAD_ZIP, websession)
            await client.allergens.current()

    with pytest.raises(InvalidZipError):
        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = Client(TEST_BAD_ZIP, websession)
            await client.allergens.outlook()
コード例 #6
0
ファイル: test_allergens.py プロジェクト: bachya/pypollencom
async def test_endpoints(  # pylint: disable=too-many-arguments
    aresponses,
    event_loop,
    fixture_current,
    fixture_extended,
    fixture_historic,
    fixture_outlook,
):
    """Test all endpoints."""
    aresponses.add(
        "www.pollen.com",
        "/api/forecast/current/pollen/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text=json.dumps(fixture_current), status=200),
    )
    aresponses.add(
        "www.pollen.com",
        "/api/forecast/extended/pollen/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text=json.dumps(fixture_extended), status=200),
    )
    aresponses.add(
        "www.pollen.com",
        "/api/forecast/historic/pollen/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text=json.dumps(fixture_historic), status=200),
    )
    aresponses.add(
        "www.pollen.com",
        "/api/forecast/outlook/{0}".format(TEST_ZIP),
        "get",
        aresponses.Response(text=json.dumps(fixture_outlook), status=200),
    )

    async with aiohttp.ClientSession(loop=event_loop) as websession:
        client = Client(TEST_ZIP, websession)

        current = await client.allergens.current()
        assert len(current["Location"]["periods"]) == 3

        extended = await client.allergens.extended()
        assert len(extended["Location"]["periods"]) == 5

        historic = await client.allergens.historic()
        assert len(historic["Location"]["periods"]) == 30

        outlook = await client.allergens.outlook()
        assert outlook["Trend"] == "subsiding"
コード例 #7
0
async def async_setup_platform(
        hass, config, async_add_entities, discovery_info=None):
    """Configure the platform and add the sensors."""
    from pypollencom import Client

    websession = aiohttp_client.async_get_clientsession(hass)

    pollen = PollenComData(
        Client(config[CONF_ZIP_CODE], websession),
        config[CONF_MONITORED_CONDITIONS])

    await pollen.async_update()

    sensors = []
    for kind in config[CONF_MONITORED_CONDITIONS]:
        sensor_class, name, icon = SENSORS[kind]
        sensors.append(
            globals()[sensor_class](
                pollen, kind, name, icon, config[CONF_ZIP_CODE]))

    async_add_entities(sensors, True)
コード例 #8
0
ファイル: pollen.py プロジェクト: sara0871/master.zip
async def async_setup_platform(
        hass, config, async_add_devices, discovery_info=None):
    """Configure the platform and add the sensors."""
    from pypollencom import Client

    websession = aiohttp_client.async_get_clientsession(hass)

    data = PollenComData(
        Client(config[CONF_ZIP_CODE], websession),
        config[CONF_MONITORED_CONDITIONS])

    await data.async_update()

    sensors = []
    for kind in config[CONF_MONITORED_CONDITIONS]:
        name, category, icon, unit = SENSORS[kind]
        sensors.append(
            PollencomSensor(
                data, config[CONF_ZIP_CODE], kind, category, name, icon, unit))

    async_add_devices(sensors, True)
コード例 #9
0
ファイル: example.py プロジェクト: bachya/pypollencom
async def run(websession):
    """Run."""
    try:
        client = Client("17015", websession)
        print('Client instantiated for ZIP "{0}"'.format(client.zip_code))

        print()
        print("CURRENT ALLERGENS")
        print(await client.allergens.current())

        print()
        print("EXTENDED ALLERGENS")
        print(await client.allergens.extended())

        print()
        print("HISTORIC ALLERGENS")
        print(await client.allergens.historic())

        print()
        print("ALLERGY OUTLOOK")
        print(await client.allergens.outlook())

        print()
        print("EXTENDED DISEASE INFO")
        print(await client.disease.extended())

        print()
        print("CURRENT ASTHMA INFO")
        print(await client.asthma.current())

        print()
        print("EXTENDED ASTHMA INFO")
        print(await client.asthma.extended())

        print()
        print("HISTORIC ASTHMA INFO")
        print(await client.asthma.historic())
    except PollenComError as err:
        print(err)
コード例 #10
0
async def test_create():
    """Test the creation of a client."""
    async with aiohttp.ClientSession() as websession:
        client = Client(TEST_ZIP, websession)
        assert client.zip_code == TEST_ZIP