Remember modes a device reports but never advertises (issue #327)

Some firmware reports a current mode that is missing from the same
resource's supportedModes. An ARTIK051 air conditioner sits in Quiet
while advertising only [Off, Sleep, Speed, Nano, NanoSleep], so HA
showed preset_mode: quiet and then refused to select it. A second
reporter has three identical units where only the two sharing an
outdoor unit hide it, which rules out a real capability difference.

learned.py remembers any such code and the coordinator persists it on
the config entry, so a mode the device only names while it is active
survives a restart. climate._supported unions it into the resource's
own list, which fixes the read and the write together --
async_set_preset_mode reverse-resolves the device code from that same
list.

Learning is allowlisted per canonical href rather than global. Across
the fixture corpus 17 dumps already report a current mode that is not
in supportedModes: an oven idling in NoOperation, a fridge's
/mode/vs/0 carrying capability tokens like WATERFILTER_DISABLE. Those
are not selectable options, and remembering one permanently would put
an option in the UI that the device can only reject. Only
/mode/convenient/vs/0 is learnable today.

On by default, with a per-device option that stops offering and
learning at once, and a reset step in the options flow for a code that
turns out to be bogus. Diagnostics report what was learned separately
from `resources`, which stays exactly what the device said.
This commit is contained in:
Marc Billow committed 2026-08-08 19:10:53 +00:00
1 parent 867f4b0ae8
commit d65735ac47
19 files changed
+754 -16

No files matched your search

+5
View File
@@ -119,6 +119,11 @@ def test_fac_bora_wind_strength_codes_fit_the_standard_scale():
# canonical view is just the raw snapshot (issue #177).
return self.last_resources
def learned_modes(self, href, field=None):
# Nothing learned in this stub -- issue #327's store lives on
# the real coordinator; climate._supported unions it in.
return []
resources = _load_device("airconditioner_fac_bora")
info = resources["/information/vs/0"]
reg = by_type.for_device_by_model(