예제 #1
0
파일: poller.py 프로젝트: a8/discovergy
async def discovergy_meter_read_task(
    *,
    config: Box,
    loop: asyncio.base_events.BaseEventLoop,
) -> None:
    """Async worker to poll the Discovergy API."""
    meters = power.get_meters(config)
    read_interval = timedelta(seconds=int(config.poll.discovergy))
    date_to = arrow.utcnow()
    date_from = date_to - read_interval
    log.debug(f"The Discovergy read interval is {read_interval}.")
    while loop.is_running():
        try:
            # FIXME (a8): This isn't an async call yet because we use requests. OTHO, this doesn't
            # really matter ATM. We only call Discovergy every few hours.
            power.get(config=config,
                      meters=meters,
                      date_from=date_from,
                      date_to=date_to)
        except Exception as e:
            log.warning(
                "Error in Discovergy poller. Retrying in 15 seconds. {}".
                format(str(e)))
            await asyncio.sleep(15)
        else:
            await asyncio.sleep(read_interval.seconds)
            date_from = date_to
            date_to = arrow.utcnow()
예제 #2
0
파일: poller.py 프로젝트: a8/discovergy
async def awattar_read_task(
    *,
    config: Box,
    loop: asyncio.base_events.BaseEventLoop,
) -> None:
    """Async worker to poll the Open Weather Map API."""
    read_interval = timedelta(seconds=int(config.poll.awattar))
    log.debug(f"The Awattar read interval is {read_interval}.")
    while loop.is_running():
        try:
            await awattar.get(config=config)
        except Exception as e:
            log.warning(
                "Error in Awattar data poller. Retrying in 15 seconds. {}".
                format(str(e)))
            await asyncio.sleep(15)
        else:
            await asyncio.sleep(read_interval.seconds)
예제 #3
0
파일: poller.py 프로젝트: a8/discovergy
async def open_weather_map_read_task(
    *,
    config: Box,
    loop: asyncio.base_events.BaseEventLoop,
) -> None:
    """Async worker to poll the Open Weather Map API."""
    read_interval = timedelta(seconds=int(config.poll.weather))
    log.debug(f"The Open Weather Map read interval is {read_interval}.")
    while loop.is_running():
        try:
            # FIXME (a8): This isn't an async call yet because we use requests.
            weather.get(config=config)
        except Exception as e:
            log.warning(
                "Error in Open Weather Map poller. Retrying in 15 seconds. {}".
                format(str(e)))
            await asyncio.sleep(15)
        else:
            await asyncio.sleep(read_interval.seconds)