Skip to content

Commit

Permalink
Fix grey dailies with weekly frequency and no weekdays selected in Ha…
Browse files Browse the repository at this point in the history
  • Loading branch information
tr4nt0r authored Jan 13, 2025
1 parent 3aa4668 commit 4dbf2b0
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 3 deletions.
12 changes: 11 additions & 1 deletion homeassistant/components/habitica/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from __future__ import annotations

from abc import abstractmethod
from dataclasses import asdict
from datetime import date, datetime, timedelta
from enum import StrEnum
from typing import TYPE_CHECKING
from uuid import UUID

from dateutil.rrule import rrule
from habiticalib import TaskType
from habiticalib import Frequency, TaskType

from homeassistant.components.calendar import (
CalendarEntity,
Expand Down Expand Up @@ -193,6 +194,10 @@ def get_events(
# only dailies that that are not 'grey dailies'
if not (task.Type is TaskType.DAILY and task.everyX):
continue
if task.frequency is Frequency.WEEKLY and not any(
asdict(task.repeat).values()
):
continue

recurrences = build_rrule(task)
recurrence_dates = self.get_recurrence_dates(
Expand Down Expand Up @@ -334,6 +339,11 @@ def get_events(
if not (task.Type is TaskType.DAILY and task.everyX):
continue

if task.frequency is Frequency.WEEKLY and not any(
asdict(task.repeat).values()
):
continue

recurrences = build_rrule(task)
recurrences_start = self.start_of_today

Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/habitica/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from dataclasses import fields
from dataclasses import asdict, fields
import datetime
from math import floor
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -34,6 +34,8 @@ def next_due_date(task: TaskData, today: datetime.datetime) -> datetime.date | N

if task.everyX == 0 or not task.nextDue: # grey dailies never become due
return None
if task.frequency is Frequency.WEEKLY and not any(asdict(task.repeat).values()):
return None

if TYPE_CHECKING:
assert task.startDate
Expand Down
51 changes: 51 additions & 0 deletions tests/components/habitica/fixtures/duedate_fixture_9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"success": true,
"data": [
{
"_id": "564b9ac9-c53d-4638-9e7f-1cd96fe19baa",
"frequency": "weekly",
"everyX": 1,
"repeat": {
"m": false,
"t": false,
"w": false,
"th": false,
"f": false,
"s": false,
"su": false
},
"streak": 1,
"nextDue": ["2024-09-20T22:00:00.000Z", "2024-09-27T22:00:00.000Z"],
"yesterDaily": true,
"history": [],
"completed": false,
"collapseChecklist": false,
"type": "daily",
"text": "Zahnseide benutzen",
"notes": "Klicke um Änderungen zu machen!",
"tags": [],
"value": -2.9663035443712333,
"priority": 1,
"attribute": "str",
"challenge": {},
"group": {
"completedBy": {},
"assignedUsers": []
},
"byHabitica": false,
"startDate": "2024-09-25T22:00:00.000Z",
"daysOfMonth": [],
"weeksOfMonth": [],
"checklist": [],
"reminders": [],
"createdAt": "2024-07-07T17:51:53.268Z",
"updatedAt": "2024-09-21T22:24:20.154Z",
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
"isDue": false,
"id": "564b9ac9-c53d-4638-9e7f-1cd96fe19baa"
}
],
"notifications": [],
"userV": 589,
"appVersion": "5.28.6"
}
50 changes: 50 additions & 0 deletions tests/components/habitica/fixtures/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,56 @@
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
"isDue": false,
"id": "6e53f1f5-a315-4edd-984d-8d762e4a08ef"
},
{
"repeat": {
"m": false,
"t": false,
"w": false,
"th": false,
"f": false,
"s": false,
"su": false
},
"challenge": {},
"group": {
"completedBy": {},
"assignedUsers": []
},
"_id": "7d92278b-9361-4854-83b6-0a66b57dce20",
"frequency": "weekly",
"everyX": 1,
"streak": 1,
"nextDue": [
"2024-12-14T23:00:00.000Z",
"2025-01-18T23:00:00.000Z",
"2025-02-15T23:00:00.000Z",
"2025-03-15T23:00:00.000Z",
"2025-04-19T23:00:00.000Z",
"2025-05-17T23:00:00.000Z"
],
"yesterDaily": true,
"history": [],
"completed": false,
"collapseChecklist": false,
"type": "daily",
"text": "Lerne eine neue Programmiersprache",
"notes": "Wähle eine Programmiersprache aus, die du noch nicht kennst, und lerne die Grundlagen.",
"tags": [],
"value": -0.9215181434950852,
"priority": 1,
"attribute": "str",
"byHabitica": false,
"startDate": "2024-09-20T23:00:00.000Z",
"daysOfMonth": [],
"weeksOfMonth": [],
"checklist": [],
"reminders": [],
"createdAt": "2024-10-10T15:57:14.304Z",
"updatedAt": "2024-11-27T23:47:29.986Z",
"userId": "5f359083-ef78-4af0-985a-0b2c6d05797c",
"isDue": false,
"id": "7d92278b-9361-4854-83b6-0a66b57dce20"
}
],
"notifications": [
Expand Down
Loading

0 comments on commit 4dbf2b0

Please sign in to comment.