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.20.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRut committed Aug 16, 2020
2 parents 67c0a44 + d4815b5 commit cbefdbf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pygrocy/grocy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 4 additions & 12 deletions pygrocy/grocy_api_client.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()}

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions pygrocy/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import iso8601
import pytz
from tzlocal import get_localzone
from datetime import datetime


def parse_date(input_value):
Expand All @@ -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)
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="0.19.0",
version="0.20.0",
author="Sebastian Rutofski",
author_email="[email protected]",
description="",
Expand Down

0 comments on commit cbefdbf

Please sign in to comment.