Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRut committed Sep 10, 2021
2 parents 055ebdf + 9671b59 commit 30b9c74
Show file tree
Hide file tree
Showing 37 changed files with 3,220 additions and 820 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: black-action
on: [push, pull_request]
jobs:
linter_name:
name: runner / black formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: rickstaa/action-black@v1
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## [v1.0.0](https://github.com/SebRut/pygrocy/tree/v1.0.0) (2021-09-10)

[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.30.0...v1.0.0)

**Implemented enhancements:**

- Add assigned\_to\_user to task [\#188](https://github.com/SebRut/pygrocy/issues/188)
- Add support for meal plan sections in grocy v3.1.0 [\#172](https://github.com/SebRut/pygrocy/issues/172)

**Closed issues:**

- add category field to task [\#189](https://github.com/SebRut/pygrocy/issues/189)
- support consuming decimal amounts [\#187](https://github.com/SebRut/pygrocy/issues/187)

**Merged pull requests:**

- add assigned\_to\_user field to Task [\#190](https://github.com/SebRut/pygrocy/pull/190) ([SebRut](https://github.com/SebRut))
- apply black to everything [\#185](https://github.com/SebRut/pygrocy/pull/185) ([SebRut](https://github.com/SebRut))
- migrate to pydantic [\#184](https://github.com/SebRut/pygrocy/pull/184) ([SebRut](https://github.com/SebRut))
- add basic support for product and note type [\#183](https://github.com/SebRut/pygrocy/pull/183) ([SebRut](https://github.com/SebRut))
- add meal plan section support [\#182](https://github.com/SebRut/pygrocy/pull/182) ([SebRut](https://github.com/SebRut))
- add users getter [\#170](https://github.com/SebRut/pygrocy/pull/170) ([SebRut](https://github.com/SebRut))

## [v0.30.0](https://github.com/SebRut/pygrocy/tree/v0.30.0) (2021-08-23)

[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.29.0...v0.30.0)
Expand Down
9 changes: 7 additions & 2 deletions pygrocy/data_models/chore.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from datetime import datetime
from enum import Enum
from typing import List, Dict
from typing import Dict

from pygrocy.base import DataModel
from pygrocy.data_models.user import User
from pygrocy.grocy_api_client import CurrentChoreResponse, ChoreDetailsResponse, GrocyApiClient
from pygrocy.grocy_api_client import (
ChoreDetailsResponse,
CurrentChoreResponse,
GrocyApiClient,
)


class PeriodType(str, Enum):
Expand Down
1 change: 1 addition & 0 deletions pygrocy/data_models/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ class EntityType(str, Enum):
USER_ENTITIES = "userentities"
USER_OBJECTS = "userobjects"
MEAL_PLAN = "meal_plan"
MEAL_PLAN_SECTIONS = "meal_plan_sections"
57 changes: 56 additions & 1 deletion pygrocy/data_models/meal_items.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import base64
from datetime import datetime
from enum import Enum

from pygrocy.base import DataModel
from pygrocy.grocy_api_client import (
GrocyApiClient,
MealPlanResponse,
MealPlanSectionResponse,
RecipeDetailsResponse,
)

Expand Down Expand Up @@ -50,6 +52,36 @@ def get_picture_url_path(self, width: int = 400):
return f"{path}?force_serve_as=picture&best_fit_width={width}"


class MealPlanSection(DataModel):
def __init__(self, response: MealPlanSectionResponse):
self._id = response.id
self._name = response.name
self._sort_number = response.sort_number
self._row_created_timestamp = response.row_created_timestamp

@property
def id(self) -> int:
return self._id

@property
def name(self) -> str:
return self._name

@property
def sort_number(self) -> int:
return self._sort_number

@property
def row_created_timestamp(self) -> datetime:
return self._row_created_timestamp


class MealPlanItemType(str, Enum):
NOTE = "note"
PRODUCT = "product"
RECIPE = "recipe"


class MealPlanItem(DataModel):
def __init__(self, response: MealPlanResponse):
self._id = response.id
Expand All @@ -58,13 +90,16 @@ def __init__(self, response: MealPlanResponse):
self._recipe_id = response.recipe_id
self._recipe_servings = response.recipe_servings
self._note = response.note
self._section_id = response.section_id
self._type = MealPlanItemType(response.type)
self._product_id = response.product_id

@property
def id(self) -> int:
return self._id

@property
def day(self) -> datetime:
def day(self) -> datetime.date:
return self._day

@property
Expand All @@ -83,8 +118,28 @@ def note(self) -> str:
def recipe(self) -> RecipeItem:
return self._recipe

@property
def section_id(self) -> int:
return self._section_id

@property
def section(self) -> MealPlanSection:
return self._section

@property
def type(self) -> MealPlanItemType:
return self._type

@property
def product_id(self) -> int:
return self._product_id

def get_details(self, api_client: GrocyApiClient):
if self.recipe_id:
recipe = api_client.get_recipe(self.recipe_id)
if recipe:
self._recipe = RecipeItem(recipe)
if self.section_id:
section = api_client.get_meal_plan_section(self.section_id)
if section:
self._section = MealPlanSection(section)
6 changes: 3 additions & 3 deletions pygrocy/data_models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _init_from_CurrentStockResponse(self, response: CurrentStockResponse):
self._init_from_ProductData(response.product)

def _init_from_MissingProductResponse(self, response: MissingProductResponse):
self._id = response.product_id
self._id = response.id
self._name = response.name
self._amount_missing = response.amount_missing
self._is_partly_in_stock = response.is_partly_in_stock
Expand All @@ -78,7 +78,7 @@ def get_details(self, api_client: GrocyApiClient):
details = api_client.get_product(self.id)
if details:
self._name = details.product.name
self._barcodes = details.barcodes
self._barcodes = [ProductBarcode(barcode) for barcode in details.barcodes]
self._product_group_id = details.product.product_group_id

@property
Expand All @@ -98,7 +98,7 @@ def available_amount(self) -> float:
return self._available_amount

@property
def best_before_date(self) -> datetime:
def best_before_date(self) -> datetime.date:
return self._best_before_date

@property
Expand Down
46 changes: 42 additions & 4 deletions pygrocy/data_models/task.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
from datetime import datetime
from typing import Dict

from pygrocy.base import DataModel
from pygrocy.grocy_api_client import TaskResponse
from pygrocy.data_models.user import User
from pygrocy.grocy_api_client import TaskCategoryDto, TaskResponse


class TaskCategory(DataModel):
def __init__(self, data: TaskCategoryDto):
self._id = data.id
self._name = data.name
self._description = data.description
self._row_created_timestamp = data.row_created_timestamp

@property
def id(self) -> int:
return self._id

@property
def name(self) -> str:
return self._name

@property
def description(self) -> str:
return self._description

@property
def row_created_timestamp(self) -> datetime:
return self._row_created_timestamp


class Task(DataModel):
Expand All @@ -14,11 +40,15 @@ def __init__(self, response: TaskResponse):
self._done = response.done
self._done_timestamp = response.done_timestamp
self._category_id = response.category_id
if response.category:
self._category = TaskCategory(response.category)
self._assigned_to_user_id = response.assigned_to_user_id
if response.assigned_to_user:
self._assigned_to_user = User(response.assigned_to_user)
self._userfields = response.userfields

@property
def id(self) -> str:
def id(self) -> int:
return self._id

@property
Expand All @@ -30,7 +60,7 @@ def description(self) -> str:
return self._description

@property
def due_date(self) -> datetime:
def due_date(self) -> datetime.date:
return self._due_date

@property
Expand All @@ -45,10 +75,18 @@ def done_timestamp(self) -> datetime:
def category_id(self) -> int:
return self._category_id

@property
def category(self) -> TaskCategory:
return self._category

@property
def assigned_to_user_id(self) -> int:
return self._assigned_to_user_id

@property
def assigned_to_user(self) -> User:
return self._assigned_to_user

@property
def userfields(self) -> Dict[str, str]:
return self._userfields
return self._userfields
2 changes: 1 addition & 1 deletion pygrocy/data_models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def last_name(self) -> str:

@property
def display_name(self) -> str:
return self._display_name
return self._display_name
23 changes: 21 additions & 2 deletions pygrocy/grocy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .data_models.battery import Battery
from .data_models.chore import Chore
from .data_models.generic import EntityType
from .data_models.meal_items import MealPlanItem, RecipeItem
from .data_models.meal_items import MealPlanItem, MealPlanSection, RecipeItem
from .data_models.product import Group, Product, ShoppingListProduct
from .data_models.task import Task
from .data_models.user import User # noqa: F401
Expand Down Expand Up @@ -98,7 +98,7 @@ def all_products(self) -> List[Product]:
raw_products = self.get_generic_objects_for_type(EntityType.PRODUCTS)
from pygrocy.grocy_api_client import ProductData

product_datas = [ProductData(product) for product in raw_products]
product_datas = [ProductData(**product) for product in raw_products]
return [Product(product) for product in product_datas]

def chores(self, get_details: bool = False) -> List[Chore]:
Expand Down Expand Up @@ -237,3 +237,22 @@ def delete_generic(self, entity_type: EntityType, object_id: int):

def get_generic_objects_for_type(self, entity_type: EntityType):
return self._api_client.get_generic_objects_for_type(entity_type.value)

def meal_plan_sections(self) -> List[MealPlanSection]:
raw_sections = self._api_client.get_meal_plan_sections()
return [MealPlanSection(section) for section in raw_sections]

def meal_plan_section(self, meal_plan_section_id: int) -> MealPlanSection:
section = self._api_client.get_meal_plan_section(meal_plan_section_id)

if section:
return MealPlanSection(section)

def users(self) -> List[User]:
user_dtos = self._api_client.get_users()
return [User(user) for user in user_dtos]

def user(self, user_id: int = None) -> User:
user = self._api_client.get_user(user_id=user_id)
if user:
return User(user)
Loading

0 comments on commit 30b9c74

Please sign in to comment.