Skip to content

Commit

Permalink
Merge pull request #1 from hmueller01/taskgroup
Browse files Browse the repository at this point in the history
switch from asyncio.gather() to async TaskGroup()
  • Loading branch information
hmueller01 authored Feb 16, 2025
2 parents 4ab6c65 + ad5dddf commit 522daf5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12"]
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ If Home Assistant is enabled (`HASS_ENABLED: True`) Home Assistant auto config m

## Changelog

| Version | Date | Author | Comment |
| :------ | :--------- | :--------- | :---------------------------------------------- |
| 0.1.0 | 2024-06-18 | hmueller01 | Inital version |
| 0.2.0 | 2024-07-25 | hmueller01 | fix timeout issues |
| 0.3.0 | 2024-09-07 | hmueller01 | migrated to new APsystemsEZ1 2.x API |
| 0.4.0 | 2024-10-21 | hmueller01 | added APsystemsEZ1 2.4 API enable_debounce=True |
| Version | Date | Author | Comment |
| :------ | :--------- | :--------- | :------------------------------------------------ |
| 0.1.0 | 2024-06-18 | hmueller01 | Inital version |
| 0.2.0 | 2024-07-25 | hmueller01 | fix timeout issues |
| 0.3.0 | 2024-09-07 | hmueller01 | migrated to new APsystemsEZ1 2.x API |
| 0.4.0 | 2024-10-21 | hmueller01 | added APsystemsEZ1 2.4 API enable_debounce=True |
| 0.4.1 | 2024-11-03 | hmueller01 | switch from asyncio.gather() to async TaskGroup() |
19 changes: 12 additions & 7 deletions apsystems_ez1_mqtt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys

from argparse import ArgumentParser
from asyncio import TaskGroup
from datetime import datetime, timedelta

from APsystemsEZ1 import ReturnDeviceInfo
Expand Down Expand Up @@ -125,7 +126,8 @@ async def main():
ssid='debug dummy ssid',
ipAddr='192.168.9.9',
minPower=int(30),
maxPower=int(800))
maxPower=int(800),
isBatterySystem=False)
else:
_logger.error("Can't read APsystems info data. Waiting for a minute ...")
await asyncio.sleep(60)
Expand All @@ -149,12 +151,15 @@ async def main():
_mqtt.hass_init(conf.ecu_config, ecu_info) # must init before homa_init
_mqtt.homa_init(ecu_info, _ecu.city.tzinfo)

_logger.info("Started all periodic tasks. Press <Ctrl>-C to terminate.")
await asyncio.gather(
periodic_wakeup(),
periodic_get_data(conf.ecu_config.update_interval),
periodic_get_power(600), # 10min update interval
)
_logger.info("Starting all periodic tasks. Press <Ctrl>-C to terminate.")
try:
async with TaskGroup() as group:
# spawn tasks
group.create_task(periodic_wakeup())
group.create_task(periodic_get_data(conf.ecu_config.update_interval))
group.create_task(periodic_get_power(600)) # 10min update interval
except (Exception) as e:
_logger.error("An exception occured: %s -> %s", e.__class__.__name__, str(e))
_logger.info("main() ended.")


Expand Down
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
aiohappyeyeballs==2.4.3
aiohttp==3.10.10
aiosignal==1.3.1
apsystems-ez1==2.4.0
aiohappyeyeballs==2.4.6
aiohttp==3.11.12
aiosignal==1.3.2
apsystems-ez1==2.5.0
astral==3.2
attrs==24.2.0
certifi==2024.8.30
frozenlist==1.4.1
attrs==25.1.0
certifi==2025.1.31
frozenlist==1.5.0
idna==3.10
multidict==6.1.0
paho-mqtt==2.1.0
PyYAML==6.0.2
str2bool==1.1
yarl==1.15.5
yarl==1.18.3

0 comments on commit 522daf5

Please sign in to comment.