Skip to content

Commit e1713a7

Browse files
authored
Merge pull request #50 from EVWorth/ruff-formatting
Ruff formatting, pre-commit, and validate workflow
2 parents 7709adc + f7f5ad4 commit e1713a7

35 files changed

+2164
-1638
lines changed

.github/workflows/validate.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Validate
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
ruff:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Ruff Check
18+
uses: astral-sh/ruff-action@v3
19+
with:
20+
args: check --output-format=github
21+
22+
- name: Ruff Format
23+
uses: astral-sh/ruff-action@v3
24+
with:
25+
args: format --check --diff

.pre-commit-config.yaml

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
---
22
fail_fast: true
33

4-
repos:
5-
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v5.0.0
7-
hooks:
8-
- id: trailing-whitespace
9-
- id: end-of-file-fixer
10-
- id: requirements-txt-fixer
11-
12-
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.12.3
14-
hooks:
15-
- id: ruff
16-
args: [--fix] # run linter
17-
- id: ruff-format # run formatter
4+
# To update pre-commit hooks run:
5+
# uv run pre-commit autoupdate
186

19-
- repo: https://github.com/asottile/pyupgrade
20-
rev: v3.20.0
21-
hooks:
22-
- id: pyupgrade
7+
repos:
8+
- hooks:
9+
- id: check-yaml
10+
- id: check-toml
11+
- id: check-json
12+
- id: no-commit-to-branch
13+
repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v6.0.0
15+
- hooks:
16+
- id: ruff-check
17+
- id: ruff-format
18+
repo: https://github.com/astral-sh/ruff-pre-commit
19+
rev: v0.13.3

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
"tests"
66
],
77
"python.testing.unittestEnabled": false,
8-
"python.testing.pytestEnabled": true
8+
"python.testing.pytestEnabled": true,
9+
"ruff.enable": true,
10+
"ruff.configuration": "pyproject.toml"
911
}

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 1.2.11 (2025-07-12)
2+
## What's Changed
3+
* Refactor for uv by @EVWorth in https://github.com/homeassistant-projects/pyadtpulse/pull/45
4+
* Update aiohttp zlib ng to aiohttp fast zlib zlib ng by @EVWorth in https://github.com/homeassistant-projects/pyadtpulse/pull/47
5+
* Workflow improvements by @EVWorth in https://github.com/homeassistant-projects/pyadtpulse/pull/48
6+
* Unit test fixes/removals by @HeroesDieYoung in https://github.com/homeassistant-projects/pyadtpulse/pull/42
7+
8+
## New Contributors
9+
* @EVWorth made their first contribution in https://github.com/homeassistant-projects/pyadtpulse/pull/45
10+
11+
**Full Changelog**: https://github.com/homeassistant-projects/pyadtpulse/compare/1.2.10...1.2.11
12+
113
## 1.2.9 (2024-04-21)
214

315
* ignore query string in check_login_errors(). This should fix a bug where the task was logged out

example-client.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/usr/bin/env python
22
"""Sample client for using pyadtpulse."""
33

4+
import sys
5+
import json
6+
import asyncio
47
import logging
58
import argparse
6-
import asyncio
7-
import json
8-
import sys
9+
from time import time, sleep
910
from pprint import pprint
10-
from time import sleep, time
1111

1212
from pyadtpulse import PyADTPulse
13+
from pyadtpulse.site import ADTPulseSite
1314
from pyadtpulse.const import (
14-
ADT_DEFAULT_KEEPALIVE_INTERVAL,
15-
ADT_DEFAULT_POLL_INTERVAL,
16-
ADT_DEFAULT_RELOGIN_INTERVAL,
1715
API_HOST_CA,
1816
DEFAULT_API_HOST,
17+
ADT_DEFAULT_POLL_INTERVAL,
18+
ADT_DEFAULT_RELOGIN_INTERVAL,
19+
ADT_DEFAULT_KEEPALIVE_INTERVAL,
1920
)
2021
from pyadtpulse.exceptions import (
21-
PulseAuthenticationError,
22-
PulseClientConnectionError,
22+
PulseLoginException,
2323
PulseConnectionError,
24+
PulseAuthenticationError,
2425
PulseGatewayOfflineError,
25-
PulseLoginException,
26+
PulseClientConnectionError,
2627
PulseServerConnectionError,
2728
PulseServiceTemporarilyUnavailableError,
2829
)
2930
from pyadtpulse.pyadtpulse_async import PyADTPulseAsync
30-
from pyadtpulse.site import ADTPulseSite
3131

3232
USER = "adtpulse_user"
3333
PASSWD = "adtpulse_password"
@@ -82,10 +82,12 @@ def setup_logger(level: int):
8282

8383

8484
def handle_args() -> argparse.Namespace:
85-
"""Handle program arguments using argparse.
85+
"""
86+
Handle program arguments using argparse.
8687
8788
Returns:
8889
argparse.Namespace: Parsed command-line arguments.
90+
8991
"""
9092
parser = argparse.ArgumentParser(description="ADT Pulse example client")
9193
parser.add_argument("json_file", nargs="?", help="JSON file containing parameters")
@@ -217,14 +219,16 @@ def handle_args() -> argparse.Namespace:
217219

218220

219221
def load_parameters_from_json(json_file: str) -> dict | None:
220-
"""Load parameters from a JSON file.
222+
"""
223+
Load parameters from a JSON file.
221224
222225
Args:
223226
json_file (str): Path to the JSON file.
224227
225228
Returns:
226229
Optional[Dict]: Loaded parameters as a dictionary,
227230
or None if there was an error.
231+
228232
"""
229233
try:
230234
with open(json_file, encoding="utf-8") as file:
@@ -268,10 +272,12 @@ def load_parameters_from_json(json_file: str) -> dict | None:
268272

269273

270274
def print_site(site: ADTPulseSite) -> None:
271-
"""Print site information.
275+
"""
276+
Print site information.
272277
273278
Args:
274279
site (ADTPulseSite): The site to display
280+
275281
"""
276282
print(f"Site: {site.name} (id={site.id})")
277283
print("Alarm panel: ")
@@ -281,7 +287,8 @@ def print_site(site: ADTPulseSite) -> None:
281287

282288

283289
def check_updates(site: ADTPulseSite, adt: PyADTPulse, run_alarm_test: bool) -> bool:
284-
"""Check a site for updates and print details.
290+
"""
291+
Check a site for updates and print details.
285292
286293
We don't really need to do this anymore, as the data will be
287294
updated in the background
@@ -292,6 +299,7 @@ def check_updates(site: ADTPulseSite, adt: PyADTPulse, run_alarm_test: bool) ->
292299
test_alarm: bool: sleep a bit if testing alarm
293300
294301
Returns: bool: True if update successful
302+
295303
"""
296304
if run_alarm_test:
297305
while (
@@ -311,12 +319,14 @@ def check_updates(site: ADTPulseSite, adt: PyADTPulse, run_alarm_test: bool) ->
311319

312320

313321
def test_alarm(site: ADTPulseSite, adt: PyADTPulse) -> None:
314-
"""Test alarm functions.
322+
"""
323+
Test alarm functions.
315324
316325
Args:
317326
site (ADTPulseSite): site to test
318327
adt (PyADTPulse): ADT Pulse connection objecct
319328
sleep_interval (int): length to sleep between tests
329+
320330
"""
321331
print("Arming alarm stay")
322332
if site.arm_home():
@@ -382,7 +392,8 @@ def sync_example(
382392
relogin_interval: int,
383393
detailed_debug_logging: bool,
384394
) -> None:
385-
"""Run example of sync pyadtpulse calls.
395+
"""
396+
Run example of sync pyadtpulse calls.
386397
387398
Args:
388399
username (str): Pulse username
@@ -394,6 +405,7 @@ def sync_example(
394405
keepalive_interval (int): keepalive interval in minutes
395406
relogin_interval (int): relogin interval in minutes
396407
detailed_debug_logging (bool): True to enable detailed debug logging
408+
397409
"""
398410
while True:
399411
try:
@@ -497,11 +509,13 @@ def sync_example(
497509

498510

499511
async def async_test_alarm(adt: PyADTPulse) -> None:
500-
"""Test alarm functions.
512+
"""
513+
Test alarm functions.
501514
502515
Args:
503516
site (ADTPulseSite): site to test
504517
adt (PyADTPulse): ADT Pulse connection objecct
518+
505519
"""
506520
print("Arming alarm stay")
507521
if await adt.site.async_arm_home():
@@ -619,7 +633,8 @@ async def async_example(
619633
relogin_interval: int,
620634
detailed_debug_logging: bool,
621635
) -> None:
622-
"""Run example of pytadtpulse async usage.
636+
"""
637+
Run example of pytadtpulse async usage.
623638
624639
Args:
625640
username (str): Pulse username
@@ -631,6 +646,7 @@ async def async_example(
631646
keepalive_interval (int): keepalive interval in minutes
632647
relogin_interval (int): relogin interval in minutes
633648
detailed_debug_logging (bool): enable detailed debug logging
649+
634650
"""
635651
adt = PyADTPulseAsync(
636652
username,

0 commit comments

Comments
 (0)