PyMetno 0.11.0__tar.gz → 0.13.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyMetno
3
- Version: 0.11.0
3
+ Version: 0.13.0
4
4
  Summary: A library to communicate with the met.no api
5
5
  Home-page: https://github.com/Danielhiversen/pyMetno/
6
6
  Author: Daniel Hjelseth Høyer
@@ -13,3 +13,6 @@ Classifier: Programming Language :: Python
13
13
  Classifier: Topic :: Home Automation
14
14
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
15
15
  License-File: LICENSE
16
+ Requires-Dist: xmltodict
17
+ Requires-Dist: aiohttp>=3.0.6
18
+ Requires-Dist: async_timeout>=3.0.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyMetno
3
- Version: 0.11.0
3
+ Version: 0.13.0
4
4
  Summary: A library to communicate with the met.no api
5
5
  Home-page: https://github.com/Danielhiversen/pyMetno/
6
6
  Author: Daniel Hjelseth Høyer
@@ -13,3 +13,6 @@ Classifier: Programming Language :: Python
13
13
  Classifier: Topic :: Home Automation
14
14
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
15
15
  License-File: LICENSE
16
+ Requires-Dist: xmltodict
17
+ Requires-Dist: aiohttp>=3.0.6
18
+ Requires-Dist: async_timeout>=3.0.0
@@ -1,4 +1,3 @@
1
1
  xmltodict
2
2
  aiohttp>=3.0.6
3
3
  async_timeout>=3.0.0
4
- pytz
@@ -7,7 +7,11 @@ from typing import Any, List
7
7
 
8
8
  import aiohttp
9
9
  import async_timeout
10
- import pytz
10
+
11
+ try:
12
+ import ciso8601
13
+ except ImportError:
14
+ ciso8601 = None
11
15
 
12
16
  # https://api.met.no/weatherapi/weathericon/_/documentation/#___top
13
17
  CONDITIONS = {
@@ -59,8 +63,15 @@ CONDITIONS = {
59
63
  # include them.
60
64
  _VARIATIONS = {}
61
65
  for key, value in CONDITIONS.items():
62
- if not key.endswith(("_day", "_night")):
66
+ # ignore keys with values specific for night or day
67
+ # their values may be night or day specific
68
+ if key.endswith("_day") or key.endswith("_night"):
69
+ continue
70
+
71
+ # don't overwrite existing day or night conditions
72
+ if not key + "_day" in CONDITIONS:
63
73
  _VARIATIONS[key + "_day"] = value
74
+ if not key + "_night" in CONDITIONS:
64
75
  _VARIATIONS[key + "_night"] = value
65
76
  CONDITIONS.update(_VARIATIONS)
66
77
  del _VARIATIONS
@@ -117,7 +128,7 @@ class MetWeatherData:
117
128
  timeseries = self.data["properties"]["timeseries"]
118
129
  now = parse_datetime(timeseries[0]["time"])
119
130
  except (TypeError, KeyError, IndexError):
120
- now = datetime.datetime.now(pytz.utc)
131
+ now = datetime.datetime.now(datetime.timezone.utc)
121
132
  return self.get_weather(now, hourly=True)
122
133
 
123
134
  def get_forecast(self, time_zone, hourly=False, range_start=1, range_stop=None):
@@ -156,6 +167,7 @@ class MetWeatherData:
156
167
  daily_windspeed = []
157
168
  daily_windgust = []
158
169
  daily_dew_point = []
170
+ daily_uv_index = []
159
171
  entries = []
160
172
 
161
173
  for time_entry in self.data["properties"]["timeseries"]:
@@ -183,6 +195,9 @@ class MetWeatherData:
183
195
  dew_point = get_data("dew_point_temperature", [time_entry])
184
196
  if dew_point is not None:
185
197
  daily_dew_point.append(dew_point)
198
+ uv_index = get_data("ultraviolet_index_clear_sky", [time_entry])
199
+ if uv_index is not None:
200
+ daily_uv_index.append(uv_index)
186
201
 
187
202
  if time.astimezone() <= timestamp:
188
203
  entries.append(time_entry)
@@ -190,7 +205,7 @@ class MetWeatherData:
190
205
  if not entries:
191
206
  return {}
192
207
  res = dict()
193
- res["datetime"] = time.astimezone(tz=pytz.utc).isoformat()
208
+ res["datetime"] = time.astimezone(tz=datetime.timezone.utc).isoformat()
194
209
  res["condition"] = CONDITIONS.get(get_data("symbol_code", entries))
195
210
  res["pressure"] = get_data("air_pressure_at_sea_level", entries)
196
211
  res["humidity"] = get_data("relative_humidity", entries)
@@ -203,6 +218,7 @@ class MetWeatherData:
203
218
  res["wind_gust"] = get_data("wind_speed_of_gust", entries)
204
219
  res["cloudiness"] = get_data("cloud_area_fraction", entries)
205
220
  res["dew_point"] = get_data("dew_point_temperature", entries)
221
+ res["uv_index"] = get_data("ultraviolet_index_clear_sky", entries)
206
222
  else:
207
223
  res["temperature"] = (
208
224
  None if daily_temperatures == [] else max(daily_temperatures)
@@ -225,6 +241,9 @@ class MetWeatherData:
225
241
  res["dew_point"] = (
226
242
  None if daily_dew_point == [] else max(daily_dew_point)
227
243
  )
244
+ res["uv_index"] = (
245
+ None if daily_uv_index == [] else max(daily_uv_index)
246
+ )
228
247
 
229
248
  return res
230
249
 
@@ -272,6 +291,7 @@ def get_data(param: str, data: List[dict]) -> Any:
272
291
  "air_pressure_at_sea_level",
273
292
  "relative_humidity",
274
293
  "dew_point_temperature",
294
+ "ultraviolet_index_clear_sky",
275
295
  ):
276
296
  new_state = instant_details[param]
277
297
  elif param in ("wind_speed", "wind_speed_of_gust"):
@@ -324,7 +344,7 @@ class AirQualityData:
324
344
  _LOGGER.error("%s returned %s", self._api_url, err)
325
345
  return False
326
346
  try:
327
- forecast_time = datetime.datetime.now(pytz.utc) + datetime.timedelta(
347
+ forecast_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(
328
348
  hours=self._forecast
329
349
  )
330
350
 
@@ -393,8 +413,16 @@ class AirQualityData:
393
413
  return True
394
414
 
395
415
 
396
- def parse_datetime(dt_str):
416
+
417
+
418
+
419
+ def parse_datetime(dt_str: str) -> datetime.datetime:
397
420
  """Parse datetime."""
421
+ if ciso8601:
422
+ try:
423
+ return ciso8601.parse_datetime(dt_str)
424
+ except ValueError:
425
+ pass
398
426
  date_format = "%Y-%m-%dT%H:%M:%S %z"
399
427
  dt_str = dt_str.replace("Z", " +0000")
400
428
  return datetime.datetime.strptime(dt_str, date_format)
@@ -3,8 +3,8 @@ from setuptools import setup
3
3
  setup(
4
4
  name = 'PyMetno',
5
5
  packages = ['metno'],
6
- install_requires=['xmltodict', "aiohttp>=3.0.6", "async_timeout>=3.0.0", 'pytz'],
7
- version = '0.11.0',
6
+ install_requires=['xmltodict', "aiohttp>=3.0.6", "async_timeout>=3.0.0"],
7
+ version = '0.13.0',
8
8
  description = 'A library to communicate with the met.no api',
9
9
  author='Daniel Hjelseth Høyer',
10
10
  url='https://github.com/Danielhiversen/pyMetno/',
File without changes
File without changes
File without changes
File without changes