Skip to content

This PR addresses several critical issues that were breaking the PostNord (PN) delivery tracking API and causing the sensors to show up as unavailable or throw backend exceptions.#44

Open
ticstyle wants to merge 21 commits into
DSorlov:mainfrom
ticstyle:main

Conversation

@ticstyle

Copy link
Copy Markdown
Contributor
  1. **Robust PostNord Date Parsing (worker/__init__.py):

  2. ** Rewrote the _handle_pn_data method to safely parse delivery strings without throwing IndexError (list index out of range). It now gracefully handles variance in spaces, commas, or alternative status messages, falling back to a string representation safely.

  3. Type-Mismatch Resolution (worker/__init__.py): Fixed an issue where sensors would remain unavailable due to strict dictionary lookups using mixed types (int vs str for postal codes). The parsed data is now stored under both integer and string keys to ensure compatibility regardless of how other components query it.

  4. Backward-Compatible Hybrid Worker (worker/__init__.py): Restored and harmonized the synchronous fetch() method alongside the asynchronous implementation. This completely resolves the 'HttpWorker' object has no attribute 'fetch' exception caused by version discrepancies between the component core and the module file. It also provides aliases for both fetch_postal_city and fetchPostalCity.

  5. CI Line-Length Lint Fix (config_flow.py): Split the long _LOGGER.warning string on line 142 into multiple lines to conform to strict PEP8/linter line-length constraints (e.g., Black/Ruff) that were previously failing the GitHub Actions CI workflow.

Changes Made

custom_components/swemail/worker/__init__.py

  • Enhanced _handle_pn_data to clean up string inputs and check list boundaries before indexing.
  • Implemented dual-key storage (mapping int(postalcode) and str(postalcode)) for the cached data payload.
  • Retained full compatibility for synchronous environments (requests-based fetch) and asynchronous ones (aiohttp-based fetch_async).

custom_components/swemail/config_flow.py

  • Formatted the long string argument inside _LOGGER.warning under the options flow fallback to comply with max line-length rules.

Testing

  • Verified that the code passes linting checks regarding line length.
  • Confirmed that the Home Assistant component initializes successfully without missing attribute errors.
  • Confirmed that entities update correctly and transition from unavailable to presenting accurate delivery tracking states (e.g., "Today").

ticstyle added 2 commits June 26, 2026 13:24
…nord api

Added synchronous fetch method using requests and updated error handling for delivery data and the new postnord api.
@ticstyle ticstyle marked this pull request as draft June 26, 2026 11:34
@ticstyle ticstyle marked this pull request as ready for review June 26, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant