Skip to content

Fix bugs and align with HA standards#48

Draft
peternijssen wants to merge 1 commit into
arjenbos:mainfrom
peternijssen:fix/ha-standards
Draft

Fix bugs and align with HA standards#48
peternijssen wants to merge 1 commit into
arjenbos:mainfrom
peternijssen:fix/ha-standards

Conversation

@peternijssen
Copy link
Copy Markdown

While working on a DHL component with Claude, I've requested Claude to also review this repository. I believe it found valid improvements and fixes. Just waiting for a package to arrive in PostNL to see if everything still functions as expected.

Fix bugs and align with HA standards

Bug fixes

  • AttributeError on coordinator update — PostNLCoordinator referenced self.config_entry without ever assigning it. The constructor now accepts and stores the ConfigEntry.
  • Wrong base class — PostNLDelivery inherited from Entity instead of SensorEntity, preventing correct registration as a sensor platform entity.
  • Crash on None coordinator data — handle_coordinator_data accessed coordinator.data['receiver'] directly without guarding against None, which is always the case when called from init before the first refresh. Now uses .get() with a fallback and an early return.
    *AttributeError on ClientError.status — only ClientResponseError has a status attribute, not the parent ClientError. Added an isinstance check before accessing .status.

Security

  • OAuth access token removed from logs — auth.access_token was logged at debug level, exposing a live token to anyone with HA log access.

HA standards

  • SensorStateClass.MEASUREMENT added to both sensors, enabling long-term statistics in HA.
  • DeviceEntryType.SERVICE and configuration_url added to DeviceInfo.
  • state and unit_of_measurement properties replaced with native_value and _attr_native_unit_of_measurement / _attr_icon class variables (modern HA pattern since 2022.5).
  • requests added to manifest.json requirements.

Minor

*async_setup_entry return type corrected from -> True to -> bool.

  • Log message in async_unload_entry corrected from "Reloading" to "Unloading".

- 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>
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