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/0.17.0'
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Rutofski <[email protected]>
  • Loading branch information
SebRut committed Aug 14, 2020
2 parents ccf5284 + 28fe2fb commit 8c4f741
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 117 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = E501
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
language_version: python3.8
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [v0.17.0](https://github.com/SebRut/pygrocy/tree/v0.17.0) (2020-08-14)

[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.16.0...v0.17.0)

**Closed issues:**

- Misnaming in enum [\#112](https://github.com/SebRut/pygrocy/issues/112)

**Merged pull requests:**

- fix issue \#112 [\#113](https://github.com/SebRut/pygrocy/pull/113) ([SebRut](https://github.com/SebRut))

## [v0.16.0](https://github.com/SebRut/pygrocy/tree/v0.16.0) (2020-08-13)

[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.15.0...v0.16.0)
Expand All @@ -16,7 +28,10 @@
- Update coveralls requirement from ~=2.0.0 to ~=2.1.1 [\#104](https://github.com/SebRut/pygrocy/pull/104) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Update pdoc3 requirement from ~=0.8.1 to ~=0.8.3 [\#102](https://github.com/SebRut/pygrocy/pull/102) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
- Update responses requirement from ~=0.10.14 to ~=0.10.15 [\#101](https://github.com/SebRut/pygrocy/pull/101) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
<<<<<<< HEAD
- add all fields from chore details api call [\#98](https://github.com/SebRut/pygrocy/pull/98) ([SebRut](https://github.com/SebRut))
=======
>>>>>>> release/0.17.0
## [v0.15.0](https://github.com/SebRut/pygrocy/tree/v0.15.0) (2020-05-25)

Expand Down
126 changes: 85 additions & 41 deletions pygrocy/grocy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
from typing import List, Dict

from .base import DataModel
from .grocy_api_client import (DEFAULT_PORT_NUMBER, ChoreDetailsResponse,
CurrentChoreResponse, CurrentStockResponse,
GrocyApiClient,
LocationData, MissingProductResponse,
ProductDetailsResponse,
MealPlanResponse,
RecipeDetailsResponse,
ShoppingListItem, TransactionType, UserDto, TaskResponse)
from .grocy_api_client import (
DEFAULT_PORT_NUMBER,
ChoreDetailsResponse,
CurrentChoreResponse,
CurrentStockResponse,
GrocyApiClient,
LocationData,
MissingProductResponse,
ProductDetailsResponse,
MealPlanResponse,
RecipeDetailsResponse,
ShoppingListItem,
TransactionType,
UserDto,
TaskResponse,
)


class Product(DataModel):
Expand Down Expand Up @@ -172,20 +180,22 @@ def display_name(self) -> str:
return self._display_name


class Chore(DataModel):
class PeriodType(str, Enum):
MANUALLY = 'manually'
DYNAMIC_REGULAR = 'dynamic-regular'
DAILY = 'daily'
WEEKLY = 'weekly'
MONTHLY = 'monthly'

class AssignmentType(str, Enum):
NO_ASSIGNMENT = 'no-assignment'
WHO_DID_LEAST_DID_FIRST = 'who-did-least-did-first'
RANDOM = 'random'
IN_ALPHABETICAL_ORDER = 'in-alphabetical-order'
class PeriodType(str, Enum):
MANUALLY = "manually"
DYNAMIC_REGULAR = "dynamic-regular"
DAILY = "daily"
WEEKLY = "weekly"
MONTHLY = "monthly"


class AssignmentType(str, Enum):
NO_ASSIGNMENT = "no-assignment"
WHO_LEAST_DID_FIRST = "who-least-did-first"
RANDOM = "random"
IN_ALPHABETICAL_ORDER = "in-alphabetical-order"


class Chore(DataModel):
def __init__(self, response):
if isinstance(response, CurrentChoreResponse):
self._init_from_CurrentChoreResponse(response)
Expand All @@ -208,7 +218,7 @@ def _init_from_ChoreDetailsResponse(self, response: ChoreDetailsResponse):
self._description = chore_data.description

if chore_data.period_type is not None:
self._period_type = Chore.PeriodType(chore_data.period_type)
self._period_type = PeriodType(chore_data.period_type)
else:
self._period_type = None

Expand All @@ -218,12 +228,14 @@ def _init_from_ChoreDetailsResponse(self, response: ChoreDetailsResponse):
self._rollover = chore_data.rollover

if chore_data.assignment_type is not None:
self._assignment_type = Chore.AssignmentType(chore_data.assignment_type)
self._assignment_type = AssignmentType(chore_data.assignment_type)
else:
self._assignment_type = None

self._assignment_config = chore_data.assignment_config
self._next_execution_assigned_to_user_id = chore_data.next_execution_assigned_to_user_id
self._next_execution_assigned_to_user_id = (
chore_data.next_execution_assigned_to_user_id
)
self._userfields = chore_data.userfields

self._last_tracked_time = response.last_tracked
Expand All @@ -234,7 +246,9 @@ def _init_from_ChoreDetailsResponse(self, response: ChoreDetailsResponse):
self._last_done_by = None
self._track_count = response.track_count
if response.next_execution_assigned_user is not None:
self._next_execution_assigned_user = User(response.next_execution_assigned_user)
self._next_execution_assigned_user = User(
response.next_execution_assigned_user
)
else:
self._next_execution_assigned_user = None

Expand Down Expand Up @@ -285,9 +299,9 @@ def assignment_config(self) -> str:
@property
def next_execution_assigned_to_user_id(self) -> int:
return self._next_execution_assigned_to_user_id

@property
def userfields(self) -> Dict[str,str]:
def userfields(self) -> Dict[str, str]:
return self._userfields

@property
Expand Down Expand Up @@ -367,7 +381,7 @@ def picture_file_name(self) -> str:

def get_picture_url_path(self, width: int = 400):
if self.picture_file_name:
b64name = base64.b64encode(self.picture_file_name.encode('ascii'))
b64name = base64.b64encode(self.picture_file_name.encode("ascii"))
path = "files/recipepictures/" + str(b64name, "utf-8")

return f"{path}?force_serve_as=picture&best_fit_width={width}"
Expand Down Expand Up @@ -412,7 +426,9 @@ def get_details(self, api_client: GrocyApiClient):


class Grocy(object):
def __init__(self, base_url, api_key, port: int = DEFAULT_PORT_NUMBER, verify_ssl=True):
def __init__(
self, base_url, api_key, port: int = DEFAULT_PORT_NUMBER, verify_ssl=True
):
self._api_client = GrocyApiClient(base_url, api_key, port, verify_ssl)

def stock(self) -> List[Product]:
Expand Down Expand Up @@ -461,20 +477,40 @@ def chores(self, get_details: bool = False) -> List[Chore]:
chore.get_details(self._api_client)
return chores

def execute_chore(self, chore_id: int, done_by: int = None, tracked_time: datetime = datetime.now()):
def execute_chore(
self,
chore_id: int,
done_by: int = None,
tracked_time: datetime = datetime.now(),
):
return self._api_client.execute_chore(chore_id, done_by, tracked_time)

def chore(self, chore_id: int) -> Chore:
resp = self._api_client.get_chore(chore_id)
return Chore(resp)

def add_product(self, product_id, amount: float, price: float, best_before_date: datetime = None,
transaction_type: TransactionType = TransactionType.PURCHASE):
return self._api_client.add_product(product_id, amount, price, best_before_date, transaction_type)

def consume_product(self, product_id: int, amount: float = 1, spoiled: bool = False,
transaction_type: TransactionType = TransactionType.CONSUME):
return self._api_client.consume_product(product_id, amount, spoiled, transaction_type)
def add_product(
self,
product_id,
amount: float,
price: float,
best_before_date: datetime = None,
transaction_type: TransactionType = TransactionType.PURCHASE,
):
return self._api_client.add_product(
product_id, amount, price, best_before_date, transaction_type
)

def consume_product(
self,
product_id: int,
amount: float = 1,
spoiled: bool = False,
transaction_type: TransactionType = TransactionType.CONSUME,
):
return self._api_client.consume_product(
product_id, amount, spoiled, transaction_type
)

def shopping_list(self, get_details: bool = False) -> List[ShoppingListProduct]:
raw_shoppinglist = self._api_client.get_shopping_list()
Expand All @@ -488,14 +524,22 @@ def shopping_list(self, get_details: bool = False) -> List[ShoppingListProduct]:
def add_missing_product_to_shopping_list(self, shopping_list_id: int = 1):
return self._api_client.add_missing_product_to_shopping_list(shopping_list_id)

def add_product_to_shopping_list(self, product_id: int, shopping_list_id: int = None, amount: int = None):
return self._api_client.add_product_to_shopping_list(product_id, shopping_list_id, amount)
def add_product_to_shopping_list(
self, product_id: int, shopping_list_id: int = None, amount: int = None
):
return self._api_client.add_product_to_shopping_list(
product_id, shopping_list_id, amount
)

def clear_shopping_list(self, shopping_list_id: int = 1):
return self._api_client.clear_shopping_list(shopping_list_id)

def remove_product_in_shopping_list(self, product_id: int, shopping_list_id: int = 1, amount: int = 1):
return self._api_client.remove_product_in_shopping_list(product_id, shopping_list_id, amount)
def remove_product_in_shopping_list(
self, product_id: int, shopping_list_id: int = 1, amount: int = 1
):
return self._api_client.remove_product_in_shopping_list(
product_id, shopping_list_id, amount
)

def product_groups(self) -> List[Group]:
raw_groups = self._api_client.get_product_groups()
Expand Down
11 changes: 3 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@

setuptools.setup(
name="pygrocy",
version="0.16.0",
version="0.17.0",
author="Sebastian Rutofski",
author_email="[email protected]",
description="",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/sebrut/pygrocy",
license='MIT',
license="MIT",
packages=setuptools.find_packages(),
install_requires=[
"requests",
"iso8601",
"pytz",
"tzlocal"
],
install_requires=["requests", "iso8601", "pytz", "tzlocal"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
Loading

0 comments on commit 8c4f741

Please sign in to comment.