pyastroweatherio 0.62.0.dev8__tar.gz → 0.62.0.dev10__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.dev10}/PKG-INFO +1 -1
  2. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio/client.py +61 -30
  3. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio/const.py +1 -0
  4. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio/dataclasses.py +47 -39
  5. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio.egg-info/PKG-INFO +1 -1
  6. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/setup.py +1 -1
  7. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/LICENSE +0 -0
  8. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/README.md +0 -0
  9. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio/__init__.py +0 -0
  10. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio/errors.py +0 -0
  11. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio/helper_functions.py +0 -0
  12. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio.egg-info/SOURCES.txt +0 -0
  13. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio.egg-info/dependency_links.txt +0 -0
  14. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio.egg-info/requires.txt +0 -0
  15. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/pyastroweatherio.egg-info/top_level.txt +0 -0
  16. {pyastroweatherio-0.62.0.dev8 → pyastroweatherio-0.62.0.dev10}/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.dev10
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
@@ -23,6 +23,7 @@ from pyastroweatherio.const import (
23
23
  DEFAULT_CONDITION_CLOUDCOVER_LOW_WEAKENING,
24
24
  DEFAULT_CONDITION_CLOUDCOVER_MEDIUM_WEAKENING,
25
25
  DEFAULT_CONDITION_CLOUDCOVER_WEIGHT,
26
+ DEFAULT_CONDITION_FOG_WEIGHT,
26
27
  DEFAULT_CONDITION_SEEING_WEIGHT,
27
28
  DEFAULT_CONDITION_TRANSPARENCY_WEIGHT,
28
29
  DEFAULT_ELEVATION,
@@ -86,6 +87,7 @@ class AstroWeather:
86
87
  cloudcover_high_weakening=DEFAULT_CONDITION_CLOUDCOVER_HIGH_WEAKENING,
87
88
  cloudcover_medium_weakening=DEFAULT_CONDITION_CLOUDCOVER_MEDIUM_WEAKENING,
88
89
  cloudcover_low_weakening=DEFAULT_CONDITION_CLOUDCOVER_LOW_WEAKENING,
90
+ fog_weight=DEFAULT_CONDITION_FOG_WEIGHT,
89
91
  seeing_weight=DEFAULT_CONDITION_SEEING_WEIGHT,
90
92
  transparency_weight=DEFAULT_CONDITION_TRANSPARENCY_WEIGHT,
91
93
  calm_weight=DEFAULT_CONDITION_CALM_WEIGHT,
@@ -115,6 +117,7 @@ class AstroWeather:
115
117
  self._cloudcover_high_weakening = cloudcover_high_weakening
116
118
  self._cloudcover_medium_weakening = cloudcover_medium_weakening
117
119
  self._cloudcover_low_weakening = cloudcover_low_weakening
120
+ self._fog_weight = fog_weight
118
121
  self._seeing_weight = seeing_weight
119
122
  self._transparency_weight = transparency_weight
120
123
  self._calm_weight = calm_weight
@@ -169,7 +172,6 @@ class AstroWeather:
169
172
  elevation,
170
173
  timezone_info,
171
174
  ) -> GeoLocationData | None:
172
-
173
175
  geolocation = GeoLocationDataModel(
174
176
  {
175
177
  "latitude": latitude,
@@ -252,7 +254,6 @@ class AstroWeather:
252
254
  transparency,
253
255
  lifted_index,
254
256
  ) -> ConditionData | None:
255
-
256
257
  condition = ConditionDataModel(
257
258
  {
258
259
  "cloudcover": details_metno.get("cloud_area_fraction"),
@@ -268,6 +269,7 @@ class AstroWeather:
268
269
  details_metno.get("cloud_area_fraction_high"),
269
270
  details_metno.get("cloud_area_fraction_medium"),
270
271
  details_metno.get("cloud_area_fraction_low"),
272
+ details_metno.get("fog_area_fraction"),
271
273
  seeing,
272
274
  transparency,
273
275
  details_metno.get("wind_speed"),
@@ -297,6 +299,7 @@ class AstroWeather:
297
299
  cloudcover_high,
298
300
  cloudcover_medium,
299
301
  cloudcover_low,
302
+ fog,
300
303
  seeing,
301
304
  transparency,
302
305
  wind_speed,
@@ -304,20 +307,6 @@ class AstroWeather:
304
307
  ) -> int:
305
308
  """Return condition based on cloud cover, seeing, transparency, and wind speed."""
306
309
 
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
310
  # Seeing is something in between 0 and 2.5 arcsecs
322
311
  seeing = seeing * 100 / SEEING_MAX # arcsecs up to 2.5
323
312
  # transparency = int(transparency * 40) # mag degration up to 2.5
@@ -336,14 +325,25 @@ class AstroWeather:
336
325
  100
337
326
  - (
338
327
  self._cloudcover_weight * max(cloudcover)
328
+ + self._fog_weight * fog
339
329
  + self._seeing_weight * seeing
340
330
  + self._transparency_weight * transparency
341
331
  + self._calm_weight * wind_speed_value
342
332
  )
343
- / (self._cloudcover_weight + self._seeing_weight + self._transparency_weight + self._calm_weight)
333
+ / (
334
+ self._cloudcover_weight
335
+ + self._fog_weight
336
+ + self._seeing_weight
337
+ + self._transparency_weight
338
+ + self._calm_weight
339
+ )
344
340
  - precipitation_amount * 100
345
341
  )
346
342
 
343
+ _LOGGER.debug(
344
+ f"Cloudcover: {max(cloudcover)}, Fog: {fog}, Seeing: {seeing}, Transparency: {transparency}, Wind speed: {wind_speed_value}"
345
+ )
346
+
347
347
  # Ensure condition is within the valid range [0, 1]
348
348
  condition = max(0, min(100, condition))
349
349
 
@@ -436,7 +436,7 @@ class AstroWeather:
436
436
  "seventimer_timepoint": details_seventimer["timepoint"],
437
437
  # Forecast_time is the actual datetime for the forecast data onwards in UTC
438
438
  # Corresponds to "time" in met data
439
- "forecast_time": forecast_time,
439
+ "forecast_time": forecast_time.replace(microsecond=0, tzinfo=timezone.utc),
440
440
  }
441
441
  )
442
442
 
@@ -486,6 +486,13 @@ class AstroWeather:
486
486
 
487
487
  return items
488
488
 
489
+ def _test_data(self, data, keys) -> bool:
490
+ """Test that specific values in a dictionary are not None"""
491
+
492
+ if not all(data[key] is not None for key in keys):
493
+ return False
494
+ return True
495
+
489
496
  async def _get_forecast_data(self, forecast_type, hours_to_show) -> None:
490
497
  """Return Forecast data for the Station."""
491
498
 
@@ -499,9 +506,11 @@ class AstroWeather:
499
506
  # Create items
500
507
  cnt = 0
501
508
 
502
- forecast_time = now.replace(minute=0, second=0, microsecond=0)
509
+ forecast_time = now.replace(minute=0, second=0, microsecond=0).replace(microsecond=0, tzinfo=timezone.utc)
503
510
  if self._test_datetime is not None:
504
- forecast_time = self._test_datetime.replace(minute=0, second=0, microsecond=0)
511
+ forecast_time = self._test_datetime.replace(minute=0, second=0, microsecond=0).replace(
512
+ microsecond=0, tzinfo=timezone.utc
513
+ )
505
514
  _LOGGER.debug("Forecast time: %s", str(forecast_time))
506
515
 
507
516
  # 7Timer: Search for start index
@@ -520,19 +529,42 @@ class AstroWeather:
520
529
 
521
530
  last_forecast_time = forecast_time
522
531
  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"):
532
+ datapoint_time = datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ").replace(
533
+ microsecond=0, tzinfo=timezone.utc
534
+ )
535
+ if forecast_time > datapoint_time:
524
536
  continue
525
537
 
526
- if datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ") - last_forecast_time > timedelta(hours=1):
538
+ if datapoint_time - last_forecast_time > timedelta(hours=1):
527
539
  break
528
540
 
529
- last_forecast_time = datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ")
541
+ last_forecast_time = datapoint_time
530
542
  details_metno = datapoint.get("data", {}).get("instant", {}).get("details")
531
543
 
532
- if details_metno.get("cloud_area_fraction") is None:
544
+ if not self._test_data(
545
+ details_metno,
546
+ [
547
+ "air_pressure_at_sea_level",
548
+ "air_temperature",
549
+ "cloud_area_fraction",
550
+ "cloud_area_fraction_high",
551
+ "cloud_area_fraction_low",
552
+ "cloud_area_fraction_medium",
553
+ "dew_point_temperature",
554
+ "fog_area_fraction",
555
+ "relative_humidity",
556
+ "ultraviolet_index_clear_sky",
557
+ "wind_from_direction",
558
+ "wind_speed",
559
+ ],
560
+ ):
533
561
  _LOGGER.error("Missing Met.no data")
534
562
  break
535
563
 
564
+ # if details_metno.get("cloud_area_fraction") is None:
565
+ # _LOGGER.error("Missing Met.no data")
566
+ # break
567
+
536
568
  details_seventimer = self._get_data_seventimer_timer(
537
569
  seventimer_init,
538
570
  datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ"),
@@ -566,7 +598,9 @@ class AstroWeather:
566
598
  "seventimer_timepoint": details_seventimer["timepoint"],
567
599
  # Forecast_time is the actual datetime for the forecast data onwards in UTC
568
600
  # Corresponds to "time" in met data
569
- "forecast_time": datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ"), # timestamp
601
+ "forecast_time": datetime.strptime(datapoint.get("time"), "%Y-%m-%dT%H:%M:%SZ").replace(
602
+ microsecond=0, tzinfo=timezone.utc
603
+ ), # timestamp
570
604
  }
571
605
  )
572
606
 
@@ -595,7 +629,6 @@ class AstroWeather:
595
629
  )
596
630
 
597
631
  try:
598
-
599
632
  items.append(ForecastData(data=item))
600
633
  except TypeError as ve:
601
634
  _LOGGER.error(f"Failed to parse forecast data: {item}")
@@ -688,6 +721,7 @@ class AstroWeather:
688
721
  details_forecast.cloud_area_fraction_high_percentage,
689
722
  details_forecast.cloud_area_fraction_medium_percentage,
690
723
  details_forecast.cloud_area_fraction_low_percentage,
724
+ details_forecast.fog_area_fraction_percentage,
691
725
  details_forecast.seeing,
692
726
  details_forecast.transparency,
693
727
  details_forecast.wind10m_speed,
@@ -789,7 +823,6 @@ class AstroWeather:
789
823
  }
790
824
  )
791
825
  try:
792
-
793
826
  items.append(UpTonightDSOData(data=item))
794
827
  except TypeError as ve:
795
828
  _LOGGER.error(f"Failed to parse deep sky object data: {item}")
@@ -843,7 +876,6 @@ class AstroWeather:
843
876
  }
844
877
  )
845
878
  try:
846
-
847
879
  items.append(UpTonightBodiesData(data=item))
848
880
  except TypeError as ve:
849
881
  _LOGGER.error(f"Failed to parse bodies data: {item}")
@@ -897,7 +929,6 @@ class AstroWeather:
897
929
  }
898
930
  )
899
931
  try:
900
-
901
932
  items.append(UpTonightCometsData(data=item))
902
933
  except TypeError as ve:
903
934
  _LOGGER.error(f"Failed to parse comets data: {item}")
@@ -171,6 +171,7 @@ DEFAULT_CONDITION_CLOUDCOVER_WEIGHT = 3
171
171
  DEFAULT_CONDITION_CLOUDCOVER_HIGH_WEAKENING = 1
172
172
  DEFAULT_CONDITION_CLOUDCOVER_MEDIUM_WEAKENING = 1
173
173
  DEFAULT_CONDITION_CLOUDCOVER_LOW_WEAKENING = 1
174
+ DEFAULT_CONDITION_FOG_WEIGHT = 3
174
175
  DEFAULT_CONDITION_SEEING_WEIGHT = 2
175
176
  DEFAULT_CONDITION_TRANSPARENCY_WEIGHT = 1
176
177
  DEFAULT_CONDITION_CALM_WEIGHT = 2
@@ -43,16 +43,6 @@ class TimeData:
43
43
  self.seventimer_timepoint = data["seventimer_timepoint"]
44
44
  self.forecast_time = data["forecast_time"]
45
45
 
46
- # @property
47
- # def seventimer_timepoint(self) -> datetime:
48
- # """Return Forecast Anchor."""
49
-
50
- # return self.seventimer_timepoint.replace(microsecond=0, tzinfo=timezone.utc)
51
-
52
- # @seventimer_timepoint.setter
53
- # def seventimer_timepoint(self, timepoint):
54
- # self.seventimer_timepoint = timepoint
55
-
56
46
 
57
47
  class GeoLocationDataModel(TypedDict):
58
48
  """Model for the location"""
@@ -73,10 +63,6 @@ class GeoLocationData:
73
63
  self.elevation = data["elevation"]
74
64
  self.timezone_info = data["timezone_info"]
75
65
 
76
- # if not all(data[key] is not None for key in asdict(self)):
77
- # print("NONE value")
78
- # print("done")
79
-
80
66
 
81
67
  class AtmosphereDataModel(TypedDict):
82
68
  """Model for atmosperic conditions"""
@@ -296,6 +282,7 @@ class ConditionData:
296
282
 
297
283
  @seeing.setter
298
284
  def seeing(self, new_value: float):
285
+ """Never called"""
299
286
  self._seeing = new_value
300
287
 
301
288
  @property
@@ -312,6 +299,7 @@ class ConditionData:
312
299
 
313
300
  @transparency.setter
314
301
  def transparency(self, new_value: float):
302
+ """Never called"""
315
303
  self._transparency = new_value
316
304
 
317
305
  @property
@@ -328,6 +316,7 @@ class ConditionData:
328
316
 
329
317
  @lifted_index.setter
330
318
  def lifted_index(self, new_value: float):
319
+ """Never called"""
331
320
  self._lifted_index = new_value
332
321
 
333
322
  @property
@@ -360,6 +349,7 @@ class ConditionData:
360
349
 
361
350
  @dewpoint2m.setter
362
351
  def dewpoint2m(self, new_value: float):
352
+ """Never called"""
363
353
  self._dewpoint2m = new_value
364
354
 
365
355
  @property
@@ -370,6 +360,7 @@ class ConditionData:
370
360
 
371
361
  @weather.setter
372
362
  def weather(self, new_value: float):
363
+ """Never called"""
373
364
  self._weather = new_value
374
365
 
375
366
  @property
@@ -380,6 +371,7 @@ class ConditionData:
380
371
 
381
372
  @weather6.setter
382
373
  def weather6(self, new_value: float):
374
+ """Never called"""
383
375
  self._weather6 = new_value
384
376
 
385
377
 
@@ -506,9 +498,9 @@ class LocationData:
506
498
  self.night_duration_astronomical = data["night_duration_astronomical"]
507
499
  self.deepsky_forecast = data["deepsky_forecast"]
508
500
  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"]
501
+ self._uptonight = data["uptonight"]
502
+ self._uptonight_bodies = data["uptonight_bodies"]
503
+ self._uptonight_comets = data["uptonight_comets"]
512
504
 
513
505
  # #########################################################################
514
506
  # Time data
@@ -621,6 +613,10 @@ class LocationData:
621
613
  def cloud_area_fraction_low_percentage(self) -> int:
622
614
  return self.condition_data.cloud_area_fraction_low_percentage
623
615
 
616
+ @property
617
+ def fog_area_fraction_percentage(self) -> int:
618
+ return self.condition_data.fog_area_fraction_percentage
619
+
624
620
  @property
625
621
  def seeing(self) -> float:
626
622
  return self.condition_data.seeing
@@ -673,6 +669,14 @@ class LocationData:
673
669
  def weather6(self) -> str:
674
670
  return self.condition_data.weather6
675
671
 
672
+ @property
673
+ def precipitation_amount(self) -> float:
674
+ return self.condition_data.precipitation_amount
675
+
676
+ @property
677
+ def precipitation_amount6(self) -> float:
678
+ return self.condition_data.precipitation_amount6
679
+
676
680
  # #########################################################################
677
681
  # Sun
678
682
  # #########################################################################
@@ -787,6 +791,12 @@ class LocationData:
787
791
 
788
792
  return round(self.moon_data.relative_size * 100 - 100, 3)
789
793
 
794
+ @property
795
+ def moon_relative_distance(self) -> float:
796
+ """Return Moon Relative Distance in %."""
797
+
798
+ return round(self.moon_data.relative_distance * 100 - 100, 3)
799
+
790
800
  # #########################################################################
791
801
  # Darkness
792
802
  # #########################################################################
@@ -914,53 +924,47 @@ class LocationData:
914
924
  # #########################################################################
915
925
  # UpTonight
916
926
  # #########################################################################
917
- # @property
918
- # def uptonight(self) -> int:
919
- # """Return the number of best DSOs for tonight."""
927
+ @property
928
+ def uptonight(self) -> int:
929
+ """Return the number of best DSOs for tonight."""
920
930
 
921
- # if self.uptonight is not None:
922
- # return len(self.uptonight)
923
- # return None
931
+ return len(self._uptonight)
924
932
 
925
933
  @property
926
934
  def uptonight_list(self) -> list[UpTonightDSOData]:
927
935
  """Return the list of UpTonight targets."""
928
936
 
929
- return self.uptonight
937
+ return self._uptonight
930
938
 
931
939
  # #########################################################################
932
940
  # UpTonight Bodies
933
941
  # #########################################################################
934
- # @property
935
- # def uptonight_bodies(self) -> int:
936
- # """Return the number of best BODIEs for tonight."""
942
+ @property
943
+ def uptonight_bodies(self) -> int:
944
+ """Return the number of best BODIEs for tonight."""
937
945
 
938
- # if self.uptonight_bodies is not None:
939
- # return len(self.uptonight_bodies)
940
- # return None
946
+ return len(self._uptonight_bodies)
941
947
 
942
948
  @property
943
949
  def uptonight_bodies_list(self) -> list[UpTonightBodiesData]:
944
950
  """Return the list of UpTonight bodies."""
945
951
 
946
- return self.uptonight_bodies
952
+ return self._uptonight_bodies
947
953
 
948
954
  # #########################################################################
949
955
  # UpTonight Comets
950
956
  # #########################################################################
951
- # @property
952
- # def uptonight_comets(self) -> int:
953
- # """Return the number of best comets for tonight."""
957
+ @property
958
+ def uptonight_comets(self) -> int:
959
+ """Return the number of best comets for tonight."""
954
960
 
955
- # if self.uptonight_comets is not None:
956
- # return len(self.uptonight_comets)
957
- # return None
961
+ return len(self._uptonight_comets)
958
962
 
959
963
  @property
960
964
  def uptonight_comets_list(self) -> list[UpTonightCometsData]:
961
965
  """Return the list of UpTonight comets."""
962
966
 
963
- return self.uptonight_comets
967
+ return self._uptonight_comets
964
968
 
965
969
 
966
970
  class ForecastDataModel(TypedDict):
@@ -1034,6 +1038,10 @@ class ForecastData:
1034
1038
  def cloud_area_fraction_low_percentage(self) -> int:
1035
1039
  return self.condition_data.cloud_area_fraction_low_percentage
1036
1040
 
1041
+ @property
1042
+ def fog_area_fraction_percentage(self) -> int:
1043
+ return self.condition_data.fog_area_fraction_percentage
1044
+
1037
1045
  @property
1038
1046
  def seeing(self) -> float:
1039
1047
  return self.condition_data.seeing
@@ -1121,9 +1129,9 @@ class NightlyConditionsData:
1121
1129
  @property
1122
1130
  def weather(self) -> str:
1123
1131
  """Return Current Weather."""
1124
-
1125
1132
  return self._weather.replace("_", " ").capitalize()
1126
1133
 
1127
1134
  @weather.setter
1128
1135
  def weather(self, new_value: str):
1136
+ """Never called"""
1129
1137
  self._weather = new_value
@@ -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.dev10
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.dev10",
7
7
  license="MIT",
8
8
  description="Python Wrapper for 7Timer and Met.no REST API",
9
9
  long_description=" ".join(