From 9ed4c6c20abf0b9d7fe06356b64279ce14fb26de Mon Sep 17 00:00:00 2001 From: Sebastian Rutofski Date: Sat, 15 Aug 2020 18:47:09 +0200 Subject: [PATCH 1/3] Use Product instead of ProductData --- pygrocy/grocy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygrocy/grocy.py b/pygrocy/grocy.py index d7b7090..4543d0b 100644 --- a/pygrocy/grocy.py +++ b/pygrocy/grocy.py @@ -128,7 +128,7 @@ def __init__(self, raw_shopping_list: ShoppingListItem): def get_details(self, api_client: GrocyApiClient): if self._product_id: - self._product = api_client.get_product(self._product_id).product + self._product = Product(api_client.get_product(self._product_id)) @property def id(self) -> int: From b02dc4ac654d9b6404b91eb99c372e0ca46e879a Mon Sep 17 00:00:00 2001 From: Sebastian Rutofski Date: Sun, 16 Aug 2020 09:26:00 +0200 Subject: [PATCH 2/3] only localize datetimes not already containing tz info (#118) Signed-off-by: Sebastian Rutofski --- pygrocy/grocy_api_client.py | 16 ++++------------ pygrocy/utils.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pygrocy/grocy_api_client.py b/pygrocy/grocy_api_client.py index 4ffe858..5201489 100644 --- a/pygrocy/grocy_api_client.py +++ b/pygrocy/grocy_api_client.py @@ -1,15 +1,12 @@ import base64 import json -import os from datetime import datetime from enum import Enum from typing import List from urllib.parse import urljoin -import pytz import requests -from pygrocy.utils import parse_date, parse_float, parse_int -from tzlocal import get_localzone +from pygrocy.utils import parse_date, parse_float, parse_int, localize_datetime DEFAULT_PORT_NUMBER = 9192 @@ -540,10 +537,7 @@ def execute_chore( done_by: int = None, tracked_time: datetime = datetime.now(), ): - # Grocy API expects UTC time; time returned from datetime.now() is local time without timezone - # information, so timezone information must be attached. - local_tz = get_localzone() - localized_tracked_time = local_tz.localize(tracked_time) + localized_tracked_time = localize_datetime(tracked_time) data = {"tracked_time": localized_tracked_time.isoformat()} @@ -656,10 +650,8 @@ def get_tasks(self) -> List[TaskResponse]: def complete_task(self, task_id: int, done_time: datetime = datetime.now()): url = f"tasks/{task_id}/complete" - # Grocy API expects UTC time; time returned from datetime.now() is local time without timezone - # information, so timezone information must be attached. - local_tz = get_localzone() - localized_done_time = local_tz.localize(done_time) + + localized_done_time = localize_datetime(done_time) data = {"done_time": localized_done_time.isoformat()} self._do_post_request(url, data) diff --git a/pygrocy/utils.py b/pygrocy/utils.py index f81826b..02fa408 100644 --- a/pygrocy/utils.py +++ b/pygrocy/utils.py @@ -1,4 +1,7 @@ import iso8601 +import pytz +from tzlocal import get_localzone +from datetime import datetime def parse_date(input_value): @@ -23,3 +26,11 @@ def parse_float(input_value, default_value=None): return float(input_value) except ValueError: return default_value + + +def localize_datetime(timestamp: datetime) -> datetime: + if timestamp.tzinfo is not None: + return timestamp + + local_tz = get_localzone() + return local_tz.localize(timestamp).astimezone(pytz.utc) From d4815b58cd0bb6b747fe0aee087bcb4fa747b1bc Mon Sep 17 00:00:00 2001 From: Sebastian Rutofski Date: Sun, 16 Aug 2020 09:27:40 +0200 Subject: [PATCH 3/3] v0.20.0 prep Signed-off-by: Sebastian Rutofski --- CHANGELOG.md | 13 +++++++++++++ setup.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43e300b..69c608f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [v0.20.0](https://github.com/SebRut/pygrocy/tree/v0.20.0) (2020-08-16) + +[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.19.0...v0.20.0) + +**Closed issues:** + +- Use Product instead of ProductDate in ShoppingListProduct [\#116](https://github.com/SebRut/pygrocy/issues/116) + +**Merged pull requests:** + +- only localize datetimes not already containing tz info [\#118](https://github.com/SebRut/pygrocy/pull/118) ([SebRut](https://github.com/SebRut)) +- Use Product instead of ProductData [\#117](https://github.com/SebRut/pygrocy/pull/117) ([SebRut](https://github.com/SebRut)) + ## [v0.19.0](https://github.com/SebRut/pygrocy/tree/v0.19.0) (2020-08-14) [Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.18.0...v0.19.0) diff --git a/setup.py b/setup.py index fe49a23..c9712e1 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pygrocy", - version="0.19.0", + version="0.20.0", author="Sebastian Rutofski", author_email="kontakt@sebastian-rutofski.de", description="",