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:48 +0000

1import datetime 1a

2import enum 1a

3 

4from isodate import parse_time 1a

5from pydantic import UUID4, ConfigDict, field_validator 1a

6 

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

10 

11 

12class WebhookType(str, enum.Enum): 1a

13 mealplan = "mealplan" 1a

14 

15 

16class CreateWebhook(MealieModel): 1a

17 enabled: bool = True 1a

18 name: str = "" 1a

19 url: str = "" 1a

20 

21 webhook_type: WebhookType = WebhookType.mealplan 1a

22 scheduled_time: datetime.time 1a

23 

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 

30 

31 type: time is treated as a UTC value 

32 type: datetime is treated as a value with a timezone 

33 """ 

34 parser_funcs = [ 1pqrbcdefghijklmno

35 lambda x: parse_datetime(x).astimezone(datetime.UTC).time(), 

36 parse_time, 

37 ] 

38 

39 if isinstance(v, datetime.time): 1pqrbcdefghijklmno

40 return v 1pqrbcdefghijklmno

41 

42 for parser_func in parser_funcs: 42 ↛ 48line 42 didn't jump to line 48 because the loop on line 42 didn't complete1bcdefghijklmno

43 try: 1bcdefghijklmno

44 return parser_func(v) 1bcdefghijklmno

45 except ValueError: 1bcdefghijklmno

46 continue 1bcdefghijklmno

47 

48 raise ValueError(f"Invalid scheduled time: {v}") 

49 

50 

51class SaveWebhook(CreateWebhook): 1a

52 group_id: UUID4 1a

53 household_id: UUID4 1a

54 

55 

56class ReadWebhook(SaveWebhook): 1a

57 id: UUID4 1a

58 model_config = ConfigDict(from_attributes=True) 1a

59 

60 

61class WebhookPagination(PaginationBase): 1a

62 items: list[ReadWebhook] 1a