Fix NoneType crash in premium sensors and cart service calls#66
Open
TeTeHacko wants to merge 1 commit intodvejsada:masterfrom
Open
Fix NoneType crash in premium sensors and cart service calls#66TeTeHacko wants to merge 1 commit intodvejsada:masterfrom
TeTeHacko wants to merge 1 commit intodvejsada:masterfrom
Conversation
- binary_sensor.py / sensor.py: use 'or {}' instead of default={}
in .get('premiumLimits') to handle explicit null from API
- hub.py: remove await self.async_update() from add_to_cart and
delete_from_cart to prevent cascade failure through broken sensors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two related bugs cause crashes for users whose Rohlík API returns `"premiumLimits": null`
(users without Premium or with certain membership tiers):
Bug 1: `premiumLimits: null` crashes sensor and binary_sensor platforms
`dict.get(key, default)` only returns the default when the key is missing.
When the API explicitly returns `"premiumLimits": null`, `.get('premiumLimits', {})`
returns `None`, and the subsequent `.get('ordersWithoutPriceLimit', ...)` raises:
This prevents `binary_sensor.tomas_herceg_premium_membership` and
`sensor.tomas_herceg_no_limit_orders` / `sensor.tomas_herceg_free_express_deliveries`
from being added to HA at all.
Traceback from HA log:
Bug 2: `add_to_cart` / `delete_from_cart` service calls return HTTP 500
Because these methods call `await self.async_update()` after the API call, which
triggers `publish_updates()` → sensor callbacks → the broken sensors above →
the exception propagates and the entire service call fails with:
This means `search_and_add_to_cart` (and `add_to_cart`, `delete_from_cart`) always
return 500 for affected users, even though the underlying API call succeeded.
Traceback:
Fix
`binary_sensor.py` / `sensor.py`: Use `or {}` instead of `, {}` default
to handle explicit `null` values from the API.
`hub.py`: Remove `await self.async_update()` from `add_to_cart` and
`delete_from_cart`. The periodic update via `UpdateSensor` (every 10 min)
is sufficient; triggering a full refresh as a side-effect of a service call
is what causes the cascade failure.
Tested on