Discard predictions only when their inputs change

A finished plan was discarded whenever any watched State object changed
during the save or calculation, including diagnostic-only weather
sensors and the thermostat's current_temperature/hvac_action. The
proposed-heat entity then went unavailable for five minutes without
cause. Compare only the values the prediction uses: room and outdoor
temperature states and units, thermostat mode and target, and relay
state and last change.

Also pass config_entry to the coordinator explicitly instead of relying
on HA's ContextVar fallback, which HA reports as deprecated usage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
buzeraandClaude Opus 5.5 committed 2026-10-26 21:21:25 +02:00
1 parent c3646ba876
commit 2a0a94c640
3 files changed
+40 -7

No files matched your search

+13
View File
@@ -388,6 +388,19 @@ class BoundaryTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(data['sample_result'], 'first_sample')
self.assertGreater(data['heat_lag_uncertainty'], 0.4)
async def test_diagnostic_input_changes_do_not_discard_prediction(self):
self.ready()
self.c.config['outside_pressure_sources'] = ['sensor.pressure']
self.set_state('sensor.pressure', '1010', unit_of_measurement='hPa')
self.set_state('climate.reference', 'heat', temperature=22, current_temperature=20.0)
async def changed(job):
output = job()
self.set_state('sensor.pressure', '1011', unit_of_measurement='hPa')
self.set_state('climate.reference', 'heat', temperature=22, current_temperature=20.1)
return output
self.hass.async_add_executor_job = changed
self.assertEqual((await self.sample())['status'], 'ready')
async def test_heat_gain_identified_with_mid_interval_switching(self):
"""Synthetic plant with radiator lag, cycled by a hysteresis thermostat."""
a, b, c = 0.004, 0.12, 0.0005