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

Commit

Permalink
Merge c81f80e into ba7d13e
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelvriend committed Jul 24, 2022
2 parents ba7d13e + c81f80e commit 721f7bc
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions pygrocy/grocy_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ def _do_delete_request(self, end_url: str):

def get_stock(self) -> List[CurrentStockResponse]:
parsed_json = self._do_get_request("stock")
return [CurrentStockResponse(**response) for response in parsed_json]
if parsed_json:
return [CurrentStockResponse(**response) for response in parsed_json]
return []

def get_volatile_stock(self) -> CurrentVolatilStockResponse:
parsed_json = self._do_get_request("stock/volatile")
Expand All @@ -390,7 +392,9 @@ def get_product_by_barcode(self, barcode) -> ProductDetailsResponse:

def get_chores(self, query_filters: List[str] = None) -> List[CurrentChoreResponse]:
parsed_json = self._do_get_request("chores", query_filters)
return [CurrentChoreResponse(**chore) for chore in parsed_json]
if parsed_json:
return [CurrentChoreResponse(**chore) for chore in parsed_json]
return []

def get_chore(self, chore_id: int) -> ChoreDetailsResponse:
url = f"chores/{chore_id}"
Expand Down Expand Up @@ -584,7 +588,9 @@ def get_shopping_list(
self, query_filters: List[str] = None
) -> List[ShoppingListItem]:
parsed_json = self._do_get_request("objects/shopping_list", query_filters)
return [ShoppingListItem(**response) for response in parsed_json]
if parsed_json:
return [ShoppingListItem(**response) for response in parsed_json]
return []

def add_missing_product_to_shopping_list(self, shopping_list_id: int = None):
data = None
Expand Down Expand Up @@ -626,7 +632,9 @@ def remove_product_in_shopping_list(

def get_product_groups(self, query_filters: List[str] = None) -> List[LocationData]:
parsed_json = self._do_get_request("objects/product_groups", query_filters)
return [LocationData(**response) for response in parsed_json]
if parsed_json:
return [LocationData(**response) for response in parsed_json]
return []

def upload_product_picture(self, product_id: int, pic_path: str):
b64fn = base64.b64encode("{}.jpg".format(product_id).encode("ascii"))
Expand Down Expand Up @@ -654,7 +662,9 @@ def get_last_db_changed(self):

def get_tasks(self, query_filters: List[str] = None) -> List[TaskResponse]:
parsed_json = self._do_get_request("tasks", query_filters)
return [TaskResponse(**data) for data in parsed_json]
if parsed_json:
return [TaskResponse(**data) for data in parsed_json]
return []

def get_task(self, task_id: int) -> TaskResponse:
url = f"objects/tasks/{task_id}"
Expand All @@ -671,7 +681,9 @@ def complete_task(self, task_id: int, done_time: datetime = datetime.now()):

def get_meal_plan(self, query_filters: List[str] = None) -> List[MealPlanResponse]:
parsed_json = self._do_get_request("objects/meal_plan", query_filters)
return [MealPlanResponse(**data) for data in parsed_json]
if parsed_json:
return [MealPlanResponse(**data) for data in parsed_json]
return []

def get_recipe(self, object_id: int) -> RecipeDetailsResponse:
parsed_json = self._do_get_request(f"objects/recipes/{object_id}")
Expand Down Expand Up @@ -719,6 +731,7 @@ def get_meal_plan_sections(
)
if parsed_json:
return [MealPlanSectionResponse(**resp) for resp in parsed_json]
return []

def get_meal_plan_section(self, meal_plan_section_id) -> MealPlanSectionResponse:
parsed_json = self._do_get_request(
Expand All @@ -731,6 +744,7 @@ def get_users(self) -> List[UserDto]:
parsed_json = self._do_get_request("users")
if parsed_json:
return [UserDto(**user) for user in parsed_json]
return []

def get_user(self, user_id: int) -> UserDto:
query_params = []
Expand Down

0 comments on commit 721f7bc

Please sign in to comment.