# 🌤️ Python Wrapper for WeatherFlow REST API
![Latest PyPI version](https://img.shields.io/pypi/v/pyweatherflowrest) ![Supported Python](https://img.shields.io/pypi/pyversions/pyweatherflowrest)
This module communicates with a WeatherFlow Weather Station using a [their REST API](https://weatherflow.github.io/Tempest/api/swagger/#/).
The module is primarily written for the purpose of being used in Home Assistant for the Custom Integration called [`weatherflow`](https://github.com/briis/hass-weatherflow) but might be used for other purposes also.
When this is done, it will replace the previous module [`pysmartweatherio`](https://github.com/briis/pysmartweatherio)
## Install
`pyweatherflowrest` is avaible on PyPi:
```bash
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](https://tempestwx.com/settings/tokens) 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.
```python
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())
```
Raw data
{
"_id": null,
"home_page": "https://github.com/briis/pyweatherflowrest",
"name": "pyweatherflowrest",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "Home Assistant,Python,WeatherFlow",
"author": "Bjarne Riis",
"author_email": "bjarne@briis.com",
"download_url": "https://files.pythonhosted.org/packages/61/f3/442c08dadf2b7964871aed0b1739542e1d1fa046b557c34a4b333b538f52/pyweatherflowrest-1.0.11.tar.gz",
"platform": null,
"description": "# \ud83c\udf24\ufe0f Python Wrapper for WeatherFlow REST API\n\n![Latest PyPI version](https://img.shields.io/pypi/v/pyweatherflowrest) ![Supported Python](https://img.shields.io/pypi/pyversions/pyweatherflowrest)\n\nThis module communicates with a WeatherFlow Weather Station using a [their REST API](https://weatherflow.github.io/Tempest/api/swagger/#/).\n\nThe module is primarily written for the purpose of being used in Home Assistant for the Custom Integration called [`weatherflow`](https://github.com/briis/hass-weatherflow) but might be used for other purposes also.\n\nWhen this is done, it will replace the previous module [`pysmartweatherio`](https://github.com/briis/pysmartweatherio)\n\n## Install\n\n`pyweatherflowrest` is avaible on PyPi:\n\n```bash\npip install pyweatherflowrest\n```\n\n## Usage\n\nThis library is primarily designed to be used in an async context.\n\nThe main interface for the library is the `pyweatherflowrest.WeatherFlowApiClient`. This interface takes 6 options:\n\n* `station_id`: (required) Supply the station id for the station you want data for.\n* `api_token`: (required) Enter your personal api token for the above station id. You can get your *Personal Use Token* [by going here](https://tempestwx.com/settings/tokens) and login with your credentials. Then click CREATE TOKEN in the upper right corner.\n* `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**\n* `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.\n* `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**\n* `session`: (optional) An existing *aiohttp.ClientSession*. Default value is **None**, and then a new ClientSession will be created.\n\n```python\nimport asyncio\nimport logging\nimport time\n\nfrom pyweatherflowrest.api import WeatherFlowApiClient\nfrom pyweatherflowrest.data import ObservationDescription, StationDescription, ForecastDescription, ForecastDailyDescription\nfrom pyweatherflowrest.exceptions import WrongStationID, Invalid, NotAuthorized, BadRequest\n\n_LOGGER = logging.getLogger(__name__)\n\nasync def main() -> None:\n logging.basicConfig(level=logging.DEBUG)\n start = time.time()\n\n weatherflow = WeatherFlowApiClient(\"YOUR STATION ID\", \"YOUR TOKEN\")\n try:\n await weatherflow.initialize() # Must be the first call\n\n except WrongStationID as err:\n _LOGGER.debug(err)\n except Invalid as err:\n _LOGGER.debug(err)\n except NotAuthorized as err:\n _LOGGER.debug(err)\n except BadRequest as err:\n _LOGGER.debug(err)\n\n data: StationDescription = weatherflow.station_data\n if data is not None:\n for field in data.__dataclass_fields__:\n value = getattr(data, field)\n print(field,\"-\", value)\n\n data: ObservationDescription = await weatherflow.update_observations()\n if data is not None:\n for field in data.__dataclass_fields__:\n value = getattr(data, field)\n print(field,\"-\", value)\n\n\n data: ForecastDescription = await weatherflow.update_forecast()\n if data is not None:\n for field in data.__dataclass_fields__:\n value = getattr(data, field)\n if field == \"forecast_daily\":\n for item in value:\n print(item.conditions, item.air_temp_high)\n elif field == \"forecast_hourly\":\n for item in value:\n print(item.conditions, item.air_temperature)\n else:\n print(field,\"-\", value)\n\n end = time.time()\n\n await weatherflow.req.close()\n\n _LOGGER.info(\"Execution time: %s seconds\", end - start)\n\nasyncio.run(main())\n\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python Wrapper for WeatherFlow Rest API",
"version": "1.0.11",
"project_urls": {
"Homepage": "https://github.com/briis/pyweatherflowrest"
},
"split_keywords": [
"home assistant",
"python",
"weatherflow"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ad83f29ee52bffa7d4e5298c922bda2e02f10c13a1265e16efb871979e35e347",
"md5": "b944370ccf50b21dfef73f339112af9c",
"sha256": "5d7fca829dcb97afa32695e1439c30b14a4d61ebca0bb931ab9ef7a3f0d43d1e"
},
"downloads": -1,
"filename": "pyweatherflowrest-1.0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b944370ccf50b21dfef73f339112af9c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 14416,
"upload_time": "2023-08-31T04:55:37",
"upload_time_iso_8601": "2023-08-31T04:55:37.478130Z",
"url": "https://files.pythonhosted.org/packages/ad/83/f29ee52bffa7d4e5298c922bda2e02f10c13a1265e16efb871979e35e347/pyweatherflowrest-1.0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "61f3442c08dadf2b7964871aed0b1739542e1d1fa046b557c34a4b333b538f52",
"md5": "2839f0039e950d218cfe7cfb4545ebe9",
"sha256": "766dc11ed8f4176879e149b7a782ef11852200f6f9c59801d2314e7003e6641d"
},
"downloads": -1,
"filename": "pyweatherflowrest-1.0.11.tar.gz",
"has_sig": false,
"md5_digest": "2839f0039e950d218cfe7cfb4545ebe9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15551,
"upload_time": "2023-08-31T04:55:39",
"upload_time_iso_8601": "2023-08-31T04:55:39.118158Z",
"url": "https://files.pythonhosted.org/packages/61/f3/442c08dadf2b7964871aed0b1739542e1d1fa046b557c34a4b333b538f52/pyweatherflowrest-1.0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-31 04:55:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "briis",
"github_project": "pyweatherflowrest",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "pyweatherflowrest"
}