Repository navigation
Conversation
springfall2008
left a comment
There was a problem hiding this comment.
Automated comment from the triage bot.
Reviewed at a4d606a (PR head, matches headRefOid). 5 findings inline, 1 in the body. The new metric_spot_* read path, the key/scaling table, the deprecation warning and the automatic_config() guard all behave as the PR body describes; what follows is one unwired consumer, one untested wiring change, and three duplication/diagnostic points. Nothing was run - this is a reading of the checked-out head only.
apps/predbat/compare.py:229 - the Compare feature does not know about metric_spot_import / metric_spot_export
compare.py has a rate-source chain that enumerates every other source - rates_import_octopus_url, metric_octopus_import, metric_energidataservice_import, metric_stromligning_import_today/_tomorrow, rates_import - and this PR adds no metric_spot_* branch to it (nor to the export side, compare.py:269).
Failure scenario: a spot-rate user (the Czech/Nord Pool or Frank Energie case this PR is written for) follows docs/compare.md, which lists the sources it supports, and writes a compare_list entry with metric_spot_import: 'sensor.current_buy_electricity_price_raw'. The key matches no branch, so the chain falls through to self.log("Using existing rate import data") and the row is costed against the live tariff while being labelled as the compared tariff - a silently wrong comparison result rather than an error, which is the worst of the three outcomes for a feature whose whole purpose is a what-if cost. The deprecated metric_octopus_import name still works in compare_list, so this is a gap rather than a regression, but it is the one consumer of the rate settings the PR leaves on the old name while docs/compare.md continues to advertise it. I traced both chains and confirmed there is no metric_spot match and no warning on the fall-through.
| scale = 100.0 | ||
| if rate_key not in data_all[0]: | ||
| rate_key = "value" | ||
| if rate_key not in data_all[0]: |
There was a problem hiding this comment.
Automated comment from the triage bot.
When data_all is non-empty but the layout matches none of the four documented keys, this falls through to rate_key = "price", from_key = "from", to_key = "till" and resets from_key/to_key even if the earlier block had already chosen start/end. minute_data() then finds no from key on any slot, skips every item and returns {}, and the only thing the user sees is fetch_sensor_data()'s generic Error: metric_spot_import is not set correctly in apps.yaml, or no energy rates can be read.
Failure scenario: a sensor whose slots are start / end / price - a plausible Nord Pool variant, and not in the table this PR adds to energy-rates.md - or any sensor with a mistyped key. Block 2 selects start/end with scale = 100, block 3 leaves rate_key as value (absent), and block 4 overrides from_key/to_key back to from/till (also absent), so nothing parses. The user is told their sensor is "not set correctly" with no indication that the key names are the problem, while the docs present the four layouts as the complete contract.
The information needed is in hand at this point: logging sorted(data_all[0]) once (via spot_rates_warn_once(), so it does not repeat every cycle) when rate_data comes back empty would name the mistake directly, and would also catch the unit confusion the docs call the most common error.
|
All six findings were fair. I've addressed them in the follow-up commit, and also guarded Kraken, which had the same silent out-ranking as the Octopus component.
Behaviour change to be aware of: EDF and E.ON (Kraken) users who set metric_spot_, metric_energidataservice_ or metric_stromligning_* themselves will now get their own source used, as Octopus users already do. Nothing changes for anyone who has not set one of those. |
Generic spot rate settings:
metric_spot_import/metric_spot_exportDiscussion item #5285
Requirement
metric_octopus_import/metric_octopus_exportcurrently accept any sensor that publishes its rates inraw_today/raw_tomorrowattributes, and that is how the Nord Pool, Czech and Frank Energie examples work. But the name implies UK Octopus only, and the required data format was not documented anywhere (you had to infer it from the examples).What changed
New settings (apps.yaml)
metric_spot_importandmetric_spot_exportconfiguration entires inapps.yamlfor feeding custom spot rates into Predbat. They read rates only from a sensor'sraw_today/raw_tomorrowattributes. They are added toAPPS_SCHEMA.futurerate_adjust_auto) and the automatic AgilePredict region lookup only look atmetric_octopus_*, so a spot sensor can never trigger either.futurerate.pyis unchanged.fetch_octopus_rates()'s logic, so a sensor gives identical rates under either name.start,end,valuefrom,till,pricefrom,to,ratevalid_from,valid_to,value_inc_vatCode
fetch.py: newfetch_spot_rates()andspot_rates_warn_once(). Newelifbranches in the import and export chains offetch_sensor_data(). Precedence isrates_*_octopus_url, thenmetric_octopus_*, thenmetric_spot_*, then Energi Data Service, then Strømligning, thenrates_*. A one-off warning is logged if bothmetric_octopus_*andmetric_spot_*are set.octopus.py:fetch_octopus_rates()gains an optionalspot_argparameter, used only for the deprecation warning below. The rates it returns and the logs it writes are unchanged (checked against the original for every attribute layout).octopus.py:OctopusAPI.automatic_config()no longer auto-configuresmetric_octopus_import/metric_octopus_exportwhen the user's apps.yaml sets a lower-ranked source for that direction:metric_spot_*,metric_energidataservice_*ormetric_stromligning_*. Previously the auto-discovered Octopus entry outranked them silently. For a skipped import,metric_standing_chargeis also left alone. A note is logged once, worded likeset_arg_auto()'s existing "keeping your apps.yaml setting" message.predbat.py:spot_rates_warnedset, initialised inreset().Docs
energy-rates.md: new section on the spot sensor data format (key and scaling table, example attribute, the "feeding cents makes prices 100× too high" pitfall), the precedence order, and the auto-config behaviour. The Czech example now uses the new names. Frank Energie now has an apps.yaml example, and its template publishesraw_todayinstead ofprices(docs only: anyone who copied the old template keeps working undermetric_octopus_export).apps-yaml.md:metric_spot_import/metric_spot_exportlisted, with the old names flagged.Deprecation
Using
raw_today/raw_tomorrowattributes throughmetric_octopus_import/metric_octopus_exportstill works but is now deprecated. Once such rates have loaded, a one-off warning names the sensor and the new setting to use. It does not fire for:rates)pricesattributemetric_octopus_gasNo removal date is set.
Behaviour change for existing users
Only the
automatic_config()guard: a user running the Octopus component with auto-configure andmetric_spot_*,metric_energidataservice_*ormetric_stromligning_*inapps.yamlwill now get their own source used, where before the Octopus one silently won. Nothing changes for anyone else.Tests
New
tests/test_fetch_spot_rates.py, registered inunit_test.pyas two tests:fetch_spot_rates(13 cases): all four key layouts and their scaling,raw_tomorrow, missing/empty/Nonesensors,rates/prices/ Octopus event sensors not being read,io_adjustednever touched, identical rates throughfetch_octopus_rates(), ametric_spot_*sensor never detected as Agile and giving no AgilePredict region, the one-off helper, and the deprecation warning (fires once per direction, silent for real Octopus /prices/ nospot_arg/ failed loads).octopus_auto_rates(6 cases): the auto-config guard across spot, Strømligning and Energi Data Service, one note across re-runs, usermetric_octopus_*regular expression still replaced as before, and no apps.yaml snapshot available.No existing tests were amended.
Not covered by a unit test: the precedence order and the both-names-set warning inside
fetch_sensor_data(), which can't be reached from the test fixture without a larger refactor.Checklist
./run_all --test fetch_octopus_rates --test fetch_spot_rates --test octopus_auto_ratesall pass./run_pre_commitpasses