Skip to content

Commit

Permalink
fix:lang kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 12, 2024
1 parent e81ae3c commit b31da30
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 135 deletions.
21 changes: 11 additions & 10 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ def handle_create_reminder(self, message: Message):
connector="and", sep=",", lang=self.lang)}
end = [a.until for a in overlapping if a.until]
if end:
dialog_data["begin"] = nice_time(min([a.expiration for a in overlapping]))
dialog_data["end"] = nice_time(max(end))
dialog_data["begin"] = nice_time(min([a.expiration for a in overlapping]), lang=self.lang)
dialog_data["end"] = nice_time(max(end), lang=self.lang)
dialog = "alert_overlapping_duration_ask"
else:
dialog_data["begin"] = join_word_list([nice_time(a.expiration) for a in overlapping],
dialog_data["begin"] = join_word_list([nice_time(a.expiration, lang=self.lang) for a in overlapping],
connector="and", sep=",", lang=self.lang)
dialog = "alert_overlapping_ask"

Expand Down Expand Up @@ -1119,7 +1119,7 @@ def confirm_alert(self, alert: Alert, message: Message,
# This is patching LF type annotation bug
# noinspection PyTypeChecker
spoken_alert_time = \
nice_time(alert.expiration, self.lang,
nice_time(alert.expiration, lang=self.lang,
use_24hour=self.use_24hour, use_ampm=not self.use_24hour)

# Schedule alert expirations
Expand Down Expand Up @@ -1260,7 +1260,8 @@ def converse(self, message: Message):
for alert in active:
self._snooze_alert(alert, snooze_duration)
self.speak_dialog("confirm_snooze_alert",
{"duration": nice_duration(round(duration.total_seconds()))})
{"duration": nice_duration(round(duration.total_seconds()),
lang=self.lang)})
return True
return False

Expand Down Expand Up @@ -1380,7 +1381,7 @@ def _pick_one_by_time(self, alerts: List[Alert], dialog: str = ""):
alerts.sort(key=lambda x: x.expiration)
spoken_list = [
f"{pronounce_number(i + 1)}. \
{nice_date_time(alert.expiration, use_24hour=self.use_24hour, use_ampm=not self.use_24hour)}"
{nice_date_time(alert.expiration, use_24hour=self.use_24hour, use_ampm=not self.use_24hour, lang=self.lang)}"
for i, alert in enumerate(alerts)
]
self.speak(join_word_list(spoken_list, connector="and", sep=",", lang=self.lang), wait=True)
Expand Down Expand Up @@ -1537,7 +1538,7 @@ def _display_list(self, alerts: List[Alert], header: str = "Todo"):
"main": alert.alert_name,
"secondary": ""
if alert.expiration is None
else datetime_display(alert.expiration, alert.until),
else datetime_display(alert.expiration, alert.until, alert.lang),
}
for alert in alerts
]
Expand Down Expand Up @@ -1689,8 +1690,8 @@ def _event_snooze_alarm(self, message):
self._snooze_alert(alert)
self.speak_dialog("confirm_snooze_alert",
{"name": alert.alert_name,
"duration": nice_duration(
self.snooze_duration)}, wait=True)
"duration": nice_duration(self.snooze_duration, lang=self.lang)},
wait=True)

def _gui_dismiss_notification(self, message):
if not message.data.get('alert'):
Expand Down Expand Up @@ -1739,7 +1740,7 @@ def _alert_prenotification(self, alert: Alert):
"alert_prenotification",
{
"reminder": alert.alert_name,
"time_until": nice_duration(alert.time_to_expiration),
"time_until": nice_duration(alert.time_to_expiration, lang=self.lang),
},
)
time.sleep(min(20, self.alert_timeout_seconds))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_requirements(requirements_filename: str):


def find_resource_files():
resource_base_dirs = ("locale", "gui", "vocab", "dialog", "regex", "res")
resource_base_dirs = ("locale", "gui", "res")
package_data = ["skill.json"]
for res in resource_base_dirs:
if path.isdir(path.join(BASE_PATH, res)):
Expand Down
68 changes: 29 additions & 39 deletions test/test_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ def test_handle_create_event(self):
overlapping_reminder = _get_message_from_file(
"reminder_event_length_at_time.json"
)
begin = nice_time(self.valid_event.expiration)
end = nice_time(self.valid_event.until)
begin = nice_time(self.valid_event.expiration, lang="en-us")
end = nice_time(self.valid_event.until, lang="en-us")
self.skill.handle_create_event(overlapping_reminder)
self.skill.ask_yesno.assert_called_once()
self.skill.ask_yesno.assert_called_with(
Expand All @@ -469,7 +469,7 @@ def test_handle_create_event(self):
overlapping_reminder2 = _get_message_from_file(
"reminder_event_length_at_time2.json"
)
begin = nice_time(self.valid_event2.expiration)
begin = nice_time(self.valid_event2.expiration, lang="en-us")
self.skill.handle_create_event(overlapping_reminder2)
self.skill.ask_yesno.assert_called_with(
"alert_overlapping_ask", {"event": "valid event 2",
Expand Down Expand Up @@ -718,7 +718,7 @@ def test_handle_event_timeframe_check(self):
# check in a time range (note: 1 minute gap 11:59-00:00)
check_message.data["utterance"] = \
f"are there any events between {day} 00:00 am and 11:59 pm"
begin = nice_time(self.valid_event.expiration, use_ampm=True)
begin = nice_time(self.valid_event.expiration, use_ampm=True, lang="en-us")

self.skill.handle_event_timeframe_check(check_message)
self.assertEqual(self.skill.speak_dialog.call_count, 2)
Expand Down Expand Up @@ -793,9 +793,8 @@ def test_handle_next_alert(self):
{
"kind": "alarm",
"name": "",
"begin": nice_date_time(self.valid_alarm_1.expiration, use_ampm=True),
"remaining": spoken_duration(self.valid_alarm_1.expiration,
lang="en-us")
"begin": nice_date_time(self.valid_alarm_1.expiration, use_ampm=True, lang="en-us"),
"remaining": spoken_duration(self.valid_alarm_1.expiration, lang="en-us")
},
wait=True
)
Expand All @@ -806,9 +805,8 @@ def test_handle_next_alert(self):
{
"kind": "timer",
"name": "oven",
"begin": nice_time(self.valid_timer.expiration, use_ampm=True),
"remaining": spoken_duration(self.valid_timer.expiration,
lang="en-us")
"begin": nice_time(self.valid_timer.expiration, use_ampm=True, lang="en-us"),
"remaining": spoken_duration(self.valid_timer.expiration, lang="en-us")
},
wait=True
)
Expand All @@ -820,10 +818,9 @@ def test_handle_next_alert(self):
{
"kind": "reminder",
"name": self.valid_reminder.alert_name,
"begin": nice_date_time(self.valid_reminder.expiration, use_ampm=True),
"end": nice_date_time(self.valid_reminder.until, use_ampm=True),
"remaining": spoken_duration(self.valid_reminder.expiration,
lang="en-us")
"begin": nice_date_time(self.valid_reminder.expiration, use_ampm=True, lang="en-us"),
"end": nice_date_time(self.valid_reminder.until, use_ampm=True, lang="en-us"),
"remaining": spoken_duration(self.valid_reminder.expiration, lang="en-us")
},
wait=True
)
Expand All @@ -835,9 +832,8 @@ def test_handle_next_alert(self):
{
"kind": "timer",
"name": "oven",
"begin": nice_time(self.valid_timer.expiration, use_ampm=True),
"remaining": spoken_duration(self.valid_timer.expiration,
lang="en-us")
"begin": nice_time(self.valid_timer.expiration, use_ampm=True, lang="en-us"),
"remaining": spoken_duration(self.valid_timer.expiration, lang="en-us")
},
wait=True
)
Expand Down Expand Up @@ -1483,10 +1479,10 @@ def test_get_alert_dialog_data(self, mock_spoken_type, mock_translate):
"name": "appointment",
"kind": "translated",
"begin": nice_time(
today_alert.expiration, use_24hour=False, use_ampm=True
today_alert.expiration, use_24hour=False, use_ampm=True, lang="en-us"
),
"end": nice_time(
today_alert.until, use_24hour=False, use_ampm=True
today_alert.until, use_24hour=False, use_ampm=True, lang="en-us"
),
"remaining": "one minute",
},
Expand All @@ -1505,10 +1501,9 @@ def test_get_alert_dialog_data(self, mock_spoken_type, mock_translate):
"name": "wakeup",
"kind": "translated",
"begin": nice_date_time(
one_time.expiration, use_24hour=False, use_ampm=True
one_time.expiration, use_24hour=False, use_ampm=True, lang="en-us"
),
"remaining": spoken_duration(one_time.expiration,
lang="en-us")
"remaining": spoken_duration(one_time.expiration, lang="en-us")
},
)

Expand All @@ -1529,10 +1524,9 @@ def test_get_alert_dialog_data(self, mock_spoken_type, mock_translate):
"kind": "translated",
"repeat": "translated",
"begin": nice_time(
weekend.expiration, use_24hour=False, use_ampm=True
weekend.expiration, use_24hour=False, use_ampm=True, lang="en-us"
),
"remaining": spoken_duration(weekend.expiration,
lang="en-us")
"remaining": spoken_duration(weekend.expiration, lang="en-us")
},
)

Expand All @@ -1559,10 +1553,9 @@ def test_get_alert_dialog_data(self, mock_spoken_type, mock_translate):
"kind": "translated",
"repeat": "translated",
"begin": nice_time(
weekday.expiration, use_24hour=False, use_ampm=True
weekday.expiration, use_24hour=False, use_ampm=True, lang="en-us"
),
"remaining": spoken_duration(weekday.expiration,
lang="en-us")
"remaining": spoken_duration(weekday.expiration, lang="en-us")
},
)

Expand Down Expand Up @@ -1591,10 +1584,9 @@ def test_get_alert_dialog_data(self, mock_spoken_type, mock_translate):
"repeat": "translated",
"kind": "translated",
"begin": nice_time(
daily.expiration, use_24hour=False, use_ampm=True
daily.expiration, use_24hour=False, use_ampm=True, lang="en-us"
),
"remaining": spoken_duration(daily.expiration,
lang="en-us")
"remaining": spoken_duration(daily.expiration, lang="en-us")
},
)

Expand All @@ -1615,10 +1607,9 @@ def test_get_alert_dialog_data(self, mock_spoken_type, mock_translate):
"repeat": "translated",
"kind": "translated",
"begin": nice_time(
weekly.expiration, use_24hour=False, use_ampm=True
weekly.expiration, use_24hour=False, use_ampm=True, lang="en-us"
),
"remaining": spoken_duration(daily.expiration,
lang="en-us")
"remaining": spoken_duration(daily.expiration, lang="en-us")
},
)

Expand All @@ -1635,12 +1626,11 @@ def test_get_alert_dialog_data(self, mock_spoken_type, mock_translate):
{
"name": "take pill",
"kind": "translated",
"repeat": nice_duration(dt.timedelta(hours=8).total_seconds()),
"repeat": nice_duration(dt.timedelta(hours=8).total_seconds(), lang="en-us"),
"begin": nice_time(
eight_hour.expiration, use_24hour=False, use_ampm=True
eight_hour.expiration, use_24hour=False, use_ampm=True, lang="en-us"
),
"remaining": spoken_duration(daily.expiration,
lang="en-us")
"remaining": spoken_duration(daily.expiration, lang="en-us")
},
)

Expand All @@ -1661,7 +1651,7 @@ def test_get_alert_dialog_data(self, mock_spoken_type, mock_translate):
"name": "",
"kind": "timer",
"begin": nice_time(
two_minute.expiration, use_24hour=False, use_ampm=True
two_minute.expiration, use_24hour=False, use_ampm=True, lang="en-us"
),
"remaining": "two minutes"
},
Expand Down
5 changes: 3 additions & 2 deletions util/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
from dateutil.relativedelta import relativedelta
from json_database.utils import merge_dict
from ovos_utils.log import LOG
from ovos_config.locale import get_default_tz
from ovos_config.locale import get_default_tz, get_default_lang
from ovos_config import Configuration


from ovos_skill_alerts.util import AlertType, DAVType, AlertPriority, Weekdays
from ovos_skill_alerts.util.dav_utils import process_ical_event, process_ical_todo

Expand Down Expand Up @@ -105,7 +106,7 @@ def lang(self) -> str:
"""
Returns the lang associated with this alert
"""
return self._data.get("lang")
return self._data.get("lang") or get_default_lang()

@property
def created(self) -> dt.datetime:
Expand Down
Loading

0 comments on commit b31da30

Please sign in to comment.