Skip to content

Commit

Permalink
Move the rest of the old dialog class to the new ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisveilleux committed May 12, 2021
1 parent 47b6baa commit 37de4a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 9 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
LocationNotFoundError,
OpenWeatherMapApi,
WeatherConfig,
WeatherDialog,
WeatherIntent,
WeatherReport,
WeeklyDialog,
Expand Down Expand Up @@ -477,12 +476,13 @@ def handle_next_precipitation(self, message: Message):
Args:
message: Message Bus event information from the intent parser
"""
intent_data = WeatherIntent(message, self.lang)
intent_data = self._get_intent_data(message)
weather = self._get_weather(intent_data)
if weather is not None:
forecast, timeframe = weather.get_next_precipitation(intent_data)
intent_data.timeframe = timeframe
dialog = WeatherDialog(forecast, self.weather_config, intent_data)
dialog_args = intent_data, self.weather_config, forecast
dialog = get_dialog_for_timeframe(intent_data.timeframe, dialog_args)
dialog.build_next_precipitation_dialog()
spoken_percentage = self.translate(
"percentage-number", data=dict(number=dialog.data["percent"])
Expand All @@ -507,7 +507,8 @@ def handle_humidity(self, message: Message):
weather = self._get_weather(intent_data)
if weather is not None:
intent_weather = weather.get_weather_for_intent(intent_data)
dialog = WeatherDialog(intent_weather, self.weather_config, intent_data)
dialog_args = intent_data, self.weather_config, intent_weather
dialog = get_dialog_for_timeframe(intent_data.timeframe, dialog_args)
dialog.build_humidity_dialog()
dialog.data.update(
humidity=self.translate(
Expand Down Expand Up @@ -847,7 +848,7 @@ def _build_forecast_dialogs(
:param forecast: daily forecasts to report
:param intent_data: information about the intent that was triggered
:return: one WeatherDialog instance for each day being reported.
:return: one DailyDialog instance for each day being reported.
"""
dialogs = list()
for forecast_day in forecast:
Expand Down Expand Up @@ -1021,7 +1022,7 @@ def _report_weather_condition(self, message: Message, condition: str):

def _build_condition_dialog(
self, weather, intent_data: WeatherIntent, condition: str
) -> WeatherDialog:
):
"""Builds a dialog for the requested weather condition.
Args:
Expand Down Expand Up @@ -1050,7 +1051,8 @@ def _report_wind(self, message: Message):
intent_weather.wind_direction = self.translate(
intent_weather.wind_direction
)
dialog = WeatherDialog(intent_weather, self.weather_config, intent_data)
dialog_args = intent_data, self.weather_config, intent_weather
dialog = get_dialog_for_timeframe(intent_data.timeframe, dialog_args)
dialog.build_wind_dialog()
self._speak_weather(dialog)

Expand Down
10 changes: 5 additions & 5 deletions skill/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
# - daily.snow.alternative.local
# - all hourly.<condition>.alternative.local/location
# - all hourly.<condition>.not.expected.local/location
class Dialog:
class WeatherDialog:
"""Abstract base class for the weather dialog builders."""

def __init__(self, intent_data: WeatherIntent, config: WeatherConfig):
Expand Down Expand Up @@ -86,7 +86,7 @@ def _add_location(self):
self.data.update(location=spoken_location)


class CurrentDialog(Dialog):
class CurrentDialog(WeatherDialog):
"""Weather dialog builder for current weather."""

def __init__(
Expand Down Expand Up @@ -193,7 +193,7 @@ def build_humidity_dialog(self):
self._add_location()


class HourlyDialog(Dialog):
class HourlyDialog(WeatherDialog):
"""Weather dialog builder for hourly weather."""

def __init__(
Expand Down Expand Up @@ -270,7 +270,7 @@ def build_next_precipitation_dialog(self):
self._add_location()


class DailyDialog(Dialog):
class DailyDialog(WeatherDialog):
"""Weather dialog builder for daily weather."""

def __init__(
Expand Down Expand Up @@ -381,7 +381,7 @@ def build_next_precipitation_dialog(self):
self._add_location()


class WeeklyDialog(Dialog):
class WeeklyDialog(WeatherDialog):
"""Weather dialog builder for weekly weather."""

def __init__(
Expand Down

0 comments on commit 37de4a5

Please sign in to comment.