Skip to content

Commit 6752497

Browse files
author
brentru
committed
enforce strict forecast types, raise error
1 parent 3f7a8d5 commit 6752497

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Adafruit_IO/mqtt_client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929

3030
logger = logging.getLogger(__name__)
3131

32+
forecast_types = ["current", "forecast_minutes_5",
33+
"forecast_minutes_30", "forecast_hours_1",
34+
"forecast_hours_2", "forecast_hours_6",
35+
"forecast_hours_24", "forecast_days_1",
36+
"forecast_days_2", "forecast_days_5",]
3237

3338
class MQTTClient(object):
3439
"""Interface for publishing and subscribing to feed changes on Adafruit IO
@@ -202,7 +207,10 @@ def subscribe_weather(self, weather_id, forecast_type):
202207
:param int weather_id: weather record you want data for
203208
:param string type: type of forecast data requested
204209
"""
205-
self._client.subscribe('{0}/integration/weather/{1}/{2}'.format(self._username, weather_id, forecast_type))
210+
if forecast_type in forecast_types:
211+
self._client.subscribe('{0}/integration/weather/{1}/{2}'.format(self._username, weather_id, forecast_type))
212+
else:
213+
raise TypeError("Invalid Forecast Type Specified.")
206214

207215
def subscribe_time(self, time):
208216
"""Subscribe to changes on the Adafruit IO time feeds. When the feed is

0 commit comments

Comments
 (0)