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/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRut committed Aug 17, 2023
2 parents 6d5dae7 + ea15f80 commit 9b9bd71
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 21 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [v2.0.0](https://github.com/SebRut/pygrocy/tree/v2.0.0) (2023-08-17)

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

**Closed issues:**

- Grocy API doesn't use offset timezone info \(chore execution gets the wrong time\) [\#254](https://github.com/SebRut/pygrocy/issues/254)

**Merged pull requests:**

- Remove qu\_factor\_purchase\_to\_stock to maintain compatibility with API v4 [\#265](https://github.com/SebRut/pygrocy/pull/265) ([fedefreue](https://github.com/fedefreue))
- Convert empty value to None for qu\_factor\_purchase\_to\_stock [\#257](https://github.com/SebRut/pygrocy/pull/257) ([marcelvriend](https://github.com/marcelvriend))
- Fix tracking time for chores, tasks and batteries [\#255](https://github.com/SebRut/pygrocy/pull/255) ([marcelvriend](https://github.com/marcelvriend))

## [v1.5.0](https://github.com/SebRut/pygrocy/tree/v1.5.0) (2022-09-19)

[Full Changelog](https://github.com/SebRut/pygrocy/compare/v1.4.1...v1.5.0)
Expand All @@ -12,12 +26,15 @@

- Update pydantic requirement from \<1.10.0,\>=1.8.2 to \>=1.8.2,\<1.11.0 [\#251](https://github.com/SebRut/pygrocy/pull/251) ([dependabot[bot]](https://github.com/apps/dependabot))
- Fix tzlocal dependency causing an exception [\#250](https://github.com/SebRut/pygrocy/pull/250) ([marcelvriend](https://github.com/marcelvriend))
- Fix enabled features lookup [\#248](https://github.com/SebRut/pygrocy/pull/248) ([marcelvriend](https://github.com/marcelvriend))

## [v1.4.1](https://github.com/SebRut/pygrocy/tree/v1.4.1) (2022-07-28)

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

**Merged pull requests:**

- Fix enabled features lookup [\#248](https://github.com/SebRut/pygrocy/pull/248) ([marcelvriend](https://github.com/marcelvriend))

## [v1.4.0](https://github.com/SebRut/pygrocy/tree/v1.4.0) (2022-07-24)

[Full Changelog](https://github.com/SebRut/pygrocy/compare/v1.3.0...v1.4.0)
Expand Down
6 changes: 0 additions & 6 deletions pygrocy/data_models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def _init_empty(self):
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 Down Expand Up @@ -115,7 +114,6 @@ 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
Expand Down Expand Up @@ -184,10 +182,6 @@ def is_partly_in_stock(self) -> int:
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
1 change: 0 additions & 1 deletion pygrocy/data_models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def row_created_timestamp(self) -> datetime:

class Task(DataModel):
def __init__(self, response: TaskResponse):

self._id = response.id
self._name = response.name
self._description = response.description
Expand Down
6 changes: 3 additions & 3 deletions pygrocy/grocy.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def execute_chore(
self,
chore_id: int,
done_by: int = None,
tracked_time: datetime = datetime.now(),
tracked_time: datetime = None,
skipped: bool = False,
):
return self._api_client.execute_chore(chore_id, done_by, tracked_time, skipped)
Expand Down Expand Up @@ -326,7 +326,7 @@ def task(self, task_id: int) -> Task:
resp = self._api_client.get_task(task_id)
return Task(resp)

def complete_task(self, task_id, done_time: datetime = datetime.now()):
def complete_task(self, task_id, done_time: datetime = None):
return self._api_client.complete_task(task_id, done_time)

def meal_plan(
Expand Down Expand Up @@ -361,7 +361,7 @@ def battery(self, battery_id: int) -> Battery:
if battery:
return Battery(battery)

def charge_battery(self, battery_id: int, tracked_time: datetime = datetime.now()):
def charge_battery(self, battery_id: int, tracked_time: datetime = None):
return self._api_client.charge_battery(battery_id, tracked_time)

def add_generic(self, entity_type: EntityType, data):
Expand Down
24 changes: 16 additions & 8 deletions pygrocy/grocy_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pydantic.schema import date

from pygrocy import EntityType
from pygrocy.utils import localize_datetime, parse_date
from pygrocy.utils import grocy_datetime_str, localize_datetime, parse_date

from .errors import GrocyError

Expand Down Expand Up @@ -91,7 +91,6 @@ class ProductData(BaseModel):
product_group_id: Optional[int] = None
qu_id_stock: int
qu_id_purchase: int
qu_factor_purchase_to_stock: float
picture_file_name: Optional[str] = None
allow_partial_units_in_stock: Optional[bool] = False
row_created_timestamp: datetime
Expand Down Expand Up @@ -453,13 +452,16 @@ def execute_chore(
self,
chore_id: int,
done_by: int = None,
tracked_time: datetime = datetime.now(),
tracked_time: datetime = None,
skipped: bool = False,
):
if tracked_time is None:
tracked_time = datetime.now()

localized_tracked_time = localize_datetime(tracked_time)

data = {
"tracked_time": localized_tracked_time.isoformat(),
"tracked_time": grocy_datetime_str(localized_tracked_time),
"skipped": skipped,
}

Expand Down Expand Up @@ -733,12 +735,15 @@ def get_task(self, task_id: int) -> TaskResponse:
parsed_json = self._do_get_request(url)
return TaskResponse(**parsed_json)

def complete_task(self, task_id: int, done_time: datetime = datetime.now()):
def complete_task(self, task_id: int, done_time: datetime = None):
url = f"tasks/{task_id}/complete"

if done_time is None:
done_time = datetime.now()

localized_done_time = localize_datetime(done_time)

data = {"done_time": localized_done_time.isoformat()}
data = {"done_time": grocy_datetime_str(localized_done_time)}
self._do_post_request(url, data)

def get_meal_plan(self, query_filters: List[str] = None) -> List[MealPlanResponse]:
Expand All @@ -765,9 +770,12 @@ def get_battery(self, battery_id: int) -> BatteryDetailsResponse:
if parsed_json:
return BatteryDetailsResponse(**parsed_json)

def charge_battery(self, battery_id: int, tracked_time: datetime = datetime.now()):
def charge_battery(self, battery_id: int, tracked_time: datetime = None):
if tracked_time is None:
tracked_time = datetime.now()

localized_tracked_time = localize_datetime(tracked_time)
data = {"tracked_time": localized_tracked_time.isoformat()}
data = {"tracked_time": grocy_datetime_str(localized_tracked_time)}

return self._do_post_request(f"batteries/{battery_id}/charge", data)

Expand Down
6 changes: 6 additions & 0 deletions pygrocy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ def parse_bool_int(input_value):

def localize_datetime(timestamp: datetime) -> datetime:
return timestamp.astimezone()


def grocy_datetime_str(timestamp: datetime) -> str:
if timestamp is None:
return ""
return timestamp.strftime("%Y-%m-%d %H:%M:%S")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pygrocy",
version="1.5.0",
version="2.0.0",
author="Sebastian Rutofski",
author_email="[email protected]",
description="",
Expand Down
1 change: 0 additions & 1 deletion test/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def test_product_get_details_valid(self, grocy):
assert product.name == "Gulash soup"
assert product.available_amount == 5
assert product.product_group_id == 3
assert product.qu_factor_purchase_to_stock == 1.0
assert product.default_quantity_unit_purchase.id == 5
assert product.default_quantity_unit_purchase.name == "Tin"
assert product.default_quantity_unit_purchase.description is None
Expand Down
6 changes: 6 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ def test_localize_datetime_input_timezone_aware(self):
633809,
tzinfo=zoneinfo.ZoneInfo("America/Los_Angeles"),
)

def test_grocy_datetime_str(self):
date = datetime(2022, 7, 10, 21, 17, 34, 633809, tzinfo=None)
date_str = utils.grocy_datetime_str(date)

assert date_str == "2022-07-10 21:17:34"

0 comments on commit 9b9bd71

Please sign in to comment.