Repository navigation
Conversation
…te grid scan load_battery_temperature_minutes read battery_temperature_history with no index. With the per-inverter list form in apps.yaml the whole list reached get_history, and every plan run failed with "TypeError: cannot use 'list' as a dict key (unhashable type: 'list')". It now passes index=self.id, as the grid_power lookup next to it does. test_battery_rate_grid_scan gets a case with the list form. It fails on main and passes with this change.
springfall2008
left a comment
There was a problem hiding this comment.
Automated comment from the triage bot.
Reviewed f60c1638: 0 findings inline, 1 in the body.
The fix is right for the reported crash. resolve_arg() takes value[index] before any template, join-list or entity resolution, so a per-inverter list now resolves to this inverter's sensor, and it does so for the {...}-templated and +[...] forms of a list entry too. The string form is unchanged: the indexed-read warning in resolve_arg() only fires when the index is truthy, so inverter 0's read of a plain string still returns it silently, and battery_temperature_history is not in CONFIG_ITEMS so get_ha_config() cannot return a value that bypasses resolve_arg(). Production only ever scans inverter 0 (execute.py passes self.inverters[0] to battery_rate_grid_update()), so self.id is 0 on every real call. The other readers of the key (fetch_battery_temperature(), check_battery_temperature_history_stuck()) never pass it to get_history_wrapper() themselves, so none is left crashing. Test 9 is genuinely red without the change: the unindexed read returns the list from resolve_arg(), get_history_wrapper() hands it to the mock get_history(), and the dict membership test raises TypeError: unhashable type: 'list'.
apps/predbat/fetch.py:2855 — a multi-entry list is summed into one temperature
The PR body's "Other get_arg calls checked" section accepts fetch_battery_temperature() because minute_data_import_export() "takes a string or a list and reads every entity". It does read every entity, but it adds them together: it passes the running series as accumulate= to minute_data(), which does mdata[minute] += accumulate.get(minute, 0) for each entity in turn.
Failure scenario: two inverters with battery_temperature_history: [sensor.inv0_temp, sensor.inv1_temp]. minute_data_import_export() is called with no required_unit and scale=1.0, so the raw degrees are added: two packs at 15 °C and 16 °C give a battery_temperature_history of 31 °C for the whole window. predict_battery_temperature() then produces a battery_temperature_prediction of ~2× the real temperature across the 48-hour horizon, and prediction.py picks the plan's rate-grid row and manual temperature cap from it — a warmer row and a looser cap than the packs allow, which is the over-permissive cold-weather plan that the 0 °C work (#6193, #6189) set out to stop. It also disagrees with the curve scan this PR fixes, which now uses inverter 0's sensor alone as the evidence's temperature dimension.
This is not a regression from the PR — the same config crashed the scan every cycle before it — but the change turns a loud failure into a silently wrong temperature once the list has more than one entry, which is the next symptom of the list form being supported. Fixing it in the same shape as the line this PR changes, reading one index in fetch_battery_temperature() too (the key is site-wide in the docs, discovery_contract's SITE_SETTINGS, and every integration's auto-config), would also make the evidence and the plan's lookup agree.
What I could not confirm: whether a multi-entry list is a config users actually write. The docs and the shipped example give one sensor, and the reporter's own list has one entry, so this may never be hit; if so, a line in docs/apps-yaml.md saying the setting is one sensor would close it from the other side.
What and why
Since v9.8.0 the rate grid scan reads
battery_temperature_historywith no index. Ifapps.yamlgives it as a per-inverter list, for examplebattery_temperature_history: [sensor.modbus_bms_cell_temp_low], the whole list is passed toget_historyand every plan run fails:I hit this on my own system with the list form above.
load_battery_temperature_minutesnow passesindex=self.id, as thegrid_powerlookup beside it does. A single sensor string still works: inverter 0 reads it with no warning.Other get_arg calls checked
Every other
get_arginbattery_curve.pyalready passes an index.battery_rate_grid.pyand the rate grid code infetch.pyandexecute.pyhave none to fix. Two reads of the same key are left alone on purpose:fetch_battery_temperature()hands the key tominute_data_import_export, which takes a string or a list and reads every entity.check_battery_temperature_history_stuck()only uses the value in a warning, and it checks for a string before it matches the GivTCP name. With the list form the warning shows the list and leaves out the rename hint, but it doesn't crash.Testing
test_battery_rate_grid_scan.pysets the list form and scans a 25-minute charge. It expects three segments at the sensor's temperature. Onmainit raisesTypeError: unhashable type: 'list', from the test's mock history where the realget_historywould raise. With this change it passes.battery_rate_grid_scan,battery_rate_grid,battery_rate_grid_update,battery_curve_keys,battery_temperature_fetchand the threebattery_temperature_stuck_warning*tests pass. pre-commit passes on the changed files. I haven't run the full suite.