Skip to content

Introduce new sensors - #50

Closed
peternijssen wants to merge 15 commits into
arjenbos:mainfrom
ha-parcel-integrations:feature/alignment
Closed

Introduce new sensors#50
peternijssen wants to merge 15 commits into
arjenbos:mainfrom
ha-parcel-integrations:feature/alignment

Conversation

@peternijssen

@peternijssen peternijssen commented May 30, 2026

Copy link
Copy Markdown
Contributor

This merges #48 and #52 as well as #49

Removes old sensors and brings new sensors to the table, aligned with the ha-dhl-nl integration.

New sensors

Entity Description
sensor.<account>_postnl_incoming_parcels Number of active incoming parcels
sensor.<account>_postnl_parcel_<barcode> Status of a single incoming shipment; created and removed automatically
sensor.<account>_postnl_next_delivery Earliest expected delivery datetime (device class timestamp)
sensor.<account>_postnl_en_route_to_postnl_point Parcels destined for a PostNL pickup point
sensor.<account>_postnl_outgoing_parcels Number of active outgoing shipments

More info can be found here, where I requested people to test it out:
https://community.home-assistant.io/t/postnl-and-dhl-nl-integration/112433/524

peternijssen and others added 9 commits May 16, 2026 21:59
- Fix coordinator AttributeError: pass config entry to PostNLCoordinator
- Fix wrong base class: SensorEntity instead of Entity
- Fix None guard on coordinator.data in handle_coordinator_data
- Fix AttributeError on ClientError.status: guard with isinstance check
- Remove OAuth access token from debug log (security)
- Fix async_setup_entry return type annotation: True -> bool
- Fix misleading log message in async_unload_entry
- Add requests to manifest requirements
- Add SensorStateClass.MEASUREMENT to both sensors
- Add DeviceEntryType.SERVICE and configuration_url to DeviceInfo
- Replace old-style state/unit_of_measurement/icon properties with native_value and _attr_ class variables

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add auth.py: full PKCE + Janrain Capture login flow using aiohttp,
  token refresh, no browser redirect required
- Replace OAuth2FlowHandler with a plain ConfigFlow (username/password)
  and reauth confirm step
- Replace AsyncConfigEntryAuth OAuth2Session wrapper with direct token
  management from the config entry; raises ConfigEntryAuthFailed on
  auth failure to stop the retry loop
- Catch HomeAssistantError in coordinator and convert to UpdateFailed
- Add receiverTitle to GraphQL shipment fragment and Package struct
- Remove application_credentials dependency from manifest and delete
  application_credentials.py
- Add translations/en.json so config flow strings render in the UI
- Add docs/api/ with full reference for login, userinfo, GraphQL and
  Track & Trace endpoints

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
If the refresh token is missing or rejected, attempt a full re-login
using the stored credentials before triggering a reauth notification.
This silently recovers from expired or rotated refresh tokens without
requiring user intervention.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace two generic PostNLDelivery sensors with five named sensors
  mirroring DHL: incoming parcels (with per-parcel lifecycle), next
  delivery (timestamp device class), en route to PostNL point, and
  outgoing parcels
- Drop Package struct in favour of plain dicts, consistent with DHL
- Move coordinator creation from sensor.py to __init__.py so it is
  available to all platforms
- config_flow: FlowResult → ConfigFlowResult, _STEP_SCHEMA → _USER_SCHEMA,
  use _get_reauth_entry(), add from __future__ import annotations
- strings.json + translations/en.json: add top-level title, 2-space indent
- Add from __future__ import annotations to __init__, coordinator, sensor
- Rewrite README aligned with DHL style; add docs/sensors.md
- Bump poll interval from 90 s to 5 min

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
__init__.py imported coordinator.py, which imported AsyncConfigEntryAuth
back from __init__.py, causing a circular import on startup. Moved
AsyncConfigEntryAuth to auth.py; coordinator now imports it from there
directly alongside PostNLGraphql from graphql.py.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace two separate hassfest.yaml and validate.yaml workflows with a
single validate.yml matching the DHL and Postcodeloterij structure:
HACS validation + hassfest, triggered on push to main, pull_request,
and daily schedule. Bump to 3.0.1 to cover the circular import fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@peternijssen peternijssen changed the title Align with ha-dhl-nl integration Introduce new sensors May 30, 2026
ConfigEntryAuthFailed is now raised instead of HomeAssistantError so
HA's coordinator machinery triggers the reauth UI prompt automatically.
Previously, UpdateFailed was raised instead, causing a silent error log
with no reauth notification shown to the user.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@arjenbos

arjenbos commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Thanks for all the effort! I am currently on holiday and do not have the internet and workstation required to do a proper review. I will try to do it asap when i'm back.

- Import DOMAIN directly from .const in sensor.py instead of via the
  package re-export
- Remove the device/entity unique-id migration block from setup_entry
  (only applied to pre-3.0.0 installs which required re-adding the
  integration anyway)
- Move the 5-minute poll interval to a POLL_INTERVAL const, matching
  the DHL and Postcodeloterij components

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@peternijssen

Copy link
Copy Markdown
Contributor Author

No probs @arjenbos . Enjoy the holiday!

I tried to split things in multiple PRs, but they all depend on each other.
I've tagged my own version to have some tests and gather feedback. So far no issues reported 🤞🏻

A different possibility is also that you support the browser-extension based integration and I follow a different path, but that kinda leads to 2 integrations, which is also not beneficial for the community I suppose.

Let me know what you think is the best way forward.

peternijssen and others added 2 commits June 11, 2026 19:23
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a PostNLDeliveredParcelsSensor that tracks recently delivered
incoming parcels. The filter (last N days, or N most recent) is set
during setup and editable via the options flow without requiring a
reload. Also adds the Dutch translation file (nl.json).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@peternijssen

Copy link
Copy Markdown
Contributor Author

Based upon request this PR is growing. Sorry about that. Let's discuss later how to continue. Also had the first person to report issues with authentication, so wondering how flawless this works in comparison with the browser extension and if we should have one or two versions.
https://community.home-assistant.io/t/postnl-and-dhl-nl-integration/112433/530

peternijssen and others added 2 commits June 12, 2026 21:58
The sender attribute (PostNLNextDeliverySensor, PostNLEnRouteToServicePointSensor,
PostNLDeliveredParcelsSensor) was always empty because PostNL's GraphQL
returns sourceDisplayName=null in every observed response. The transform
now falls back to the title field, which holds the actual sender name.

Also moves the hardcoded "Days" / "Number of parcels" filter dropdown
labels to a translation_key block so they switch with the HA UI language.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@peternijssen
peternijssen marked this pull request as ready for review June 21, 2026 17:36
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.

2 participants