PyHolfuy 0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- holfuy/__init__.py +131 -0
- holfuy/const.py +20 -0
- pyholfuy-0.0.dist-info/METADATA +55 -0
- pyholfuy-0.0.dist-info/RECORD +7 -0
- pyholfuy-0.0.dist-info/WHEEL +5 -0
- pyholfuy-0.0.dist-info/licenses/LICENSE +21 -0
- pyholfuy-0.0.dist-info/top_level.txt +1 -0
holfuy/__init__.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Library to handle connection with Holfuy Live API."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import aiohttp
|
|
9
|
+
|
|
10
|
+
from .const import (
|
|
11
|
+
CONF_TEMPERATURE_UNIT_CELSUIS,
|
|
12
|
+
CONF_WIND_SPEED_UNIT_MS,
|
|
13
|
+
CONF_AVERAGING_NEWEST,
|
|
14
|
+
CONF_MODE_JSON,
|
|
15
|
+
STATIONS_ALL,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
TIMEOUT = 30
|
|
19
|
+
_LOGGER = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
API_URL = "http://api.holfuy.com/live/"
|
|
22
|
+
|
|
23
|
+
# noqa: E501
|
|
24
|
+
#### API Description
|
|
25
|
+
# URL Format: http://api.holfuy.com/live/?s=101&pw=pass&m=JSON&tu=C&su=m/s
|
|
26
|
+
#
|
|
27
|
+
# s: station(s) ID e.g. s=101 or you can get the data from more stations by one query as well (coma separated list) e.g. s=101,102,103 . If you would get all stations' data (to which you have access) by one single API call please use the "all" string -> s=all .
|
|
28
|
+
# pw: password for the API access (it could be sent by a POST "pw" parameter also)
|
|
29
|
+
# m:mode XML or CSV or JSON default: CSV
|
|
30
|
+
# avg:averaging "0": newest data from the station, "1" newest quarter hourly average, "2" newest hourly average (default = 0)
|
|
31
|
+
# su: wind speed unit: knots, km/h, m/s, mph, default: m/s
|
|
32
|
+
# tu: temperature unit C:Celsius , F: Fahrenheit default: Celsius
|
|
33
|
+
# batt: add this parameter to get the station's battery voltage (JSON only).
|
|
34
|
+
# cam: add this parameter to the URL for timestamp of the last picture from the camera. (JSON only, only for stations with a camera)
|
|
35
|
+
# daily: add this parameter to get daily Max-Min temperatures and precipitation since last midnight CE(S)T (JSON only, max 5 stations)
|
|
36
|
+
# loc: add this parameter to the URL to get the station's location in reply too (JSON only)
|
|
37
|
+
# utc: add this parameter to the URL for timestamps in UTC, otherwise times will be in CE(S)T
|
|
38
|
+
# Data: DateTime: time of the last data / average in ".date('T')." (Central European Time) or in UTC if utc param is set.
|
|
39
|
+
#####
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class HolfuyService:
|
|
43
|
+
"""Representation of Holfuy weather data."""
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
api_key: str,
|
|
48
|
+
websession=None,
|
|
49
|
+
temperature_unit=CONF_TEMPERATURE_UNIT_CELSUIS,
|
|
50
|
+
wind_speed_unit=CONF_WIND_SPEED_UNIT_MS,
|
|
51
|
+
timestamps_in_utc=False,
|
|
52
|
+
) -> None:
|
|
53
|
+
"""Initialize the Weather object."""
|
|
54
|
+
|
|
55
|
+
self._api_url = API_URL
|
|
56
|
+
self._api_key = api_key
|
|
57
|
+
self._wind_speed_unit = wind_speed_unit
|
|
58
|
+
self._temperature_unit = temperature_unit
|
|
59
|
+
self._timestamps_in_utc = timestamps_in_utc
|
|
60
|
+
|
|
61
|
+
if websession is None:
|
|
62
|
+
|
|
63
|
+
async def _create_session():
|
|
64
|
+
return aiohttp.ClientSession()
|
|
65
|
+
|
|
66
|
+
loop = asyncio.get_event_loop()
|
|
67
|
+
self._websession = loop.run_until_complete(_create_session())
|
|
68
|
+
else:
|
|
69
|
+
self._websession = websession
|
|
70
|
+
|
|
71
|
+
async def fetch_data(
|
|
72
|
+
self,
|
|
73
|
+
stations: list[str] | None = None,
|
|
74
|
+
averaging_mode=CONF_AVERAGING_NEWEST,
|
|
75
|
+
include_battery=False,
|
|
76
|
+
include_daily=False,
|
|
77
|
+
include_location=False,
|
|
78
|
+
) -> dict[str, Any] | None:
|
|
79
|
+
"""Get the latest data from Holfuy."""
|
|
80
|
+
|
|
81
|
+
params = {
|
|
82
|
+
"pw": self._api_key,
|
|
83
|
+
"m": CONF_MODE_JSON,
|
|
84
|
+
"tu": self._temperature_unit,
|
|
85
|
+
"su": self._wind_speed_unit,
|
|
86
|
+
"avg": averaging_mode,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if self._timestamps_in_utc:
|
|
90
|
+
params["utc"] = ""
|
|
91
|
+
|
|
92
|
+
if include_battery:
|
|
93
|
+
params["batt"] = ""
|
|
94
|
+
|
|
95
|
+
if include_daily:
|
|
96
|
+
params["daily"] = ""
|
|
97
|
+
|
|
98
|
+
if include_location:
|
|
99
|
+
params["loc"] = ""
|
|
100
|
+
|
|
101
|
+
if stations:
|
|
102
|
+
params["s"] = ",".join(map(str, stations))
|
|
103
|
+
else:
|
|
104
|
+
params["s"] = STATIONS_ALL
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
async with asyncio.timeout(TIMEOUT):
|
|
108
|
+
resp = await self._websession.get(self._api_url, params=params)
|
|
109
|
+
|
|
110
|
+
if resp.status >= 400:
|
|
111
|
+
_LOGGER.error("%s returned %s", self._api_url, resp.status)
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
result = await resp.json()
|
|
115
|
+
|
|
116
|
+
# Request for a single station is not enveloped in a list of
|
|
117
|
+
# measurements objects. Make data consistent for all request types before it
|
|
118
|
+
# is returned.
|
|
119
|
+
if stations and len(stations) == 1:
|
|
120
|
+
result = {"measurements": result}
|
|
121
|
+
|
|
122
|
+
return result
|
|
123
|
+
|
|
124
|
+
except (TimeoutError, aiohttp.ClientError) as err:
|
|
125
|
+
_LOGGER.error(
|
|
126
|
+
"Access to %s returned error '%s'", self._api_url, type(err).__name__
|
|
127
|
+
)
|
|
128
|
+
return None
|
|
129
|
+
except ValueError:
|
|
130
|
+
_LOGGER.exception("Unable to parse json response from %s", self._api_url)
|
|
131
|
+
return None
|
holfuy/const.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
CONF_MODE_JSON = "JSON" # We only handle JSON from the api
|
|
2
|
+
CONF_MODE_XML = "CSV"
|
|
3
|
+
CONF_MODE_CSV = "XML"
|
|
4
|
+
|
|
5
|
+
CONF_AVERAGING_NEWEST = 0
|
|
6
|
+
CONF_AVERAGING_QUARTERLY = 1
|
|
7
|
+
CONF_AVERAGING_HOURLY = 2
|
|
8
|
+
|
|
9
|
+
CONF_WIND_SPEED_UNIT_KNOTS = "knots"
|
|
10
|
+
CONF_WIND_SPEED_UNIT_KMH = "km/h"
|
|
11
|
+
CONF_WIND_SPEED_UNIT_MS = "m/s"
|
|
12
|
+
CONF_WIND_SPEED_UNIT_MPH = "mph"
|
|
13
|
+
|
|
14
|
+
CONF_TEMPERATURE_UNIT_CELSUIS = "Celsius"
|
|
15
|
+
CONF_TEMPERATURE_UNIT_FAHRENHEIT = "Fahrenheit"
|
|
16
|
+
|
|
17
|
+
CONF_OPTION_BATT = "batt"
|
|
18
|
+
CONF_OPTION_DAILY = "daily"
|
|
19
|
+
|
|
20
|
+
STATIONS_ALL = "all"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PyHolfuy
|
|
3
|
+
Version: 0.0
|
|
4
|
+
Summary: A Python library for interacting with Holfuy weather stations.
|
|
5
|
+
Author-email: Håvard Dagenborg <haavardj@dagenborg.net>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: homepage, https://github.com/haavardj/PyHolfuy
|
|
8
|
+
Keywords: weather,holfuy,api,python
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: aiohttp>=3.9.4
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: aioresponses==0.7.8; extra == "test"
|
|
17
|
+
Requires-Dist: coverage==7.8.0; extra == "test"
|
|
18
|
+
Requires-Dist: mypy==1.15.0; extra == "test"
|
|
19
|
+
Requires-Dist: pytest-asyncio==0.26.0; extra == "test"
|
|
20
|
+
Requires-Dist: pytest-cov==6.1.1; extra == "test"
|
|
21
|
+
Requires-Dist: pytest-error-for-skips==2.0.2; extra == "test"
|
|
22
|
+
Requires-Dist: pytest-timeout==2.3.1; extra == "test"
|
|
23
|
+
Requires-Dist: pytest==8.3.5; extra == "test"
|
|
24
|
+
Requires-Dist: ruff==0.11.7; extra == "test"
|
|
25
|
+
Requires-Dist: syrupy==4.9.1; extra == "test"
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pre-commit==4.2.0; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
# PyHolfuy
|
|
33
|
+
A Python library for talking to [Holfuy Weather Stations](https://holfuy.com/).
|
|
34
|
+
|
|
35
|
+
You need an API key to access the service. To obtain one, please visit the [Holfuy API](https://api.holfuy.com/live/) pages.
|
|
36
|
+
|
|
37
|
+
The Library only access live data.
|
|
38
|
+
|
|
39
|
+
## Example Code
|
|
40
|
+
Here is an example of how to use the library.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import aiohttp
|
|
44
|
+
import asyncio
|
|
45
|
+
from holfuy import HolfuyService
|
|
46
|
+
|
|
47
|
+
async def main():
|
|
48
|
+
async with aiohttp.ClientSession() as session:
|
|
49
|
+
s = HolfuyService("", session)
|
|
50
|
+
data = await s.fetch_data(["101"])
|
|
51
|
+
print(data)
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
asyncio.run(main())
|
|
55
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
holfuy/__init__.py,sha256=iNeZqVv_pWg1IMv-ezqn1NxCc8kYcGCekQ7o76ybiG8,4526
|
|
2
|
+
holfuy/const.py,sha256=0PADMZ4XzkeLAHn_KNi5DNP7IVtICOYEbFiWjAMAFqk,491
|
|
3
|
+
pyholfuy-0.0.dist-info/licenses/LICENSE,sha256=xF0ocSqx7NzvDH3jXBxEnf6xqOYWGB0_Xa1VLTZzl_A,1074
|
|
4
|
+
pyholfuy-0.0.dist-info/METADATA,sha256=jbDAL4aqWFs4dWvhDjd7f-XReOFv17aKtAYfkKJMA_4,1794
|
|
5
|
+
pyholfuy-0.0.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
|
|
6
|
+
pyholfuy-0.0.dist-info/top_level.txt,sha256=uFdZ8sLqhc_bW4N7jQ5EMwHqcEqoab3D4sJG53CkR8U,7
|
|
7
|
+
pyholfuy-0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Håvard Dagenborg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
holfuy
|