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

Commit

Permalink
migrate to pydantic (#184)
Browse files Browse the repository at this point in the history
* add pydantic dependency

* switch battery server comm to pydantic

* migrate chores to pydantic

* migrate meal plans to pydantic

* migrate barcode to pydantic

* migrate product related stuff to pydantic

* migrate shoppinglist to pydantic

* migrate stock stuff to pydantic

* migrate tasks to pydantic

* fix some types
  • Loading branch information
SebRut committed Sep 1, 2021
1 parent 521fc6b commit 77ae694
Show file tree
Hide file tree
Showing 17 changed files with 206 additions and 817 deletions.
2 changes: 1 addition & 1 deletion pygrocy/data_models/meal_items.py
Expand Up @@ -99,7 +99,7 @@ def id(self) -> int:
return self._id

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

@property
Expand Down
6 changes: 3 additions & 3 deletions pygrocy/data_models/product.py
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
4 changes: 2 additions & 2 deletions pygrocy/data_models/task.py
Expand Up @@ -19,7 +19,7 @@ def __init__(self, response: TaskResponse):
self._userfields = response.userfields

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

@property
Expand All @@ -31,7 +31,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 Down
2 changes: 1 addition & 1 deletion pygrocy/grocy.py
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

0 comments on commit 77ae694

Please sign in to comment.