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

Commit

Permalink
Merge ad0dbf7 into 465b78c
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRut committed Mar 2, 2020
2 parents 465b78c + ad0dbf7 commit cc5400f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -29,7 +29,7 @@ grocy = Grocy("https://example.com", "GROCY_API_KEY", port = 9192, verify_ssl =
Get current stock:
```python
for entry in grocy.stock():
print("{} in stock for product id {}".format(entry.product_id, entry.amount))
print("{} in stock for product id {}".format(entry.id, entry.amount))
```

## Development testing
Expand Down
25 changes: 13 additions & 12 deletions pygrocy/grocy.py
Expand Up @@ -12,14 +12,14 @@
class Product(object):
def __init__(self, response):
if isinstance(response, CurrentStockResponse):
self._product_id = response.product_id
self._id = response.product_id
self._name = None
self._available_amount = response.amount
self._best_before_date = response.best_before_date
self._amount_missing = None
self._is_partly_in_stock = None
elif isinstance(response, MissingProductResponse):
self._product_id = response.product_id
self._id = response.product_id
self._name = response.name
self._available_amount = None
self._best_before_date = None
Expand All @@ -29,7 +29,7 @@ def __init__(self, response):
self._product_group_id = None

def get_details(self, api_client: GrocyApiClient):
details = api_client.get_product(self.product_id)
details = api_client.get_product(self.id)
if details is None:
return
self._name = details.product.name
Expand All @@ -41,8 +41,8 @@ def name(self) -> str:
return self._name

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

@property
def product_group_id(self) -> int:
Expand All @@ -68,6 +68,7 @@ def amount_missing(self) -> float:
def is_partly_in_stock(self) -> int:
return self._is_partly_in_stock


class Group(object):
def __init__(self, raw_product_group: LocationData):
self._id = raw_product_group.id
Expand All @@ -86,6 +87,7 @@ def name(self) -> str:
def description(self) -> str:
return self._description


class ShoppingListProduct(object):
def __init__(self, raw_shopping_list: ShoppingListItem):
self._id = raw_shopping_list.id
Expand All @@ -107,7 +109,7 @@ def product_id(self) -> int:
return self._product_id

@property
def amount(self) -> int:
def amount(self) -> float:
return self._amount

@property
Expand All @@ -116,28 +118,27 @@ def note(self) -> str:

@property
def product(self) -> Product:
if self._product_id is None:
self.get_details()
return self._product


class Chore(object):
def __init__(self, raw_chore: CurrentChoreResponse):
self._chore_id = raw_chore.chore_id
self._id = raw_chore.chore_id
self._last_tracked_time = raw_chore.last_tracked_time
self._next_estimated_execution_time = raw_chore.next_estimated_execution_time

self._name = None
self._last_done_by = None

def get_details(self, api_client: GrocyApiClient):
details = api_client.get_chore(self.chore_id)
details = api_client.get_chore(self.id)
self._name = details.chore.name
self._last_tracked_time = details.last_tracked
self._last_done_by = details.last_done_by

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

@property
def last_tracked_time(self) -> datetime:
Expand Down
12 changes: 6 additions & 6 deletions test/test_grocy.py
Expand Up @@ -25,12 +25,12 @@ def test_get_chores_valid(self):

assert isinstance(chores, list)
assert len(chores) == 6
assert chores[0].chore_id == 1
assert chores[1].chore_id == 2
assert chores[2].chore_id == 3
assert chores[3].chore_id == 4
assert chores[4].chore_id == 5
assert chores[5].chore_id == 6
assert chores[0].id == 1
assert chores[1].id == 2
assert chores[2].id == 3
assert chores[3].id == 4
assert chores[4].id == 5
assert chores[5].id == 6

def test_product_get_details_valid(self):
stock = self.grocy.stock()
Expand Down

0 comments on commit cc5400f

Please sign in to comment.