juham-visualcrossing 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+
@@ -1,8 +1,9 @@
1
1
  from datetime import datetime, timedelta, timezone
2
2
  import json
3
+ from typing import Any, Dict, Optional, cast
4
+ from typing_extensions import override # for python 3.9 compatibility
3
5
 
4
- from typing import Any
5
- from juham.base import Base
6
+ from juham.base import Base, MqttMsg, JMqtt
6
7
  from juham.web import RCloud, RCloudThread
7
8
 
8
9
 
@@ -11,13 +12,13 @@ class VisualCrossingThread(RCloudThread):
11
12
  site."""
12
13
 
13
14
  # class attributes
14
- _forecast_topic = ""
15
- _base_url = ""
16
- _api_key = ""
17
- _location = ""
15
+ _forecast_topic: str = ""
16
+ _base_url: str = ""
17
+ _api_key: str = ""
18
+ _location: str = ""
18
19
  _interval: float = 12 * 3600
19
20
 
20
- def __init__(self, client=None):
21
+ def __init__(self, client: Optional[JMqtt] = None):
21
22
  """Construct with the given mqtt client. Acquires data from the visual
22
23
  crossing web service and publishes the forecast data to
23
24
  forecast_topic.
@@ -26,13 +27,14 @@ class VisualCrossingThread(RCloudThread):
26
27
  client (object, optional): MQTT client. Defaults to None.
27
28
  """
28
29
  super().__init__(client)
29
- self.mqtt_client = client
30
+ self.mqtt_client: Optional[JMqtt] = client
30
31
 
32
+ @override
31
33
  def update_interval(self) -> float:
32
34
  return self._interval
33
35
 
34
- # @override
35
- def make_url(self) -> str:
36
+ @override
37
+ def make_weburl(self) -> str:
36
38
  if not self._api_key:
37
39
  self.error("Uninitialized api_key {self.get_class_id()}: {self._api_key}")
38
40
  return ""
@@ -63,8 +65,8 @@ class VisualCrossingThread(RCloudThread):
63
65
  self._api_key = api_key
64
66
  self._location = location
65
67
 
66
- # @override
67
- def process_data(self, data: Any):
68
+ @override
69
+ def process_data(self, data: Any) -> None:
68
70
  self.info("VisualCrossing process_data()")
69
71
  data = data.json()
70
72
  forecast = []
@@ -112,24 +114,35 @@ class VisualCrossing(RCloud):
112
114
  update_interval.
113
115
  """
114
116
 
115
- workerThreadId = VisualCrossingThread.get_class_id()
116
- forecast_topic = Base.mqtt_root_topic + "/forecast"
117
- base_url = "https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/"
118
- update_interval = 12 * 3600
119
- api_key = "SE9W7EHP775N7NDNW8ANM2MZN"
120
- location = "lahti,finland"
117
+ workerThreadId: str = VisualCrossingThread.get_class_id()
118
+ base_url: str = (
119
+ "https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/"
120
+ )
121
+ update_interval: float = 12 * 3600
122
+ api_key: str = "SE9W7EHP775N7NDNW8ANM2MZN"
123
+ location: str = "lahti,finland"
121
124
 
122
- def __init__(self, name="visualcrossing"):
125
+ def __init__(self, name="visualcrossing") -> None:
126
+ """Constructs VisualCrossing automation object for acquiring and publishing
127
+ forecast data.
128
+
129
+ Args:
130
+ name (str, optional): name of the object. Defaults to "visualcrossing".
131
+ """
123
132
  super().__init__(name)
124
- self.debug(f"VisualCrossing created")
133
+ self.worker: Optional[VisualCrossingThread] = None
134
+ self.forecast_topic: str = self.make_topic_name("forecast")
135
+ self.debug(f"VisualCrossing with name {name} created")
125
136
 
126
- def on_connect(self, client, userdata, flags, rc):
137
+ @override
138
+ def on_connect(self, client: object, userdata: Any, flags: int, rc: int) -> None:
127
139
  super().on_connect(client, userdata, flags, rc)
128
140
  if rc == 0:
129
141
  self.subscribe(self.forecast_topic)
130
142
  self.debug(f"VisualCrossing subscribed to topic {self.forecast_topic}")
131
143
 
132
- def on_message(self, client, userdata, msg):
144
+ @override
145
+ def on_message(self, client: object, userdata: Any, msg: MqttMsg) -> None:
133
146
  if msg.topic == self.forecast_topic:
134
147
  em = json.loads(msg.payload.decode())
135
148
  self.on_forecast(em)
@@ -144,10 +157,13 @@ class VisualCrossing(RCloud):
144
157
  """
145
158
  self.debug(f"VisualCrossing: got mqtt message {em}")
146
159
 
147
- # @override
148
- def run(self):
160
+ @override
161
+ def run(self) -> None:
149
162
  # create, initialize and start the asynchronous thread for acquiring forecast
150
- self.worker = Base.instantiate(VisualCrossing.workerThreadId)
163
+
164
+ self.worker = cast(
165
+ VisualCrossingThread, Base.instantiate(VisualCrossing.workerThreadId)
166
+ )
151
167
  self.worker.init(
152
168
  self.forecast_topic,
153
169
  self.base_url,
@@ -155,14 +171,13 @@ class VisualCrossing(RCloud):
155
171
  self.api_key,
156
172
  self.location,
157
173
  )
158
- self.debug(f"VisualCrossing.run(): base_url is {self.base_url}")
159
- self.debug(f"VisualCrossing.run(): interval is {self.update_interval}")
160
- self.debug(f"VisualCrossing.run(): api_key is {self.api_key}")
161
- self.debug(f"VisualCrossing.run(): location is {self.location}")
174
+ self.debug(
175
+ f"VisualCrossing run: {self.base_url}, {self.update_interval}s, location is {self.location}"
176
+ )
162
177
  super().run()
163
178
 
164
- # @override
165
- def to_dict(self):
179
+ @override
180
+ def to_dict(self) -> dict:
166
181
  data = super().to_dict()
167
182
  data["_visualcrossing"] = {
168
183
  "topic": self.forecast_topic,
@@ -172,8 +187,8 @@ class VisualCrossing(RCloud):
172
187
  }
173
188
  return data
174
189
 
175
- # @override
176
- def from_dict(self, data):
190
+ @override
191
+ def from_dict(self, data) -> None:
177
192
  super().from_dict(data)
178
193
  if "_visualcrossing" in data:
179
194
  for key, value in data["_visualcrossing"].items():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: juham_visualcrossing
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: A Weather forecast plugin extending `juham` applications
5
5
  Author-email: J Meskanen <juham.api@gmail.com>
6
6
  Maintainer-email: "J. Meskanen" <juham.api@gmail.com>
@@ -40,11 +40,11 @@ Classifier: License :: OSI Approved :: MIT License
40
40
  Classifier: Programming Language :: Python :: 3.8
41
41
  Requires-Python: >=3.8
42
42
  Description-Content-Type: text/markdown
43
- Requires-Dist: juham >=0.0.7
44
- Requires-Dist: pytz >=2024.1
43
+ Requires-Dist: juham>=0.0.12
44
+ Requires-Dist: pytz>=2024.1
45
45
  Requires-Dist: importlib-metadata
46
46
  Provides-Extra: dev
47
- Requires-Dist: check-manifest ; extra == 'dev'
47
+ Requires-Dist: check-manifest; extra == "dev"
48
48
 
49
49
  juham_visualcrossing
50
50
  ====================
@@ -0,0 +1,8 @@
1
+ juham_visualcrossing/__init__.py,sha256=qsVRSTeJW8jgBtLviUjq5JiJ8Z6eYkBQn6zMWgS0okY,161
2
+ juham_visualcrossing/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
3
+ juham_visualcrossing/visualcrossing.py,sha256=i-YPltSzG9oTrNSfNXVcQSmw5TGMzeVBy1O8DUwrHSo,7232
4
+ juham_visualcrossing-0.0.2.dist-info/METADATA,sha256=RGSHQ8qh5lXNaGbQd4B2Uz2kacSvIaddaySnmKBBu88,3152
5
+ juham_visualcrossing-0.0.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
6
+ juham_visualcrossing-0.0.2.dist-info/entry_points.txt,sha256=A-NSi2RN5KSKwpbKG592v5qnWnGHmIjPktubd5PQ80M,76
7
+ juham_visualcrossing-0.0.2.dist-info/top_level.txt,sha256=7yWaUHZo-Ng96VJBzUFhaFCBamL71PUjIxZISxMBjSM,21
8
+ juham_visualcrossing-0.0.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.2.0)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- juham_visualcrossing/__init__.py,sha256=qsVRSTeJW8jgBtLviUjq5JiJ8Z6eYkBQn6zMWgS0okY,161
2
- juham_visualcrossing/visualcrossing.py,sha256=W-FPKSJJ0IvxhKZhYOzmswbpu3Uuy6EZqE1r_Xjev14,6678
3
- juham_visualcrossing-0.0.1.dist-info/METADATA,sha256=865kbtRSCr1FqX-Tveq4kDyfZJchYhARu6bAyL6GFaM,3154
4
- juham_visualcrossing-0.0.1.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
5
- juham_visualcrossing-0.0.1.dist-info/entry_points.txt,sha256=A-NSi2RN5KSKwpbKG592v5qnWnGHmIjPktubd5PQ80M,76
6
- juham_visualcrossing-0.0.1.dist-info/top_level.txt,sha256=7yWaUHZo-Ng96VJBzUFhaFCBamL71PUjIxZISxMBjSM,21
7
- juham_visualcrossing-0.0.1.dist-info/RECORD,,