fix(state,pricing): bound entity-id replace() to first occurrence (#900)#900
Open
jackmcintyre wants to merge 1 commit into
Open
fix(state,pricing): bound entity-id replace() to first occurrence (#900)#900jackmcintyre wants to merge 1 commit into
jackmcintyre wants to merge 1 commit into
Conversation
Entity-id derivation used unbounded str.replace() in 7 places, swapping EVERY occurrence of the substring. For ids containing the substring more than once (rare but possible with custom renames like 'sensor.amber_price_price'), the result was malformed — e.g. 'sensor.amber_price_detailed_price_detailed' instead of 'sensor.amber_price_detailed_price'. Added count=1 to all 7 sites: - state/reader.py: _read_shadow_prices (2), _read_legacy_forecasts (2), read_all_external_state demand_window derivation (1) - pricing/provider.py: AmberProvider.read_forecasts (1), AmberExpressProvider.read_forecasts (1) This matches the existing correct pattern at reader.py:198/203 which already used count=1. TDD: failing test with double '_price' substring asserting only the first occurrence is replaced. 3216 pass, coverage 95%.
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.
Summary
Entity-id derivation used unbounded
str.replace()in 7 places, swapping EVERY occurrence of the substring. For ids containing the substring more than once (rare but possible with custom renames likesensor.amber_price_price), the result was malformed — e.g.sensor.amber_price_detailed_price_detailedinstead ofsensor.amber_price_detailed_price.This matches the existing correct pattern at
reader.py:198/203which already usedcount=1for theamber_express_prefix transform. The inconsistency was the bug.Changes — added
count=1to all 7 sitesstate/reader.py:_read_shadow_prices(2 sites:_price→_forecast)_read_legacy_forecasts(2 sites:_price→_price_detailed)read_all_external_statedemand_window derivation (1 site:price_spike→demand_window)pricing/provider.py:AmberProvider.read_forecasts(1 site)AmberExpressProvider.read_forecasts(1 site)Validation
TestEntityIdDerivationCountwith double_pricesubstring asserting only the first occurrence is replaced. Confirmed the unbounded replace producedsensor.amber_price_detailed_price_detailed(both replaced); after fix producessensor.amber_price_detailed_price.uv run ruff checkclean.