Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into dependabot/pip/pytest-asyncio-gte-0.18.3-and…
Browse files Browse the repository at this point in the history
…-lt-0.21.0
  • Loading branch information
mjmeli authored Jan 6, 2023
2 parents a977609 + 1b63c88 commit a6ed292
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Auto approve

on: pull_request_target

jobs:
auto-approve:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.actor == 'dependabot[bot]' || github.actor == 'mjmeli'
steps:
- uses: hmarr/auto-approve-action@v3
with:
review-message: "Auto approved automated PR"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ If you want to run the examples, you will need to install extra dependencies.

```bash
pip install .[example]
python example.py
python examples/example_rest.py
```

## Development
Expand Down Expand Up @@ -150,7 +150,7 @@ If you want to debug requests via the Android app, the following general approac
[maintenance-shield]: https://img.shields.io/badge/maintainer-%40mjmeli-blue.svg?style=for-the-badge
[pypi-shield]: https://img.shields.io/pypi/v/pyduke-energy?style=for-the-badge
[pypi]: https://pypi.org/project/pyduke-energy/
[build-shield]: https://img.shields.io/github/workflow/status/mjmeli/pyduke-energy/Tests?style=for-the-badge
[build-shield]: https://img.shields.io/github/actions/workflow/status/mjmeli/pyduke-energy/tests.yml?branch=main&style=for-the-badge
[build]: https://github.com/mjmeli/pyduke-energy/actions/workflows/tests.yaml
[language-shield]: https://img.shields.io/github/languages/top/mjmeli/pyduke-energy?style=for-the-badge
[language]: https://github.com/mjmeli/ha-duke-energy-gateway/search?l=python
Expand Down
1 change: 1 addition & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rm -rf dist
pip install -e .[release]
python3 -m build
python3 -m twine upload dist/*
12 changes: 7 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pyduke-energy
version = 1.0.2
version = 1.0.3
author = Michael Meli
author_email = [email protected]
description = Python Wrapper for unofficial Duke Energy REST API
Expand Down Expand Up @@ -31,15 +31,17 @@ example =
kafka-python
test =
tox
pytest~=7.1.1
pytest>=7.1.1,<7.3.0
pytest-asyncio>=0.18.3,<0.21.0
pytest-cov~=3.0.0
pytest-cov>=3.0,<4.1
pytest-timeout~=2.1.0
black==22.8.0
black==22.12.0
flake8==5.0.4
pylint==2.15.0
pylint==2.15.9
pydocstyle==6.1.1
isort~=5.10.1
release =
twine

[options.packages.find]
where = src
9 changes: 8 additions & 1 deletion src/pyduke_energy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
IOT_API_BASE_URL = "https://app-core1.de-iot.io/rest/cloud/"
FASTPOLL_ENDPOINT = "smartmeter/fastpoll/start"
OAUTH_ENDPOINT = "auth/oauth2/token"
BASIC_AUTH = "Basic NEdtR3J1M085TEFIV3BMNjVjbWpyZDhtQ1VKZU5XTVo6OWFyZVZoZlM3R2N4UmgzWA==" # hard-coded from Android app
SMARTMETER_AUTH_ENDPOINT = "smartmeter/v1/auth"
ACCT_ENDPOINT = "auth/account-list"
ACCT_DET_ENDPOINT = "auth/account-details"
GW_STATUS_ENDPOINT = "gw/gateways/status"
GW_USAGE_ENDPOINT = "smartmeter/usageByHour"

# hard-coded from Android app
BASIC_AUTH = (
"Basic NEdtR3J1M085TEFIV3BMNjVjbWpyZDhtQ1VKZU5XTVo6OWFyZVZoZlM3R2N4UmgzWA=="
)

DEFAULT_TIMEOUT = 10 # seconds

MQTT_HOST = "app-core1.de-iot.io"
Expand All @@ -28,6 +32,9 @@
# number of times a message timeout can occur before just reconnecting
MESSAGE_TIMEOUT_RETRY_COUNT = 3

# number of times a message timeout can occur before we totally give up
MESSAGE_TIMEOUT_GIVE_UP_COUNT = 10

# in minutes, minimum amount of time to wait before retrying connection on forever loop
FOREVER_RETRY_MIN_MINUTES = 1

Expand Down
8 changes: 7 additions & 1 deletion src/pyduke_energy/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
FASTPOLL_TIMEOUT_SEC,
FOREVER_RETRY_MAX_MINUTES,
FOREVER_RETRY_MIN_MINUTES,
MESSAGE_TIMEOUT_GIVE_UP_COUNT,
MESSAGE_TIMEOUT_RETRY_COUNT,
MESSAGE_TIMEOUT_SEC,
MQTT_ENDPOINT,
Expand Down Expand Up @@ -291,13 +292,18 @@ async def connect_and_subscribe(self):
await asyncio.wait_for(self._rx_msg, MESSAGE_TIMEOUT_SEC)
self._msg_retry_count = 0
self._forever_retry_count = 0
except asyncio.TimeoutError:
except asyncio.TimeoutError as toex:
self._msg_retry_count += 1
if self._disconnected.done():
_LOGGER.debug(
"Unexpected disconnect detected, attemping reconnect"
)
await self._reconnect()
elif self._msg_retry_count > MESSAGE_TIMEOUT_GIVE_UP_COUNT:
_LOGGER.error("Too many msg timeouts, giving up")
raise MqttError(
"Reached timeout limit for reconnecting to MQTT"
) from toex
elif self._msg_retry_count > MESSAGE_TIMEOUT_RETRY_COUNT:
_LOGGER.debug("Multiple msg timeout, attempting reconnect")
await self._reconnect()
Expand Down

0 comments on commit a6ed292

Please sign in to comment.