Fix ty failures in new AC temperature-step tests (CI)
ClimateDesc.write_fn is typed as WriteFn (Callable[[Any, dict], ...]), which only covers the (payload, rep) shape every other capability's write_fn honors -- calling it through that alias with the climate-only href/resources args, without first narrowing away the | None, failed ty two ways: the missing "is not None" check and the extra positional args past WriteFn's declared arity. Call _climate_write directly instead, same as test_coordinator_send_command.py and test_airconditioner_artik051_krac.py already do.
This commit is contained in:
1 file changed
+14
-12
@@ -157,15 +157,21 @@ def test_climate_write_preserves_half_degree_temperature_steps():
|
|||||||
The increment on /temperatures/vs/0 lives inside its items[] entry (the
|
The increment on /temperatures/vs/0 lives inside its items[] entry (the
|
||||||
same shape every fixture in the corpus uses), not at the resource's top
|
same shape every fixture in the corpus uses), not at the resource's top
|
||||||
level -- a fabricated flat `{"/temperatures/vs/0": {"increment": ...}}`
|
level -- a fabricated flat `{"/temperatures/vs/0": {"increment": ...}}`
|
||||||
resource would pass a step-reading bug like that silently."""
|
resource would pass a step-reading bug like that silently.
|
||||||
climate_desc = next(e for e in airconditioner.CLIMATE.entities if isinstance(e, ClimateDesc))
|
|
||||||
write = climate_desc.write_fn
|
Calls _climate_write directly rather than through ClimateDesc.write_fn
|
||||||
|
(as test_climate_write_targets above does): WriteFn only declares the
|
||||||
|
(payload, rep) shape every other write_fn honors, so the type checker
|
||||||
|
rejects a call carrying the climate-only href/resources params through
|
||||||
|
that narrower alias -- same reason test_coordinator_send_command.py and
|
||||||
|
test_airconditioner_artik051_krac.py import the function directly too.
|
||||||
|
"""
|
||||||
resources = _load_device("airconditioner_cac")
|
resources = _load_device("airconditioner_cac")
|
||||||
assert write(("temperature_ocf", 24.5), {}, None, resources) == (
|
assert airconditioner._climate_write(("temperature_ocf", 24.5), {}, None, resources) == (
|
||||||
["temperature", "desired", "0"],
|
["temperature", "desired", "0"],
|
||||||
{"temperature": 24.5},
|
{"temperature": 24.5},
|
||||||
)
|
)
|
||||||
assert write(("temperature", 24.5), {}, None, resources) == (
|
assert airconditioner._climate_write(("temperature", 24.5), {}, None, resources) == (
|
||||||
["temperatures", "vs", "0"],
|
["temperatures", "vs", "0"],
|
||||||
{
|
{
|
||||||
"x.com.samsung.da.items": [
|
"x.com.samsung.da.items": [
|
||||||
@@ -180,11 +186,9 @@ def test_climate_write_rounds_to_whole_degree_with_no_advertised_increment():
|
|||||||
increment field on /temperatures/vs/0's item -- target_temperature_step
|
increment field on /temperatures/vs/0's item -- target_temperature_step
|
||||||
(climate.py) defaults to 1.0 there, so the write path must match rather
|
(climate.py) defaults to 1.0 there, so the write path must match rather
|
||||||
than pass the raw value through unrounded."""
|
than pass the raw value through unrounded."""
|
||||||
climate_desc = next(e for e in airconditioner.CLIMATE.entities if isinstance(e, ClimateDesc))
|
|
||||||
write = climate_desc.write_fn
|
|
||||||
resources = _load_device("airconditioner_artik051_krac_18k")
|
resources = _load_device("airconditioner_artik051_krac_18k")
|
||||||
assert airconditioner._temperature_step(resources) is None
|
assert airconditioner._temperature_step(resources) is None
|
||||||
assert write(("temperature", 23.6), {}, None, resources) == (
|
assert airconditioner._climate_write(("temperature", 23.6), {}, None, resources) == (
|
||||||
["temperatures", "vs", "0"],
|
["temperatures", "vs", "0"],
|
||||||
{
|
{
|
||||||
"x.com.samsung.da.items": [
|
"x.com.samsung.da.items": [
|
||||||
@@ -199,10 +203,8 @@ def test_climate_write_rejects_non_numeric_temperature():
|
|||||||
build a body with `{"temperature": None}` -- coordinator.py's
|
build a body with `{"temperature": None}` -- coordinator.py's
|
||||||
async_send_command logs and drops a write_fn result of None instead of
|
async_send_command logs and drops a write_fn result of None instead of
|
||||||
POSTing it."""
|
POSTing it."""
|
||||||
climate_desc = next(e for e in airconditioner.CLIMATE.entities if isinstance(e, ClimateDesc))
|
assert airconditioner._climate_write(("temperature_ocf", "not-a-number"), {}) is None
|
||||||
write = climate_desc.write_fn
|
assert airconditioner._climate_write(("temperature", None), {}) is None
|
||||||
assert write(("temperature_ocf", "not-a-number"), {}) is None
|
|
||||||
assert write(("temperature", None), {}) is None
|
|
||||||
|
|
||||||
|
|
||||||
def test_climate_consumed_hrefs_declared_as_coverage():
|
def test_climate_consumed_hrefs_declared_as_coverage():
|
||||||
|
|||||||
Reference in new issue
Block a user