Debian Codegraph @

cookidoo_api/types.py

raw
1 """Cookidoo API types."""
2
3 from dataclasses import dataclass, field
4 from datetime import datetime
5 from enum import StrEnum
6
7 from cookidoo_api.const import OAUTH_CLIENT_ID, OAUTH_REDIRECT_URI
8
9
10 class ThermomixMachineType(StrEnum):
11 """Thermomix machine types."""
12
13 TM5 = "TM5"
14 TM6 = "TM6"
15 TM7 = "TM7"
16 TM31 = "TM31"
17
18
19 @dataclass
20 class CookidooLocalizationConfig:
21 """A localization config class."""
22
23 country_code: str = "ch"
24 language: str = "de-CH"
25 url: str = "https://cookidoo.ch/foundation/de-CH"
26
27
28 @dataclass
29 class CookidooConfig:
30 """Cookidoo config type.
31
32 Attributes
33 ----------
34 localization
35 The localization for the api including country, language and url
36 email
37 The email to login
38 password
39 The password to login
40 client_id
41 The OAuth2 client id to run the login flow as
42 redirect_uri
43 The OAuth2 redirect uri registered for ``client_id``
44
45 The login runs as a public client (authorization code + PKCE, no client
46 secret), so both values are public identifiers rather than credentials and
47 they default to the ones of the Cookidoo mobile app. Callers do not need to
48 set them; see ``docs/oauth-client.md``.
49
50 """
51
52 localization: CookidooLocalizationConfig = field(
53 default_factory=CookidooLocalizationConfig
54 )
55 email: str = "your@email"
56 password: str = "1234password!"
57 client_id: str = OAUTH_CLIENT_ID
58 redirect_uri: str = OAUTH_REDIRECT_URI
59
60
61 @dataclass
62 class CookidooUserInfo:
63 """A user info class."""
64
65 id: str
66 username: str
67 description: str | None
68 picture: str | None
69
70
71 @dataclass
72 class CookidooSubscription:
73 """A subscription class."""
74
75 active: bool
76 expires: str
77 start_date: str
78 status: str
79 subscription_level: str
80 subscription_source: str
81 type: str
82 extended_type: str
83
84
85 @dataclass
86 class CookidooDevice:
87 """A paired Thermomix appliance on the account."""
88
89 type: ThermomixMachineType
90
91
92 class CookidooCookState(StrEnum):
93 """State of an ongoing remote-monitored cook."""
94
95 RUNNING = "RUNNING"
96 PAUSED = "PAUSED"
97 DONE = "DONE"
98 ACKNOWLEDGED = "ACKNOWLEDGED"
99 STALE = "STALE"
100
101
102 @dataclass
103 class CookidooCookingActivity:
104 """Live cook state pushed by an appliance's remote monitoring.
105
106 Values the recipe does not provide are ``None`` (the app renders ``"---"``
107 for an unset current temperature, which is normalised to ``None`` here).
108 """
109
110 device_id: str
111 cooking_activity_id: str | None = None
112 state: CookidooCookState | None = None
113 recipe_id: str | None = None
114 recipe_type: str | None = None
115 recipe_name: str | None = None
116 step: str | None = None
117 remaining_seconds: int | None = None
118 is_time_estimated: bool = False
119 current_temperature: float | None = None
120 target_temperature: float | None = None
121 message_title: str | None = None
122 message_body: str | None = None
123 message_criticality: str | None = None
124 completed_at: datetime | None = None
125 stale_at: datetime | None = None
126
127 @property
128 def is_active(self) -> bool:
129 """Whether a cook is currently running or paused."""
130 return self.state in (CookidooCookState.RUNNING, CookidooCookState.PAUSED)
131
132
133 @dataclass
134 class CookidooAuthData:
135 """OAuth2 tokens obtained from a login, for persistence and restore.
136
137 ``expires_at`` is a POSIX timestamp (seconds) for the access token.
138 """
139
140 access_token: str
141 refresh_token: str
142 expires_at: float
143
144
145 @dataclass
146 class CookidooIngredient:
147 """Cookidoo ingredient type.
148
149 Attributes
150 ----------
151 id
152 The id of the ingredient
153 name
154 The label of the ingredient
155 description
156 The description of the item, including the quantity or other helpful information
157
158 """
159
160 id: str
161 name: str
162 description: str
163
164
165 @dataclass
166 class CookidooItem:
167 """Cookidoo item type.
168
169 Attributes
170 ----------
171 id
172 The id of the item
173 name
174 The label of the item
175
176 """
177
178 id: str
179 name: str
180 is_owned: bool
181
182
183 @dataclass
184 class CookidooIngredientItem(CookidooItem):
185 """Cookidoo ingredient item type.
186
187 Attributes
188 ----------
189 description
190 The description of the item, including the quantity or other helpful information
191
192 """
193
194 description: str
195
196
197 @dataclass
198 class CookidooAdditionalItem(CookidooItem):
199 """Cookidoo additional item type."""
200
201 pass
202
203
204 @dataclass
205 class CookidooShoppingRecipe:
206 """Cookidoo shopping recipe type.
207
208 Attributes
209 ----------
210 id
211 The id of the recipe
212 name
213 The label of the recipe
214 ingredients
215 The ingredients of the recipe
216 thumbnail
217 The thumbnail image URL (small preview)
218 image
219 The full-size image URL
220 url
221 The URL of the recipe
222
223 """
224
225 id: str
226 name: str
227 ingredients: list[CookidooIngredient]
228 thumbnail: str | None
229 image: str | None
230 url: str
231
232
233 @dataclass
234 class CookidooSearchRecipeHit:
235 """A single recipe hit from Cookidoo search.
236
237 Attributes
238 ----------
239 id
240 The id of the recipe
241 name
242 The title of the recipe
243 thumbnail
244 The thumbnail image URL (small preview)
245 image
246 The full-size image URL
247 url
248 The URL of the recipe
249
250 """
251
252 id: str
253 name: str
254 thumbnail: str | None
255 image: str | None
256 url: str
257
258
259 @dataclass
260 class CookidooSearchResult:
261 """Cookidoo search result type.
262
263 Attributes
264 ----------
265 recipes
266 List of recipe hits matching the search
267 total
268 Total number of matching recipes
269
270 """
271
272 recipes: list[CookidooSearchRecipeHit]
273 total: int
274
275
276 @dataclass
277 class CookidooCategory:
278 """Cookidoo category type.
279
280 Attributes
281 ----------
282 id
283 The id of the category
284 name
285 The label of the category
286 notes
287 The additional information of the category
288
289 """
290
291 id: str
292 name: str
293 notes: str
294
295
296 @dataclass
297 class CookidooRecipeCollection:
298 """Cookidoo recipe collection type.
299
300 Attributes
301 ----------
302 id
303 The id of the collection
304 name
305 The label of the collection
306 additional_information
307 The additional information of the collection
308
309 """
310
311 id: str
312 name: str
313 total_recipes: int
314
315
316 @dataclass
317 class CookidooNutrition:
318 """Nutrition value type.
319
320 Attributes
321 ----------
322 number
323 The value of the nutrition
324 type
325 The type of nutrition (e.g., protein, fat, kcal, etc.)
326 unittype
327 The unit of the nutrition value (e.g., g, kcal, kJ)
328
329 """
330
331 number: float
332 type: str
333 unittype: str
334
335
336 @dataclass
337 class CookidooRecipeNutrition:
338 """Recipe nutrition type.
339
340 Attributes
341 ----------
342 nutritions
343 List of nutrition values
344 quantity
345 The quantity for which the nutrition applies
346 unit_notation
347 The unit notation (e.g., 'ración')
348
349 """
350
351 nutritions: list[CookidooNutrition]
352 quantity: int
353 unit_notation: str
354
355
356 @dataclass
357 class CookidooNutritionGroup:
358 """Nutrition group type.
359
360 Attributes
361 ----------
362 name
363 The name of the nutrition group
364 recipe_nutritions
365 List of recipe nutrition objects
366
367 """
368
369 name: str
370 recipe_nutritions: list[CookidooRecipeNutrition]
371
372
373 @dataclass
374 class CookidooRecipeStep:
375 """Recipe step type.
376
377 Attributes
378 ----------
379 title
380 The title of the step (may be empty)
381 formatted_text
382 The instruction text for the step, as HTML markup
383
384 """
385
386 title: str
387 formatted_text: str
388
389
390 @dataclass
391 class CookidooRecipeStepGroup:
392 """Recipe step group type.
393
394 Attributes
395 ----------
396 title
397 The title of the step group (may be empty)
398 recipe_steps
399 List of recipe steps in this group
400
401 """
402
403 title: str
404 recipe_steps: list[CookidooRecipeStep]
405
406
407 @dataclass
408 class CookidooShoppingRecipeDetails(CookidooShoppingRecipe):
409 """Cookidoo recipe details type.
410
411 Attributes
412 ----------
413 difficulty
414 The difficulty of the recipe
415 notes
416 Hints and additional information about the recipe
417 categories
418 The categories of the recipe
419 collections
420 The collections of the recipe
421 utensils
422 The utensils needed for the recipe
423 serving_size
424 The service size of the recipe
425 active_time
426 The time needed preparing the recipe [in seconds]
427 total_time
428 The time needed until the recipe is ready [in seconds]
429 nutrition_groups
430 The nutrition groups of the recipe (from API, may be empty)
431 step_groups
432 The grouped cooking instructions for the recipe (from API, may be
433 empty). Instruction text is returned as HTML markup, as sent by the
434 API.
435
436 """
437
438 difficulty: str
439 notes: list[str]
440 categories: list[CookidooCategory]
441 collections: list[CookidooRecipeCollection]
442 utensils: list[str]
443 serving_size: int
444 active_time: int
445 total_time: int
446 nutrition_groups: list[CookidooNutritionGroup]
447 step_groups: list[CookidooRecipeStepGroup]
448
449
450 @dataclass
451 class CookidooChapterRecipe:
452 """Cookidoo chapter recipe type.
453
454 Attributes
455 ----------
456 id
457 The id of the recipe
458 name
459 The label of the recipe
460 total_time
461 The time for the recipe
462
463 """
464
465 id: str
466 name: str
467 total_time: int
468
469
470 @dataclass
471 class CookidooChapter:
472 """Cookidoo chapter type.
473
474 Attributes
475 ----------
476 title
477 The title of the chapter
478 recipes
479 The recipes in the chapter
480
481 """
482
483 name: str
484 recipes: list[CookidooChapterRecipe]
485
486
487 @dataclass
488 class CookidooCustomRecipe:
489 """Cookidoo custom recipe type.
490
491 Attributes
492 ----------
493 id
494 The id of the recipe
495 name
496 The label of the recipe
497 ingredients
498 The ingredients of the recipe
499 instructions
500 The instructions of the recipe
501 tools
502 The tools needed for the recipe
503 serving_size
504 The service size of the recipe
505 active_time
506 The time needed preparing the recipe [in seconds]
507 total_time
508 The time needed until the recipe is ready [in seconds]
509 thumbnail
510 The thumbnail image URL (small preview)
511 image
512 The full-size image URL
513 url
514 The URL of the recipe
515
516 """
517
518 id: str
519 name: str
520 ingredients: list[str]
521 instructions: list[str]
522 tools: list[str]
523 serving_size: int
524 active_time: int
525 total_time: int
526 thumbnail: str | None
527 image: str | None
528 url: str
529
530
531 @dataclass
532 class CookidooCollection:
533 """Cookidoo collection type.
534
535 Attributes
536 ----------
537 id
538 The id of the collection
539 title
540 The title of the collection
541 description
542 The description of the collection
543 chapters
544 The recipes in the collection
545
546 """
547
548 id: str
549 name: str
550 description: str | None
551 chapters: list[CookidooChapter]
552
553
554 @dataclass
555 class CookidooCalendarDayRecipe:
556 """Cookidoo calendar day recipe type.
557
558 Attributes
559 ----------
560 id
561 The id of the recipe
562 name
563 The label of the recipe
564 total_time
565 The time for the recipe
566 thumbnail
567 The thumbnail image URL (small preview)
568 image
569 The full-size image URL
570 url
571 The URL of the recipe
572
573 """
574
575 id: str
576 name: str
577 total_time: int
578 thumbnail: str | None
579 image: str | None
580 url: str
581
582
583 @dataclass
584 class CookidooCalendarDay:
585 """Cookidoo calendar day type.
586
587 Attributes
588 ----------
589 id
590 The id of the calendar day
591 title
592 The title of the calendar day
593 recipes
594 The recipes in the calendar day
595 customer_recipe_ids
596 IDs of custom recipes planned for the day (when returned by the API)
597
598 """
599
600 id: str
601 title: str
602 recipes: list[CookidooCalendarDayRecipe]
603 customer_recipe_ids: list[str] = field(default_factory=list)