This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
2,931 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from datetime import datetime | ||
|
||
from pygrocy.base import DataModel | ||
from pygrocy.grocy_api_client import BatteryDetailsResponse, CurrentBatteryResponse | ||
|
||
|
||
class Battery(DataModel): | ||
def __init__(self, response): | ||
self._init_empty() | ||
|
||
self._next_estimated_charge_time = response.next_estimated_charge_time | ||
|
||
if isinstance(response, CurrentBatteryResponse): | ||
self._init_from_CurrentBatteryResponse(response) | ||
elif isinstance(response, BatteryDetailsResponse): | ||
self._init_from_BatteryDetailsResponse(response) | ||
|
||
def _init_from_CurrentBatteryResponse(self, response: CurrentBatteryResponse): | ||
self._id = response.id | ||
self._last_tracked_time = response.last_tracked_time | ||
|
||
def _init_from_BatteryDetailsResponse(self, response: BatteryDetailsResponse): | ||
self._charge_cycles_count = response.charge_cycles_count | ||
self._last_charged = response.last_charged | ||
self._id = response.battery.id | ||
self._name = response.battery.name | ||
self._description = response.battery.description | ||
self._used_in = response.battery.used_in | ||
self._charge_interval_days = response.battery.charge_interval_days | ||
self._created_timestamp = response.battery.created_timestamp | ||
self._userfields = response.battery.userfields | ||
|
||
def _init_empty(self): | ||
self._last_tracked_time = None | ||
self._charge_cycles_count = None | ||
self._last_charged = None | ||
self._name = None | ||
self._description = None | ||
self._used_in = None | ||
self._charge_interval_days = None | ||
self._created_timestamp = None | ||
self._userfields = None | ||
|
||
@property | ||
def id(self) -> int: | ||
return self._id | ||
|
||
@property | ||
def name(self) -> str: | ||
return self._name | ||
|
||
@property | ||
def description(self) -> str: | ||
return self._description | ||
|
||
@property | ||
def used_in(self) -> str: | ||
return self._used_in | ||
|
||
@property | ||
def charge_interval_days(self) -> int: | ||
return self._charge_interval_days | ||
|
||
@property | ||
def created_timestamp(self) -> datetime: | ||
return self._created_timestamp | ||
|
||
@property | ||
def charge_cycles_count(self) -> int: | ||
return self._charge_cycles_count | ||
|
||
@property | ||
def userfields(self): | ||
return self._userfields | ||
|
||
@property | ||
def last_charged(self) -> datetime: | ||
return self._last_charged | ||
|
||
@property | ||
def last_tracked_time(self) -> datetime: | ||
return self._last_tracked_time | ||
|
||
@property | ||
def next_estimated_charge_time(self) -> datetime: | ||
return self._next_estimated_charge_time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,7 @@ iso8601~=0.1.14 | |
pre-commit | ||
isort | ||
pytest | ||
pytest-cov | ||
pytest-cov | ||
vcrpy | ||
pytest-recording | ||
pytest-mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name="pygrocy", | ||
version="0.25.0", | ||
version="0.26.0", | ||
author="Sebastian Rutofski", | ||
author_email="[email protected]", | ||
description="", | ||
|
49 changes: 49 additions & 0 deletions
49
test/cassettes/test_battery/TestBattery.test_charge_battery.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
interactions: | ||
- request: | ||
body: '{"tracked_time": "2021-02-13T21:43:24.942943+00:00"}' | ||
headers: | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '52' | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- python-requests/2.25.1 | ||
accept: | ||
- application/json | ||
method: POST | ||
uri: https://localhost/api/batteries/1/charge | ||
response: | ||
body: | ||
string: !!binary | | ||
H4sIAAAAAAAEA3WMQQqAIBBFrxKzTnCm2ngZsXQhlYWNRER3z7Jty/9475/gLShAhBp6w+zioQvJ | ||
gKMZRmc1+9lliSShkCSwqQhV2yjqshSXXQ/RGf7Ejc28/top2CU8ZzKnZbz3XxXSNF03xQBpFpQA | ||
AAA= | ||
headers: | ||
Access-Control-Allow-Headers: | ||
- '*' | ||
Access-Control-Allow-Methods: | ||
- GET, POST, PUT, DELETE, OPTIONS | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Connection: | ||
- keep-alive | ||
Content-Encoding: | ||
- gzip | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Sat, 13 Feb 2021 21:43:25 GMT | ||
Server: | ||
- nginx/1.18.0 | ||
Transfer-Encoding: | ||
- chunked | ||
X-Powered-By: | ||
- PHP/7.4.14 | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
Oops, something went wrong.