Coverage for opt/mealie/lib/python3.12/site-packages/mealie/schema/household/webhook.py: 95%
35 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 15:32 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 15:32 +0000
1import datetime 1a
2import enum 1a
4from isodate import parse_time 1a
5from pydantic import UUID4, ConfigDict, field_validator 1a
7from mealie.schema._mealie import MealieModel 1a
8from mealie.schema._mealie.datetime_parse import parse_datetime 1a
9from mealie.schema.response.pagination import PaginationBase 1a
12class WebhookType(str, enum.Enum): 1a
13 mealplan = "mealplan" 1a
16class CreateWebhook(MealieModel): 1a
17 enabled: bool = True 1a
18 name: str = "" 1a
19 url: str = "" 1a
21 webhook_type: WebhookType = WebhookType.mealplan 1a
22 scheduled_time: datetime.time 1a
24 @field_validator("scheduled_time", mode="before") 1a
25 @classmethod 1a
26 def validate_scheduled_time(cls, v): 1a
27 """
28 Validator accepts both datetime and time values from external sources.
29 DateTime types are parsed and converted to time objects without timezones
31 type: time is treated as a UTC value
32 type: datetime is treated as a value with a timezone
33 """
34 parser_funcs = [ 1bcdefghijk
35 lambda x: parse_datetime(x).astimezone(datetime.UTC).time(),
36 parse_time,
37 ]
39 if isinstance(v, datetime.time): 1bcdefghijk
40 return v 1bcdefghijk
42 for parser_func in parser_funcs: 42 ↛ 48line 42 didn't jump to line 48 because the loop on line 42 didn't complete1bcdefghijk
43 try: 1bcdefghijk
44 return parser_func(v) 1bcdefghijk
45 except ValueError: 1bcdefghijk
46 continue 1bcdefghijk
48 raise ValueError(f"Invalid scheduled time: {v}")
51class SaveWebhook(CreateWebhook): 1a
52 group_id: UUID4 1a
53 household_id: UUID4 1a
56class ReadWebhook(SaveWebhook): 1a
57 id: UUID4 1a
58 model_config = ConfigDict(from_attributes=True) 1a
61class WebhookPagination(PaginationBase): 1a
62 items: list[ReadWebhook] 1a