AC: quantize subdevice temperature writes against their own step (Opus review)
async_send_command handed write_fn/validate_fn the raw cache snapshot (real, on-the-wire hrefs), not a subdevice-scoped view. Every other consumer of a full resources dict (exists_fn, rep_fn, is_legacy_board, ...) reads through coordinator.canonical_resources() specifically to avoid this; write_fn/validate_fn didn't, so on a composite AC (issue #177) _temperature_step's resources.get(HREF_TEMP_CONTROL) saw the master's /temperature/control/vs/0 instead of the subdevice's own /temperature/control/vs/1, silently rounding a subdevice's 0.5-degree write to a whole degree. The remote-control gate stays on the raw snapshot -- /remotectrl/* is a shared, MAIN-only resource a subdevice's owned-hrefs-only canonical view would drop entirely. climate.py's target_temperature_step duplicated this same read-in-order logic; pointed it at airconditioner._temperature_step so the read and write paths can't drift again. Also, from the same review: - _quantize_temperature rejects non-finite floats (nan/inf survive float() but raise out of round()/division, escaping write_fn's documented None-on-bad-payload contract). - Deduplicated the quantize-and-check block shared by the temperature_ocf/temperature branches of _climate_write. - Added the /temperatures/vs/0 items[]-fallback test that was previously unreachable (every increment-carrying fixture also has /temperature/control/vs/0, which _temperature_step checks first). - Added a coordinator-level test seeding an indexed subdevice with its own step, distinct from the master's, covering the fix above. - The Towels/Bedding regression test now checks all 7 locale catalogs, not just English -- the bug is a code-mapping error, and test_every_language_mirrors_the_english_catalog only checks key topology, not values.
This commit is contained in:
@@ -201,3 +201,33 @@ async def test_main_climate_write_unaffected_by_subdevice_translation(coordinato
|
||||
|
||||
posted_path, _ = coordinator._session.post_calls[0]
|
||||
assert posted_path == ["power", "vs", "0"]
|
||||
|
||||
|
||||
async def test_indexed_subdevice_climate_write_quantizes_with_its_own_temperature_step(
|
||||
coordinator,
|
||||
) -> None:
|
||||
"""A composite AC's write_fn (airconditioner._climate_write) reads the
|
||||
temperature step off write_fn's own `resources` argument -- if
|
||||
async_send_command handed it the raw cache snapshot (real, on-the-wire
|
||||
hrefs) instead of this subdevice's canonical_resources() view, the
|
||||
subdevice's own /temperature/control/vs/1 would be invisible under the
|
||||
canonical HREF_TEMP_CONTROL key, and the write would quantize against
|
||||
the master's step (or none at all) instead of its own."""
|
||||
sub1 = Subdevice(kind="indexed", key="1", seed_path=("device", "1"))
|
||||
coordinator._observe.apply(
|
||||
"/temperature/control/vs/0",
|
||||
{"x.com.samsung.da.increment": "1"},
|
||||
source="poll",
|
||||
)
|
||||
coordinator._observe.apply(
|
||||
"/temperature/control/vs/1",
|
||||
{"x.com.samsung.da.increment": "0.5"},
|
||||
source="poll",
|
||||
)
|
||||
bound = _climate_bound("/mode/vs/1", sub1)
|
||||
|
||||
await coordinator.async_send_command(bound, ("temperature_ocf", 24.5))
|
||||
|
||||
posted_path, posted_bytes = coordinator._session.post_calls[0]
|
||||
assert posted_path == ["temperature", "desired", "1"]
|
||||
assert cbor2.loads(posted_bytes) == {"temperature": 24.5}
|
||||
|
||||
Reference in New Issue
Block a user