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.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRut committed Mar 5, 2022
2 parents 30b9c74 + 3e817a8 commit e457647
Show file tree
Hide file tree
Showing 22 changed files with 1,377 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ addons:
sources:
- sourceline: 'ppa:deadsnakes/ppa'
packages:
- python3.6
- python3.8
- python3.9
- python3.10
- python3-pip
- python3-setuptools
- python3-wheel
Expand Down
53 changes: 42 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,55 @@
# Changelog

## [v1.1.0](https://github.com/SebRut/pygrocy/tree/v1.1.0) (2022-03-05)

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

**Implemented enhancements:**

- Feature: Edit Stock [\#201](https://github.com/SebRut/pygrocy/issues/201)
- Add path in request when creating base url [\#121](https://github.com/SebRut/pygrocy/issues/121)
- Get product by Barcode [\#85](https://github.com/SebRut/pygrocy/issues/85)

**Fixed bugs:**

- min\_stock\_amount should be float, not int [\#217](https://github.com/SebRut/pygrocy/issues/217)

**Closed issues:**

- execute\_chore is formatting time in UTC time. grocy server ignores the timezone, so it shifts the date of chore execution [\#222](https://github.com/SebRut/pygrocy/issues/222)
- Update Product Userfields [\#196](https://github.com/SebRut/pygrocy/issues/196)

**Merged pull requests:**

- update python [\#219](https://github.com/SebRut/pygrocy/pull/219) ([SebRut](https://github.com/SebRut))
- Optional float [\#218](https://github.com/SebRut/pygrocy/pull/218) ([harshi1122](https://github.com/harshi1122))
- Update responses requirement from ~=0.14.0 to ~=0.18.0 [\#216](https://github.com/SebRut/pygrocy/pull/216) ([dependabot[bot]](https://github.com/apps/dependabot))
- Added support for product quantities [\#214](https://github.com/SebRut/pygrocy/pull/214) ([andreheuer](https://github.com/andreheuer))
- Update pydantic requirement from ~=1.8.2 to \>=1.8.2,\<1.10.0 [\#212](https://github.com/SebRut/pygrocy/pull/212) ([dependabot[bot]](https://github.com/apps/dependabot))
- Feature/edit stock [\#209](https://github.com/SebRut/pygrocy/pull/209) ([georgegebbett](https://github.com/georgegebbett))
- Product by barcode [\#208](https://github.com/SebRut/pygrocy/pull/208) ([georgegebbett](https://github.com/georgegebbett))
- Update iso8601 requirement from ~=0.1.16 to \>=0.1.16,\<1.1.0 [\#202](https://github.com/SebRut/pygrocy/pull/202) ([dependabot[bot]](https://github.com/apps/dependabot))
- Update tzlocal requirement from \<3.0,\>=2.1 to \>=2.1,\<5.0 [\#198](https://github.com/SebRut/pygrocy/pull/198) ([dependabot[bot]](https://github.com/apps/dependabot))
- ProductDetailsResponse last\_used Type Date instead of Datetime [\#194](https://github.com/SebRut/pygrocy/pull/194) ([sebiecker](https://github.com/sebiecker))
- support path for url [\#193](https://github.com/SebRut/pygrocy/pull/193) ([SebRut](https://github.com/SebRut))
- Update responses requirement from ~=0.13.4 to ~=0.14.0 [\#191](https://github.com/SebRut/pygrocy/pull/191) ([dependabot[bot]](https://github.com/apps/dependabot))

## [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)
- Done time should be optional, as it is for execute\_chore call [\#176](https://github.com/SebRut/pygrocy/issues/176)
- Add support for meal plan sections in grocy v3.1.0 [\#172](https://github.com/SebRut/pygrocy/issues/172)
- Add debug mode [\#167](https://github.com/SebRut/pygrocy/issues/167)
- Missing generic put and get option [\#155](https://github.com/SebRut/pygrocy/issues/155)
- add "get all products" method [\#97](https://github.com/SebRut/pygrocy/issues/97)

**Fixed bugs:**

- Sending no time when tracking chore gives an error [\#175](https://github.com/SebRut/pygrocy/issues/175)

**Closed issues:**

Expand All @@ -27,14 +69,8 @@

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

**Implemented enhancements:**

- Done time should be optional, as it is for execute\_chore call [\#176](https://github.com/SebRut/pygrocy/issues/176)
- Add debug mode [\#167](https://github.com/SebRut/pygrocy/issues/167)

**Fixed bugs:**

- Sending no time when tracking chore gives an error [\#175](https://github.com/SebRut/pygrocy/issues/175)
- Lovelace not accessible [\#158](https://github.com/SebRut/pygrocy/issues/158)

**Closed issues:**
Expand Down Expand Up @@ -63,11 +99,6 @@

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

**Implemented enhancements:**

- Missing generic put and get option [\#155](https://github.com/SebRut/pygrocy/issues/155)
- add "get all products" method [\#97](https://github.com/SebRut/pygrocy/issues/97)

**Closed issues:**

- 404 errors and unresponsive sensors after configuring integration in HA [\#154](https://github.com/SebRut/pygrocy/issues/154)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pygrocy
[![Development Build Status](https://api.travis-ci.com/SebRut/pygrocy.svg?branch=develop)](https://travis-ci.com/SebRut/pygrocy)
[![PyPI](https://img.shields.io/pypi/v/pygrocy.svg)](https://pypi.org/project/pygrocy/)
![Python Version](https://img.shields.io/badge/python-3.6%20%7C%203.8%20%7C%203.9-blue)
![Python Version](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue)
![Grocy Version](https://img.shields.io/badge/grocy-3.1.0-yellow)
[![Coverage Status](https://coveralls.io/repos/github/SebRut/pygrocy/badge.svg?branch=master)](https://coveralls.io/github/SebRut/pygrocy?branch=master)
[![CodeFactor](https://www.codefactor.io/repository/github/sebrut/pygrocy/badge)](https://www.codefactor.io/repository/github/sebrut/pygrocy)
Expand Down
47 changes: 47 additions & 0 deletions pygrocy/data_models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
ProductBarcodeData,
ProductData,
ProductDetailsResponse,
QuantityUnitData,
ShoppingListItem,
StockLogResponse,
)


Expand All @@ -23,6 +25,30 @@ def barcode(self) -> str:
return self._barcode


class QuantityUnit(DataModel):
def __init__(self, data: QuantityUnitData):
self._id = data.id
self._name = data.name
self._name_plural = data.name_plural
self._description = data.description

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

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

@property
def name_plural(self) -> str:
return self._name_plural

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


class Product(DataModel):
def __init__(self, data):
self._init_empty()
Expand All @@ -34,6 +60,8 @@ def __init__(self, data):
self._init_from_ProductDetailsResponse(data)
elif isinstance(data, ProductData):
self._init_from_ProductData(data)
elif isinstance(data, StockLogResponse):
self._init_from_StockLogResponse(data)

def _init_empty(self):
self._name = None
Expand All @@ -44,6 +72,9 @@ def _init_empty(self):
self._available_amount = None
self._best_before_date = None

self._default_quantity_unit_purchase = None
self._qu_factor_purchase_to_stock = None

self._barcodes = []
self._product_group_id = None

Expand All @@ -65,6 +96,9 @@ def _init_from_ProductDetailsResponse(self, response: ProductDetailsResponse):
self._available_amount = response.stock_amount
self._best_before_date = response.next_best_before_date
self._barcodes = [ProductBarcode(data) for data in response.barcodes]
self._default_quantity_unit_purchase = QuantityUnit(
response.default_quantity_unit_purchase
)

if response.product:
self._init_from_ProductData(response.product)
Expand All @@ -73,13 +107,18 @@ def _init_from_ProductData(self, product: ProductData):
self._id = product.id
self._product_group_id = product.product_group_id
self._name = product.name
self._qu_factor_purchase_to_stock = product.qu_factor_purchase_to_stock

def _init_from_StockLogResponse(self, response: StockLogResponse):
self._id = response.product_id

def get_details(self, api_client: GrocyApiClient):
details = api_client.get_product(self.id)
if details:
self._name = details.product.name
self._barcodes = [ProductBarcode(barcode) for barcode in details.barcodes]
self._product_group_id = details.product.product_group_id
self._available_amount = details.stock_amount

@property
def name(self) -> str:
Expand Down Expand Up @@ -117,6 +156,14 @@ def amount_missing(self) -> float:
def is_partly_in_stock(self) -> int:
return self._is_partly_in_stock

@property
def default_quantity_unit_purchase(self) -> QuantityUnit:
return self._default_quantity_unit_purchase

@property
def qu_factor_purchase_to_stock(self) -> float:
return self._qu_factor_purchase_to_stock


class Group(DataModel):
def __init__(self, raw_product_group: LocationData):
Expand Down
95 changes: 92 additions & 3 deletions pygrocy/grocy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ def __init__(
base_url,
api_key,
port: int = DEFAULT_PORT_NUMBER,
path: str = None,
verify_ssl=True,
debug=False,
):
self._api_client = GrocyApiClient(base_url, api_key, port, verify_ssl, debug)
self._api_client = GrocyApiClient(
base_url, api_key, port, path, verify_ssl, debug
)

if debug:
_LOGGER.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -94,6 +97,11 @@ def product(self, product_id: int) -> Product:
if resp:
return Product(resp)

def product_by_barcode(self, barcode: str) -> Product:
resp = self._api_client.get_product_by_barcode(barcode)
if resp:
return Product(resp)

def all_products(self) -> List[Product]:
raw_products = self.get_generic_objects_for_type(EntityType.PRODUCTS)
from pygrocy.grocy_api_client import ProductData
Expand Down Expand Up @@ -145,6 +153,83 @@ def consume_product(
product_id, amount, spoiled, transaction_type
)

def inventory_product(
self,
product_id: int,
new_amount: int,
best_before_date: datetime = None,
shopping_location_id: int = None,
location_id: int = None,
price: int = None,
get_details: bool = True,
) -> Product:
product = Product(
self._api_client.inventory_product(
product_id,
new_amount,
best_before_date,
shopping_location_id,
location_id,
price,
)
)

if get_details:
product.get_details(self._api_client)
return product

def add_product_by_barcode(
self,
barcode: str,
amount: float,
price: float,
best_before_date: datetime = None,
get_details: bool = True,
) -> Product:
product = Product(
self._api_client.add_product_by_barcode(
barcode, amount, price, best_before_date
)
)

if get_details:
product.get_details(self._api_client)
return product

def consume_product_by_barcode(
self,
barcode: str,
amount: float = 1,
spoiled: bool = False,
get_details: bool = True,
) -> Product:
product = Product(
self._api_client.consume_product_by_barcode(barcode, amount, spoiled)
)

if get_details:
product.get_details(self._api_client)
return product

def inventory_product_by_barcode(
self,
barcode: str,
new_amount: int,
best_before_date: datetime = None,
location_id: int = None,
price: int = None,
get_details: bool = True,
) -> Product:
product = Product(
self._api_client.inventory_product_by_barcode(
barcode, new_amount, best_before_date, location_id, price
)
)

if get_details:
product.get_details(self._api_client)
return product

def shopping_list(self, get_details: bool = False) -> List[ShoppingListProduct]:
raw_shoppinglist = self._api_client.get_shopping_list()
shopping_list = [ShoppingListProduct(resp) for resp in raw_shoppinglist]
Expand All @@ -158,10 +243,14 @@ 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
self,
product_id: int,
shopping_list_id: int = None,
amount: int = None,
quantity_unit_id: int = None,
):
return self._api_client.add_product_to_shopping_list(
product_id, shopping_list_id, amount
product_id, shopping_list_id, amount, quantity_unit_id
)

def clear_shopping_list(self, shopping_list_id: int = 1):
Expand Down
Loading

0 comments on commit e457647

Please sign in to comment.