Skip to content

Commit 7d8a735

Browse files
committed
chore: fix CI issues, linting, and type safety
- Fix syntax errors and truncated code in src/nwp500/models/schedule.py - Add 'from __future__ import annotations' to all source files to fix runtime NameErrors - Resolve all ruff linting and formatting issues (E501, F401, etc.) - Fix pyright type-checking errors in AWS credential handling and model methods - Update tests/test_reservations.py to match high-level MQTT client API - Restore AuthTokens.to_dict() for compatibility
1 parent 680f06b commit 7d8a735

35 files changed

Lines changed: 160 additions & 86 deletions

examples/advanced/recirculation_control.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ def on_button_only_set(status):
119119
button_only_set = True
120120

121121
await mqtt_client.subscribe_device_status(device, on_button_only_set)
122-
await mqtt_client.set_recirculation_mode(
123-
device, 2
124-
) # 2 = Button Only
122+
await mqtt_client.set_recirculation_mode(device, 2) # 2 = Button Only
125123

126124
# Wait for confirmation
127125
for i in range(10): # Wait up to 10 seconds

src/nwp500/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
communication for NWP500 heat pump water heaters.
55
"""
66

7+
from __future__ import annotations
8+
79
from importlib.metadata import (
810
PackageNotFoundError,
911
version,

src/nwp500/auth.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import json
1717
import logging
18-
import warnings
1918
from datetime import UTC, datetime, timedelta
2019
from typing import Any, Self, cast
2120

@@ -182,6 +181,21 @@ def bearer_token(self) -> str:
182181
"""Get the formatted Bearer token for Authorization header."""
183182
return f"Bearer {self.access_token}"
184183

184+
def to_dict(self) -> dict[str, Any]:
185+
"""Convert tokens to a dictionary for serialization.
186+
187+
This includes the calculated issued_at timestamp, which is needed
188+
to maintain the correct expiration time when restoring tokens.
189+
"""
190+
data = self.model_dump()
191+
# Ensure issued_at is serialized in a format that model_validate can
192+
# parse
193+
if isinstance(data.get("issued_at"), datetime):
194+
data["issued_at"] = (
195+
data["issued_at"].strftime("%Y-%m-%dT%H:%M:%S.%f") + "Z"
196+
)
197+
return data
198+
185199

186200
class AuthenticationResponse(NavienBaseModel):
187201
"""Complete authentication response including user info and tokens."""
@@ -428,7 +442,9 @@ async def sign_in(
428442
)
429443

430444
# Parse successful response
431-
auth_response = AuthenticationResponse.model_validate(response_data)
445+
auth_response = AuthenticationResponse.model_validate(
446+
response_data
447+
)
432448
self._auth_response = auth_response
433449
self._user_email = user_id # Store the email for later use
434450

src/nwp500/cli/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""CLI package for nwp500-python."""
22

3+
from __future__ import annotations
4+
35
from .__main__ import run
46
from .handlers import (
57
handle_device_info_request,

src/nwp500/cli/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Navien Water Heater Control CLI - Main Entry Point."""
22

3+
from __future__ import annotations
4+
35
import asyncio
46
import functools
57
import logging

src/nwp500/cli/commands.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Command registry for NWP500 CLI."""
22

3+
from __future__ import annotations
4+
35
from collections.abc import Callable
46
from dataclasses import dataclass
57
from typing import Any

src/nwp500/cli/handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Command handlers for CLI operations."""
22

3+
from __future__ import annotations
4+
35
import asyncio
46
import json
57
import logging
@@ -328,9 +330,7 @@ def raw_callback(topic: str, message: dict[str, Any]) -> None:
328330
device_type, mqtt.client_id, "rsv/rd"
329331
)
330332
await mqtt.subscribe(response_topic, raw_callback)
331-
await mqtt.update_reservations(
332-
device, reservations, enabled=enabled
333-
)
333+
await mqtt.update_reservations(device, reservations, enabled=enabled)
334334
try:
335335
await asyncio.wait_for(future, timeout=10)
336336
except TimeoutError:

src/nwp500/cli/monitoring.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Monitoring and periodic status polling."""
22

3+
from __future__ import annotations
4+
35
import asyncio
46
import logging
57

@@ -41,9 +43,7 @@ def on_status_update(status: DeviceStatus) -> None:
4143

4244
await mqtt.subscribe_device_status(device, on_status_update)
4345
await mqtt.start_periodic_requests(device, period_seconds=30)
44-
await mqtt.request_device_status(
45-
device
46-
) # Get an initial status right away
46+
await mqtt.request_device_status(device) # Get an initial status right away
4747

4848
# Keep the script running indefinitely
4949
await asyncio.Event().wait()

src/nwp500/cli/output_formatters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Output formatting utilities for CLI (CSV, JSON)."""
22

3+
from __future__ import annotations
4+
35
import csv
46
import json
57
import logging

src/nwp500/cli/rich_output.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Rich-enhanced output formatting with graceful fallback."""
22

3+
from __future__ import annotations
4+
35
import json
46
import logging
57
import os

0 commit comments

Comments
 (0)