pyastroweatherio 0.62.0.dev7__tar.gz → 0.62.0.dev9__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.
Files changed (17) hide show
  1. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/PKG-INFO +1 -1
  2. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/client.py +101 -95
  3. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/dataclasses.py +245 -46
  4. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/helper_functions.py +71 -159
  5. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/PKG-INFO +1 -1
  6. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/SOURCES.txt +0 -1
  7. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/setup.py +1 -1
  8. pyastroweatherio-0.62.0.dev7/pyastroweatherio/models.py +0 -209
  9. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/LICENSE +0 -0
  10. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/README.md +0 -0
  11. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/__init__.py +0 -0
  12. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/const.py +0 -0
  13. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/errors.py +0 -0
  14. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/dependency_links.txt +0 -0
  15. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/requires.txt +0 -0
  16. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/top_level.txt +0 -0
  17. {pyastroweatherio-0.62.0.dev7 → pyastroweatherio-0.62.0.dev9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyastroweatherio
3
- Version: 0.62.0.dev7
3
+ Version: 0.62.0.dev9
4
4
  Summary: Python Wrapper for 7Timer and Met.no REST API
5
5
  Home-page: https://github.com/mawinkler/pyastroweatherio
6
6
  Author: Markus Winkler
@@ -5,14 +5,14 @@ import json
5
5
  import logging
6
6
  import math
7
7
  import os.path
8
- from datetime import UTC, datetime, timedelta
8
+ from datetime import UTC, datetime, timedelta, timezone
9
9
  from json.decoder import JSONDecodeError
10
+ from pprint import pprint as pp
10
11
  from typing import Optional
11
12
 
12
13
  import aiofiles
13
14
  from aiohttp import ClientSession, ClientTimeout
14
15
  from aiohttp.client_exceptions import ClientError
15
- from pydantic import ValidationError
16
16
 
17
17
  from pyastroweatherio.const import (
18
18
  BASE_URL_MET,
@@ -41,15 +41,25 @@ from pyastroweatherio.const import (
41
41
  )
42
42
  from pyastroweatherio.dataclasses import (
43
43
  AtmosphereData,
44
- TimeData,
45
- GeoLocationData,
44
+ AtmosphereDataModel,
46
45
  ConditionData,
46
+ ConditionDataModel,
47
47
  ForecastData,
48
+ ForecastDataModel,
49
+ GeoLocationData,
50
+ GeoLocationDataModel,
48
51
  LocationData,
52
+ LocationDataModel,
49
53
  NightlyConditionsData,
50
- UpTonightDSOData,
54
+ NightlyConditionsDataModel,
55
+ TimeData,
56
+ TimeDataModel,
51
57
  UpTonightBodiesData,
58
+ UpTonightBodiesDataModel,
52
59
  UpTonightCometsData,
60
+ UpTonightCometsDataModel,
61
+ UpTonightDSOData,
62
+ UpTonightDSODataModel,
53
63
  )
54
64
  from pyastroweatherio.errors import RequestError
55
65
  from pyastroweatherio.helper_functions import (
@@ -57,20 +67,6 @@ from pyastroweatherio.helper_functions import (
57
67
  AtmosphericRoutines,
58
68
  ConversionFunctions,
59
69
  )
60
- from pyastroweatherio.models import (
61
- AtmosphereDataModel,
62
- ConditionDataModel,
63
- ForecastDataModel,
64
- GeoLocationDataModel,
65
- LocationDataModel,
66
- TimeDataModel,
67
- NightlyConditionsDataModel,
68
- UpTonightDSODataModel,
69
- UpTonightBodiesDataModel,
70
- UpTonightCometsDataModel,
71
- )
72
-
73
- from pprint import pprint as pp
74
70
 
75
71
  _LOGGER = logging.getLogger(__name__)
76
72
  _NOT_AVAILABLE = -9999
@@ -173,9 +169,8 @@ class AstroWeather:
173
169
  elevation,
174
170
  timezone_info,
175
171
  ) -> GeoLocationData | None:
176
-
177
- geolocation = GeoLocationData(
178
- data={
172
+ geolocation = GeoLocationDataModel(
173
+ {
179
174
  "latitude": latitude,
180
175
  "longitude": longitude,
181
176
  "elevation": elevation,
@@ -184,9 +179,8 @@ class AstroWeather:
184
179
  )
185
180
 
186
181
  try:
187
- GeoLocationDataModel.validate(geolocation)
188
- return geolocation
189
- except ValidationError as ve:
182
+ return GeoLocationData(data=geolocation)
183
+ except TypeError as ve:
190
184
  _LOGGER.error(f"Failed to parse geo location data: {geolocation}")
191
185
  _LOGGER.error(ve)
192
186
  return None
@@ -233,8 +227,8 @@ class AstroWeather:
233
227
  else:
234
228
  lifted_index = LIFTED_INDEX_7TIMER_MAPPING[details_seventimer["lifted_index"]]
235
229
 
236
- atmosphere = AtmosphereData(
237
- data={
230
+ atmosphere = AtmosphereDataModel(
231
+ {
238
232
  "seeing": seeing,
239
233
  "transparency": transparency,
240
234
  "lifted_index": lifted_index,
@@ -242,9 +236,8 @@ class AstroWeather:
242
236
  )
243
237
 
244
238
  try:
245
- AtmosphereDataModel.validate(atmosphere)
246
- return atmosphere
247
- except ValidationError as ve:
239
+ return AtmosphereData(data=atmosphere)
240
+ except TypeError as ve:
248
241
  _LOGGER.error(f"Failed to parse atmosphere data: {atmosphere}")
249
242
  _LOGGER.error(ve)
250
243
  return None
@@ -258,9 +251,8 @@ class AstroWeather:
258
251
  transparency,
259
252
  lifted_index,
260
253
  ) -> ConditionData | None:
261
-
262
- condition = ConditionData(
263
- data={
254
+ condition = ConditionDataModel(
255
+ {
264
256
  "cloudcover": details_metno.get("cloud_area_fraction"),
265
257
  "cloud_area_fraction": details_metno.get("cloud_area_fraction"),
266
258
  "cloud_area_fraction_high": details_metno.get("cloud_area_fraction_high"),
@@ -292,9 +284,8 @@ class AstroWeather:
292
284
  )
293
285
 
294
286
  try:
295
- ConditionDataModel.validate(condition)
296
- return condition
297
- except ValidationError as ve:
287
+ return ConditionData(data=condition)
288
+ except TypeError as ve:
298
289
  _LOGGER.error(f"Failed to parse condition data: {condition}")
299
290
  _LOGGER.error(ve)
300
291
  return None
@@ -311,20 +302,6 @@ class AstroWeather:
311
302
  ) -> int:
312
303
  """Return condition based on cloud cover, seeing, transparency, and wind speed."""
313
304
 
314
- # if not all(
315
- # v is not None
316
- # for v in [
317
- # cloudcover_high,
318
- # cloudcover_medium,
319
- # cloudcover_low,
320
- # seeing,
321
- # transparency,
322
- # wind_speed,
323
- # precipitation_amount,
324
- # ]
325
- # ):
326
- # return None
327
-
328
305
  # Seeing is something in between 0 and 2.5 arcsecs
329
306
  seeing = seeing * 100 / SEEING_MAX # arcsecs up to 2.5
330
307
  # transparency = int(transparency * 40) # mag degration up to 2.5
@@ -435,26 +412,26 @@ class AstroWeather:
435
412
 
436
413
  atmosphere_data = await self._get_atmosphere(details_seventimer, details_metno)
437
414
 
438
- time_data = TimeData(
439
- data={
415
+ time_data = TimeDataModel(
416
+ {
440
417
  # seventimer_init is "init" of 7timer astro data
441
418
  "seventimer_init": seventimer_init,
442
419
  # seventimer_timepoint is "timepoint" of 7timer astro data and defines the data for init + timepoint
443
420
  "seventimer_timepoint": details_seventimer["timepoint"],
444
421
  # Forecast_time is the actual datetime for the forecast data onwards in UTC
445
422
  # Corresponds to "time" in met data
446
- "forecast_time": forecast_time,
423
+ "forecast_time": forecast_time.replace(microsecond=0, tzinfo=timezone.utc),
447
424
  }
448
425
  )
449
426
 
450
427
  try:
451
- TimeDataModel.validate(time_data)
452
- except ValidationError as ve:
428
+ time_data = TimeData(data=time_data)
429
+ except TypeError as ve:
453
430
  _LOGGER.error(f"Failed to parse location data model data: {time_data}")
454
431
  _LOGGER.error(ve)
455
432
 
456
- item = LocationData(
457
- data={
433
+ item = LocationDataModel(
434
+ {
458
435
  # Time data
459
436
  "time_data": time_data,
460
437
  # Time shift to UTC
@@ -486,14 +463,20 @@ class AstroWeather:
486
463
  )
487
464
 
488
465
  try:
489
- LocationDataModel.validate(item)
490
- items.append(item)
491
- except ValidationError as ve:
466
+ items.append(LocationData(data=item))
467
+ except TypeError as ve:
492
468
  _LOGGER.error(f"Failed to parse location data model data: {item}")
493
469
  _LOGGER.error(ve)
494
470
 
495
471
  return items
496
472
 
473
+ def _test_data(self, data, keys) -> bool:
474
+ """Test that specific values in a dictionary are not None"""
475
+
476
+ if not all(data[key] is not None for key in keys):
477
+ return False
478
+ return True
479
+
497
480
  async def _get_forecast_data(self, forecast_type, hours_to_show) -> None:
498
481
  """Return Forecast data for the Station."""
499
482
 
@@ -507,9 +490,11 @@ class AstroWeather:
507
490
  # Create items
508
491
  cnt = 0
509
492
 
510
- forecast_time = now.replace(minute=0, second=0, microsecond=0)
493
+ forecast_time = now.replace(minute=0, second=0, microsecond=0).replace(microsecond=0, tzinfo=timezone.utc)
511
494
  if self._test_datetime is not None:
512
- forecast_time = self._test_datetime.replace(minute=0, second=0, microsecond=0)
495
+ forecast_time = self._test_datetime.replace(minute=0, second=0, microsecond=0).replace(
496
+ microsecond=0, tzinfo=timezone.utc
497
+ )
513
498
  _LOGGER.debug("Forecast time: %s", str(forecast_time))
514
499
 
515
500
  # 7Timer: Search for start index
@@ -528,19 +513,42 @@ class AstroWeather:
528
513
 
529
514
  last_forecast_time = forecast_time
530
515
  for metno_index, datapoint in enumerate(self._weather_data_metno):
531
- if forecast_time > datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ"):
516
+ datapoint_time = datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ").replace(
517
+ microsecond=0, tzinfo=timezone.utc
518
+ )
519
+ if forecast_time > datapoint_time:
532
520
  continue
533
521
 
534
- if datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ") - last_forecast_time > timedelta(hours=1):
522
+ if datapoint_time - last_forecast_time > timedelta(hours=1):
535
523
  break
536
524
 
537
- last_forecast_time = datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ")
525
+ last_forecast_time = datapoint_time
538
526
  details_metno = datapoint.get("data", {}).get("instant", {}).get("details")
539
527
 
540
- if details_metno.get("cloud_area_fraction") is None:
528
+ if not self._test_data(
529
+ details_metno,
530
+ [
531
+ "air_pressure_at_sea_level",
532
+ "air_temperature",
533
+ "cloud_area_fraction",
534
+ "cloud_area_fraction_high",
535
+ "cloud_area_fraction_low",
536
+ "cloud_area_fraction_medium",
537
+ "dew_point_temperature",
538
+ "fog_area_fraction",
539
+ "relative_humidity",
540
+ "ultraviolet_index_clear_sky",
541
+ "wind_from_direction",
542
+ "wind_speed",
543
+ ],
544
+ ):
541
545
  _LOGGER.error("Missing Met.no data")
542
546
  break
543
547
 
548
+ # if details_metno.get("cloud_area_fraction") is None:
549
+ # _LOGGER.error("Missing Met.no data")
550
+ # break
551
+
544
552
  details_seventimer = self._get_data_seventimer_timer(
545
553
  seventimer_init,
546
554
  datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ"),
@@ -566,26 +574,28 @@ class AstroWeather:
566
574
 
567
575
  atmosphere_data = await self._get_atmosphere(details_seventimer, details_metno)
568
576
 
569
- time_data = TimeData(
570
- data={
577
+ td = TimeDataModel(
578
+ {
571
579
  # seventimer_init is "init" of 7timer astro data
572
580
  "seventimer_init": init_ts,
573
581
  # seventimer_timepoint is "timepoint" of 7timer astro data and defines the data for init + timepoint
574
582
  "seventimer_timepoint": details_seventimer["timepoint"],
575
583
  # Forecast_time is the actual datetime for the forecast data onwards in UTC
576
584
  # Corresponds to "time" in met data
577
- "forecast_time": datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ"), # timestamp
585
+ "forecast_time": datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ").replace(
586
+ microsecond=0, tzinfo=timezone.utc
587
+ ), # timestamp
578
588
  }
579
589
  )
580
590
 
581
591
  try:
582
- TimeDataModel.validate(time_data)
583
- except ValidationError as ve:
592
+ time_data = TimeData(data=td)
593
+ except TypeError as ve:
584
594
  _LOGGER.error(f"Failed to parse location data model data: {time_data}")
585
595
  _LOGGER.error(ve)
586
596
 
587
- item = ForecastData(
588
- data={
597
+ item = ForecastDataModel(
598
+ {
589
599
  # Time data
590
600
  "time_data": time_data,
591
601
  "hour": datetime.strptime(
@@ -603,9 +613,8 @@ class AstroWeather:
603
613
  )
604
614
 
605
615
  try:
606
- ForecastDataModel.validate(item)
607
- items.append(item)
608
- except ValidationError as ve:
616
+ items.append(ForecastData(data=item))
617
+ except TypeError as ve:
609
618
  _LOGGER.error(f"Failed to parse forecast data: {item}")
610
619
  _LOGGER.error(ve)
611
620
 
@@ -704,8 +713,8 @@ class AstroWeather:
704
713
  )
705
714
 
706
715
  if details_forecast.forecast_time.hour == sun_next_rising.hour or index >= (forecast_data_len - 1):
707
- item = NightlyConditionsData(
708
- data={
716
+ item = NightlyConditionsDataModel(
717
+ {
709
718
  "seventimer_init": init_ts,
710
719
  "dayname": forecast_dayname,
711
720
  "hour": start_forecast_hour,
@@ -716,8 +725,8 @@ class AstroWeather:
716
725
  )
717
726
 
718
727
  try:
719
- NightlyConditionsDataModel.validate(item)
720
- except ValidationError as ve:
728
+ item = NightlyConditionsData(data=item)
729
+ except TypeError as ve:
721
730
  _LOGGER.error(f"Failed to parse nightly conditions model data: {item}")
722
731
  _LOGGER.error(ve)
723
732
 
@@ -783,8 +792,8 @@ class AstroWeather:
783
792
  else:
784
793
  dso_meridian_antitransit_utc = ""
785
794
 
786
- item = UpTonightDSOData(
787
- data={
795
+ item = UpTonightDSODataModel(
796
+ {
788
797
  "id": dso_id.get(str(row), ""),
789
798
  "target_name": dso_target_name.get(str(row), ""),
790
799
  "type": dso_type.get(str(row), ""),
@@ -797,9 +806,8 @@ class AstroWeather:
797
806
  }
798
807
  )
799
808
  try:
800
- UpTonightDSODataModel.validate(item)
801
- items.append(item)
802
- except ValidationError as ve:
809
+ items.append(UpTonightDSOData(data=item))
810
+ except TypeError as ve:
803
811
  _LOGGER.error(f"Failed to parse deep sky object data: {item}")
804
812
  _LOGGER.error(ve)
805
813
 
@@ -839,8 +847,8 @@ class AstroWeather:
839
847
  else:
840
848
  body_meridian_transit_utc = ""
841
849
 
842
- item = UpTonightBodiesData(
843
- data={
850
+ item = UpTonightBodiesDataModel(
851
+ {
844
852
  "target_name": body_target_name.get(str(row), ""),
845
853
  "max_altitude": body_max_altitude.get(str(row), ""),
846
854
  "azimuth": body_azimuth.get(str(row), ""),
@@ -851,9 +859,8 @@ class AstroWeather:
851
859
  }
852
860
  )
853
861
  try:
854
- UpTonightBodiesDataModel.validate(item)
855
- items.append(item)
856
- except ValidationError as ve:
862
+ items.append(UpTonightBodiesData(data=item))
863
+ except TypeError as ve:
857
864
  _LOGGER.error(f"Failed to parse bodies data: {item}")
858
865
  _LOGGER.error(ve)
859
866
 
@@ -891,8 +898,8 @@ class AstroWeather:
891
898
  - timedelta(seconds=await self._astro_routines.time_shift())
892
899
  ).replace(tzinfo=UTC)
893
900
 
894
- item = UpTonightCometsData(
895
- data={
901
+ item = UpTonightCometsDataModel(
902
+ {
896
903
  "designation": comet_target_name.get(str(row), ""),
897
904
  "distance_au_earth": distance_au_earth.get(str(row), ""),
898
905
  "distance_au_sun": distance_au_sun.get(str(row), ""),
@@ -905,9 +912,8 @@ class AstroWeather:
905
912
  }
906
913
  )
907
914
  try:
908
- UpTonightCometsDataModel.validate(item)
909
- items.append(item)
910
- except ValidationError as ve:
915
+ items.append(UpTonightCometsData(data=item))
916
+ except TypeError as ve:
911
917
  _LOGGER.error(f"Failed to parse comets data: {item}")
912
918
  _LOGGER.error(ve)
913
919