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

Commit cbefdbf

Browse files
committed
Merge branch 'release/0.20.0'
2 parents 67c0a44 + d4815b5 commit cbefdbf

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## [v0.20.0](https://github.com/SebRut/pygrocy/tree/v0.20.0) (2020-08-16)
4+
5+
[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.19.0...v0.20.0)
6+
7+
**Closed issues:**
8+
9+
- Use Product instead of ProductDate in ShoppingListProduct [\#116](https://github.com/SebRut/pygrocy/issues/116)
10+
11+
**Merged pull requests:**
12+
13+
- only localize datetimes not already containing tz info [\#118](https://github.com/SebRut/pygrocy/pull/118) ([SebRut](https://github.com/SebRut))
14+
- Use Product instead of ProductData [\#117](https://github.com/SebRut/pygrocy/pull/117) ([SebRut](https://github.com/SebRut))
15+
316
## [v0.19.0](https://github.com/SebRut/pygrocy/tree/v0.19.0) (2020-08-14)
417

518
[Full Changelog](https://github.com/SebRut/pygrocy/compare/v0.18.0...v0.19.0)

pygrocy/grocy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __init__(self, raw_shopping_list: ShoppingListItem):
128128

129129
def get_details(self, api_client: GrocyApiClient):
130130
if self._product_id:
131-
self._product = api_client.get_product(self._product_id).product
131+
self._product = Product(api_client.get_product(self._product_id))
132132

133133
@property
134134
def id(self) -> int:

pygrocy/grocy_api_client.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import base64
22
import json
3-
import os
43
from datetime import datetime
54
from enum import Enum
65
from typing import List
76
from urllib.parse import urljoin
87

9-
import pytz
108
import requests
11-
from pygrocy.utils import parse_date, parse_float, parse_int
12-
from tzlocal import get_localzone
9+
from pygrocy.utils import parse_date, parse_float, parse_int, localize_datetime
1310

1411
DEFAULT_PORT_NUMBER = 9192
1512

@@ -540,10 +537,7 @@ def execute_chore(
540537
done_by: int = None,
541538
tracked_time: datetime = datetime.now(),
542539
):
543-
# Grocy API expects UTC time; time returned from datetime.now() is local time without timezone
544-
# information, so timezone information must be attached.
545-
local_tz = get_localzone()
546-
localized_tracked_time = local_tz.localize(tracked_time)
540+
localized_tracked_time = localize_datetime(tracked_time)
547541

548542
data = {"tracked_time": localized_tracked_time.isoformat()}
549543

@@ -656,10 +650,8 @@ def get_tasks(self) -> List[TaskResponse]:
656650

657651
def complete_task(self, task_id: int, done_time: datetime = datetime.now()):
658652
url = f"tasks/{task_id}/complete"
659-
# Grocy API expects UTC time; time returned from datetime.now() is local time without timezone
660-
# information, so timezone information must be attached.
661-
local_tz = get_localzone()
662-
localized_done_time = local_tz.localize(done_time)
653+
654+
localized_done_time = localize_datetime(done_time)
663655

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

pygrocy/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import iso8601
2+
import pytz
3+
from tzlocal import get_localzone
4+
from datetime import datetime
25

36

47
def parse_date(input_value):
@@ -23,3 +26,11 @@ def parse_float(input_value, default_value=None):
2326
return float(input_value)
2427
except ValueError:
2528
return default_value
29+
30+
31+
def localize_datetime(timestamp: datetime) -> datetime:
32+
if timestamp.tzinfo is not None:
33+
return timestamp
34+
35+
local_tz = get_localzone()
36+
return local_tz.localize(timestamp).astimezone(pytz.utc)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pygrocy",
8-
version="0.19.0",
8+
version="0.20.0",
99
author="Sebastian Rutofski",
1010
author_email="[email protected]",
1111
description="",

0 commit comments

Comments
 (0)