pyastroweatherio 0.62.0.dev8__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 (16) hide show
  1. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/PKG-INFO +1 -1
  2. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/client.py +43 -29
  3. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/dataclasses.py +34 -28
  4. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/PKG-INFO +1 -1
  5. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/setup.py +1 -1
  6. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/LICENSE +0 -0
  7. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/README.md +0 -0
  8. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/__init__.py +0 -0
  9. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/const.py +0 -0
  10. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/errors.py +0 -0
  11. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio/helper_functions.py +0 -0
  12. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/SOURCES.txt +0 -0
  13. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/dependency_links.txt +0 -0
  14. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/requires.txt +0 -0
  15. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev9}/pyastroweatherio.egg-info/top_level.txt +0 -0
  16. {pyastroweatherio-0.62.0.dev8 → 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.dev8
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,7 +5,7 @@ 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
10
  from pprint import pprint as pp
11
11
  from typing import Optional
@@ -169,7 +169,6 @@ class AstroWeather:
169
169
  elevation,
170
170
  timezone_info,
171
171
  ) -> GeoLocationData | None:
172
-
173
172
  geolocation = GeoLocationDataModel(
174
173
  {
175
174
  "latitude": latitude,
@@ -252,7 +251,6 @@ class AstroWeather:
252
251
  transparency,
253
252
  lifted_index,
254
253
  ) -> ConditionData | None:
255
-
256
254
  condition = ConditionDataModel(
257
255
  {
258
256
  "cloudcover": details_metno.get("cloud_area_fraction"),
@@ -304,20 +302,6 @@ class AstroWeather:
304
302
  ) -> int:
305
303
  """Return condition based on cloud cover, seeing, transparency, and wind speed."""
306
304
 
307
- # if not all(
308
- # v is not None
309
- # for v in [
310
- # cloudcover_high,
311
- # cloudcover_medium,
312
- # cloudcover_low,
313
- # seeing,
314
- # transparency,
315
- # wind_speed,
316
- # precipitation_amount,
317
- # ]
318
- # ):
319
- # return None
320
-
321
305
  # Seeing is something in between 0 and 2.5 arcsecs
322
306
  seeing = seeing * 100 / SEEING_MAX # arcsecs up to 2.5
323
307
  # transparency = int(transparency * 40) # mag degration up to 2.5
@@ -436,7 +420,7 @@ class AstroWeather:
436
420
  "seventimer_timepoint": details_seventimer["timepoint"],
437
421
  # Forecast_time is the actual datetime for the forecast data onwards in UTC
438
422
  # Corresponds to "time" in met data
439
- "forecast_time": forecast_time,
423
+ "forecast_time": forecast_time.replace(microsecond=0, tzinfo=timezone.utc),
440
424
  }
441
425
  )
442
426
 
@@ -486,6 +470,13 @@ class AstroWeather:
486
470
 
487
471
  return items
488
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
+
489
480
  async def _get_forecast_data(self, forecast_type, hours_to_show) -> None:
490
481
  """Return Forecast data for the Station."""
491
482
 
@@ -499,9 +490,11 @@ class AstroWeather:
499
490
  # Create items
500
491
  cnt = 0
501
492
 
502
- 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)
503
494
  if self._test_datetime is not None:
504
- 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
+ )
505
498
  _LOGGER.debug("Forecast time: %s", str(forecast_time))
506
499
 
507
500
  # 7Timer: Search for start index
@@ -520,19 +513,42 @@ class AstroWeather:
520
513
 
521
514
  last_forecast_time = forecast_time
522
515
  for metno_index, datapoint in enumerate(self._weather_data_metno):
523
- 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:
524
520
  continue
525
521
 
526
- 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):
527
523
  break
528
524
 
529
- last_forecast_time = datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ")
525
+ last_forecast_time = datapoint_time
530
526
  details_metno = datapoint.get("data", {}).get("instant", {}).get("details")
531
527
 
532
- 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
+ ):
533
545
  _LOGGER.error("Missing Met.no data")
534
546
  break
535
547
 
548
+ # if details_metno.get("cloud_area_fraction") is None:
549
+ # _LOGGER.error("Missing Met.no data")
550
+ # break
551
+
536
552
  details_seventimer = self._get_data_seventimer_timer(
537
553
  seventimer_init,
538
554
  datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ"),
@@ -566,7 +582,9 @@ class AstroWeather:
566
582
  "seventimer_timepoint": details_seventimer["timepoint"],
567
583
  # Forecast_time is the actual datetime for the forecast data onwards in UTC
568
584
  # Corresponds to "time" in met data
569
- "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
570
588
  }
571
589
  )
572
590
 
@@ -595,7 +613,6 @@ class AstroWeather:
595
613
  )
596
614
 
597
615
  try:
598
-
599
616
  items.append(ForecastData(data=item))
600
617
  except TypeError as ve:
601
618
  _LOGGER.error(f"Failed to parse forecast data: {item}")
@@ -789,7 +806,6 @@ class AstroWeather:
789
806
  }
790
807
  )
791
808
  try:
792
-
793
809
  items.append(UpTonightDSOData(data=item))
794
810
  except TypeError as ve:
795
811
  _LOGGER.error(f"Failed to parse deep sky object data: {item}")
@@ -843,7 +859,6 @@ class AstroWeather:
843
859
  }
844
860
  )
845
861
  try:
846
-
847
862
  items.append(UpTonightBodiesData(data=item))
848
863
  except TypeError as ve:
849
864
  _LOGGER.error(f"Failed to parse bodies data: {item}")
@@ -897,7 +912,6 @@ class AstroWeather:
897
912
  }
898
913
  )
899
914
  try:
900
-
901
915
  items.append(UpTonightCometsData(data=item))
902
916
  except TypeError as ve:
903
917
  _LOGGER.error(f"Failed to parse comets data: {item}")
@@ -73,10 +73,6 @@ class GeoLocationData:
73
73
  self.elevation = data["elevation"]
74
74
  self.timezone_info = data["timezone_info"]
75
75
 
76
- # if not all(data[key] is not None for key in asdict(self)):
77
- # print("NONE value")
78
- # print("done")
79
-
80
76
 
81
77
  class AtmosphereDataModel(TypedDict):
82
78
  """Model for atmosperic conditions"""
@@ -506,9 +502,9 @@ class LocationData:
506
502
  self.night_duration_astronomical = data["night_duration_astronomical"]
507
503
  self.deepsky_forecast = data["deepsky_forecast"]
508
504
  self.condition_data = data["condition_data"]
509
- self.uptonight = data["uptonight"]
510
- self.uptonight_bodies = data["uptonight_bodies"]
511
- self.uptonight_comets = data["uptonight_comets"]
505
+ self._uptonight = data["uptonight"]
506
+ self._uptonight_bodies = data["uptonight_bodies"]
507
+ self._uptonight_comets = data["uptonight_comets"]
512
508
 
513
509
  # #########################################################################
514
510
  # Time data
@@ -621,6 +617,10 @@ class LocationData:
621
617
  def cloud_area_fraction_low_percentage(self) -> int:
622
618
  return self.condition_data.cloud_area_fraction_low_percentage
623
619
 
620
+ @property
621
+ def fog_area_fraction_percentage(self) -> int:
622
+ return self.condition_data.fog_area_fraction_percentage
623
+
624
624
  @property
625
625
  def seeing(self) -> float:
626
626
  return self.condition_data.seeing
@@ -673,6 +673,14 @@ class LocationData:
673
673
  def weather6(self) -> str:
674
674
  return self.condition_data.weather6
675
675
 
676
+ @property
677
+ def precipitation_amount(self) -> float:
678
+ return self.condition_data.precipitation_amount
679
+
680
+ @property
681
+ def precipitation_amount6(self) -> float:
682
+ return self.condition_data.precipitation_amount6
683
+
676
684
  # #########################################################################
677
685
  # Sun
678
686
  # #########################################################################
@@ -914,53 +922,47 @@ class LocationData:
914
922
  # #########################################################################
915
923
  # UpTonight
916
924
  # #########################################################################
917
- # @property
918
- # def uptonight(self) -> int:
919
- # """Return the number of best DSOs for tonight."""
925
+ @property
926
+ def uptonight(self) -> int:
927
+ """Return the number of best DSOs for tonight."""
920
928
 
921
- # if self.uptonight is not None:
922
- # return len(self.uptonight)
923
- # return None
929
+ return len(self._uptonight)
924
930
 
925
931
  @property
926
932
  def uptonight_list(self) -> list[UpTonightDSOData]:
927
933
  """Return the list of UpTonight targets."""
928
934
 
929
- return self.uptonight
935
+ return self._uptonight
930
936
 
931
937
  # #########################################################################
932
938
  # UpTonight Bodies
933
939
  # #########################################################################
934
- # @property
935
- # def uptonight_bodies(self) -> int:
936
- # """Return the number of best BODIEs for tonight."""
940
+ @property
941
+ def uptonight_bodies(self) -> int:
942
+ """Return the number of best BODIEs for tonight."""
937
943
 
938
- # if self.uptonight_bodies is not None:
939
- # return len(self.uptonight_bodies)
940
- # return None
944
+ return len(self._uptonight_bodies)
941
945
 
942
946
  @property
943
947
  def uptonight_bodies_list(self) -> list[UpTonightBodiesData]:
944
948
  """Return the list of UpTonight bodies."""
945
949
 
946
- return self.uptonight_bodies
950
+ return self._uptonight_bodies
947
951
 
948
952
  # #########################################################################
949
953
  # UpTonight Comets
950
954
  # #########################################################################
951
- # @property
952
- # def uptonight_comets(self) -> int:
953
- # """Return the number of best comets for tonight."""
955
+ @property
956
+ def uptonight_comets(self) -> int:
957
+ """Return the number of best comets for tonight."""
954
958
 
955
- # if self.uptonight_comets is not None:
956
- # return len(self.uptonight_comets)
957
- # return None
959
+ return len(self._uptonight_comets)
958
960
 
959
961
  @property
960
962
  def uptonight_comets_list(self) -> list[UpTonightCometsData]:
961
963
  """Return the list of UpTonight comets."""
962
964
 
963
- return self.uptonight_comets
965
+ return self._uptonight_comets
964
966
 
965
967
 
966
968
  class ForecastDataModel(TypedDict):
@@ -1034,6 +1036,10 @@ class ForecastData:
1034
1036
  def cloud_area_fraction_low_percentage(self) -> int:
1035
1037
  return self.condition_data.cloud_area_fraction_low_percentage
1036
1038
 
1039
+ @property
1040
+ def fog_area_fraction_percentage(self) -> int:
1041
+ return self.condition_data.fog_area_fraction_percentage
1042
+
1037
1043
  @property
1038
1044
  def seeing(self) -> float:
1039
1045
  return self.condition_data.seeing
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyastroweatherio
3
- Version: 0.62.0.dev8
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
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
  setup(
4
4
  name="pyastroweatherio",
5
5
  packages=["pyastroweatherio"],
6
- version="0.62.0.dev8",
6
+ version="0.62.0.dev9",
7
7
  license="MIT",
8
8
  description="Python Wrapper for 7Timer and Met.no REST API",
9
9
  long_description=" ".join(