From 691aa94048f5dc1f8b80b4b36725b2f34bb76071 Mon Sep 17 00:00:00 2001 From: Ben McClure Date: Thu, 11 May 2023 14:08:48 +0000 Subject: [PATCH] Add option to show overdue chores today on the calendar, instead of in the past --- custom_components/chore_helper/calendar.py | 4 ++++ custom_components/chore_helper/chore.py | 4 ++++ custom_components/chore_helper/config_flow.py | 5 +++++ custom_components/chore_helper/const.py | 2 ++ custom_components/chore_helper/translations/en.json | 6 ++++-- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/custom_components/chore_helper/calendar.py b/custom_components/chore_helper/calendar.py index d5634e5..9de68a9 100644 --- a/custom_components/chore_helper/calendar.py +++ b/custom_components/chore_helper/calendar.py @@ -103,7 +103,11 @@ async def async_get_events( continue chore = hass.data[DOMAIN][SENSOR_PLATFORM][entity] start = chore.get_next_due_date(start_date, True) + today = datetime.now().date() while start is not None and start_date <= start <= end_date: + if chore.show_overdue_today and (start < today): + start = today + try: end = start + timedelta(days=1) except TypeError: diff --git a/custom_components/chore_helper/chore.py b/custom_components/chore_helper/chore.py index c08abfe..8ae1d24 100644 --- a/custom_components/chore_helper/chore.py +++ b/custom_components/chore_helper/chore.py @@ -47,6 +47,7 @@ class Chore(RestoreEntity): "_offset_dates", "_add_dates", "_remove_dates", + "show_overdue_today", "config_entry", "last_completed", ) @@ -79,6 +80,9 @@ def __init__(self, config_entry: ConfigEntry) -> None: const.CONF_DATE_FORMAT, const.DEFAULT_DATE_FORMAT ) self._forecast_dates: int = config.get(const.CONF_FORECAST_DATES) or 0 + self.show_overdue_today: bool = ( + config.get(const.CONF_SHOW_OVERDUE_TODAY) or False + ) self._due_dates: list[date] = [] self._next_due_date: date | None = None self._last_updated: datetime | None = None diff --git a/custom_components/chore_helper/config_flow.py b/custom_components/chore_helper/config_flow.py index 95a3a48..e8fc950 100644 --- a/custom_components/chore_helper/config_flow.py +++ b/custom_components/chore_helper/config_flow.py @@ -111,6 +111,11 @@ def general_schema_definition( ), optional(ATTR_HIDDEN, handler.options, False): bool, optional(const.CONF_MANUAL, handler.options, False): bool, + optional( + const.CONF_SHOW_OVERDUE_TODAY, + handler.options, + const.DEFAULT_SHOW_OVERDUE_TODAY, + ): bool, } return schema diff --git a/custom_components/chore_helper/const.py b/custom_components/chore_helper/const.py index d1f4502..ad5d6d2 100644 --- a/custom_components/chore_helper/const.py +++ b/custom_components/chore_helper/const.py @@ -28,6 +28,7 @@ CONF_SENSOR = "sensor" CONF_ENABLED = "enabled" CONF_FORECAST_DATES = "forecast_dates" +CONF_SHOW_OVERDUE_TODAY = "show_overdue_today" CONF_FREQUENCY = "frequency" CONF_MANUAL = "manual_update" CONF_ICON_NORMAL = "icon_normal" @@ -58,6 +59,7 @@ DEFAULT_FIRST_WEEK = 1 DEFAULT_DATE_FORMAT = "%b-%d-%Y" DEFAULT_FORECAST_DATES = 10 +DEFAULT_SHOW_OVERDUE_TODAY = False DEFAULT_ICON_NORMAL = "mdi:broom" DEFAULT_ICON_TODAY = "mdi:bell" diff --git a/custom_components/chore_helper/translations/en.json b/custom_components/chore_helper/translations/en.json index 3113e5c..022ee14 100644 --- a/custom_components/chore_helper/translations/en.json +++ b/custom_components/chore_helper/translations/en.json @@ -13,7 +13,8 @@ "icon_tomorrow": "Icon due tomorrow (mdi:bell-outline) - optional", "icon_today": "Icon due today (mdi:bell) - optional", "icon_overdue": "Icon overdue (mdi:bell-alert) - optional", - "forecast_dates": "Number of future due dates to forecast" + "forecast_dates": "Number of future due dates to forecast", + "show_overdue_today": "Show overdue chore today on calendar" } }, "detail": { @@ -66,7 +67,8 @@ "icon_tomorrow": "Icon due tomorrow (mdi:bell-outline) - optional", "icon_today": "Icon due today (mdi:bell) - optional", "icon_overdue": "Icon overdue (mdi:bell-alert) - optional", - "forecast_dates": "Number of future due dates to forecast" + "forecast_dates": "Number of future due dates to forecast", + "show_overdue_today": "Show overdue chore today on calendar" } }, "detail": {