Skip to main content

Python Wrapper for WeatherFlow Rest API

Project description

🌤️ Python Wrapper for WeatherFlow REST API

Latest PyPI version Supported Python

This module communicates with a WeatherFlow Weather Station using a their REST API.

The module is primarily written for the purpose of being used in Home Assistant for the Custom Integration called weatherflow but might be used for other purposes also.

When this is done, it will replace the previous module pysmartweatherio

Install

pyweatherflowrest is avaible on PyPi:

pip install pyweatherflowrest

Usage

This library is primarily designed to be used in an async context.

The main interface for the library is the pyweatherflowrest.WeatherFlowApiClient. This interface takes 6 options:

  • station_id: (required) Supply the station id for the station you want data for.
  • api_token: (required) Enter your personal api token for the above station id. You can get your Personal Use Token by going here and login with your credentials. Then click CREATE TOKEN in the upper right corner.
  • units: (optional) Valid options here are metric or imperial. WeatherFlow stations always deliver data in metric units, so conversion will only take place if if metric is not selected. Default value is metric
  • forecast_hours: (optional) Specify how many hours of the Hourly Forecast that needs to be retrieved. Values between 1 and 240 are valid. Default value is 48 hours.
  • homeassistant: (optional) Valid options are True or False. If set to True, there will be some unit types that will not be converted, as Home Assistant will take care of that. Default value is False
  • session: (optional) An existing aiohttp.ClientSession. Default value is None, and then a new ClientSession will be created.
import asyncio
import logging
import time

from pyweatherflowrest.api import WeatherFlowApiClient
from pyweatherflowrest.data import ObservationDescription, StationDescription, ForecastDescription, ForecastDailyDescription
from pyweatherflowrest.exceptions import WrongStationID, Invalid, NotAuthorized, BadRequest

_LOGGER = logging.getLogger(__name__)

async def main() -> None:
    logging.basicConfig(level=logging.DEBUG)
    start = time.time()

    weatherflow = WeatherFlowApiClient("YOUR STATION ID", "YOUR TOKEN")
    try:
        await weatherflow.initialize() # Must be the first call

    except WrongStationID as err:
        _LOGGER.debug(err)
    except Invalid as err:
        _LOGGER.debug(err)
    except NotAuthorized as err:
        _LOGGER.debug(err)
    except BadRequest as err:
        _LOGGER.debug(err)

    data: StationDescription = weatherflow.station_data
    if data is not None:
        for field in data.__dataclass_fields__:
            value = getattr(data, field)
            print(field,"-", value)

    data: ObservationDescription = await weatherflow.update_observations()
    if data is not None:
        for field in data.__dataclass_fields__:
            value = getattr(data, field)
            print(field,"-", value)


    data: ForecastDescription = await weatherflow.update_forecast()
    if data is not None:
        for field in data.__dataclass_fields__:
            value = getattr(data, field)
            if field == "forecast_daily":
                for item in value:
                    print(item.conditions, item.air_temp_high)
            elif field == "forecast_hourly":
                for item in value:
                    print(item.conditions, item.air_temperature)
            else:
                print(field,"-", value)

    end = time.time()

    await weatherflow.req.close()

    _LOGGER.info("Execution time: %s seconds", end - start)

asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyweatherflowrest-1.0.11.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

pyweatherflowrest-1.0.11-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file pyweatherflowrest-1.0.11.tar.gz.

File metadata

  • Download URL: pyweatherflowrest-1.0.11.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pyweatherflowrest-1.0.11.tar.gz
Algorithm Hash digest
SHA256 766dc11ed8f4176879e149b7a782ef11852200f6f9c59801d2314e7003e6641d
MD5 2839f0039e950d218cfe7cfb4545ebe9
BLAKE2b-256 61f3442c08dadf2b7964871aed0b1739542e1d1fa046b557c34a4b333b538f52

See more details on using hashes here.

File details

Details for the file pyweatherflowrest-1.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for pyweatherflowrest-1.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 5d7fca829dcb97afa32695e1439c30b14a4d61ebca0bb931ab9ef7a3f0d43d1e
MD5 b944370ccf50b21dfef73f339112af9c
BLAKE2b-256 ad83f29ee52bffa7d4e5298c922bda2e02f10c13a1265e16efb871979e35e347

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page