Fix pre-existing ty diagnostics in a second batch of test files

Same isinstance/cast narrowing and Optional-field assert pattern as the
prior commits, covering the airconditioner, fridge, washer, operational,
subdevices, sensor_hysteresis, laundry, select_options, identity and
entities test files.
This commit is contained in:
Marc Billow committed 2026-08-03 00:11:05 +00:00
1 parent 07061c734d
commit 36a642135b
17 files changed
+322 -100

No files matched your search

+15 -8
View File
@@ -8,6 +8,9 @@ entity there would silently drop working sensors on first-poll timing,
not just fix phantom ones.
"""
from typing import cast
from custom_components.localthings.coordinator import LocalThingsCoordinator
from custom_components.localthings.entity import _is_included
from custom_components.localthings.registry.capability import Capability
from custom_components.localthings.registry.discovery import BoundEntity
@@ -27,6 +30,10 @@ class _FakeCoordinator:
return self.last_resources
def _coord(last_resources) -> LocalThingsCoordinator:
return cast(LocalThingsCoordinator, _FakeCoordinator(last_resources))
def _bound(desc, href):
capability = Capability(href=href, entities=(desc,))
return BoundEntity(href=href, capability=capability, desc=desc)
@@ -40,17 +47,17 @@ class TestDefaultFieldGate:
def test_included_when_field_present(self):
bound = self._bound()
coord = _FakeCoordinator({"/x/vs/0": {"x.com.samsung.da.value": "1"}})
coord = _coord({"/x/vs/0": {"x.com.samsung.da.value": "1"}})
assert _is_included(bound, coord) is True
def test_excluded_when_field_absent_from_populated_rep(self):
bound = self._bound()
coord = _FakeCoordinator({"/x/vs/0": {"x.com.samsung.da.other": "1"}})
coord = _coord({"/x/vs/0": {"x.com.samsung.da.other": "1"}})
assert _is_included(bound, coord) is False
def test_included_on_true_stub(self):
bound = self._bound()
coord = _FakeCoordinator({"/x/vs/0": {"href": "/x/vs/0"}})
coord = _coord({"/x/vs/0": {"href": "/x/vs/0"}})
assert _is_included(bound, coord) is True
def test_included_on_genuinely_empty_rep(self):
@@ -60,12 +67,12 @@ class TestDefaultFieldGate:
exists_fn (e.g. common.ENERGY_METER) opts into excluding on
confirmed-empty, after verifying that's actually safe for its field."""
bound = self._bound()
coord = _FakeCoordinator({"/x/vs/0": {}})
coord = _coord({"/x/vs/0": {}})
assert _is_included(bound, coord) is True
def test_excluded_when_href_missing_from_resources(self):
bound = self._bound()
coord = _FakeCoordinator({})
coord = _coord({})
assert _is_included(bound, coord) is False
@@ -77,9 +84,9 @@ class TestExplicitExistsFnGate:
exists_fn=lambda rep, resources: rep.get("flag") is True,
)
bound = _bound(desc, "/x/vs/0")
coord = _FakeCoordinator({"/x/vs/0": {"flag": True}})
coord = _coord({"/x/vs/0": {"flag": True}})
assert _is_included(bound, coord) is True
coord = _FakeCoordinator({"/x/vs/0": {"flag": False, "x.com.samsung.da.value": "1"}})
coord = _coord({"/x/vs/0": {"flag": False, "x.com.samsung.da.value": "1"}})
assert _is_included(bound, coord) is False
@@ -87,5 +94,5 @@ class TestNoFieldEntities:
def test_rep_fn_entity_always_included(self):
desc = SensorDesc(key="x", rep_fn=lambda rep: rep.get("x.com.samsung.da.value"))
bound = _bound(desc, "/x/vs/0")
coord = _FakeCoordinator({"/x/vs/0": {}})
coord = _coord({"/x/vs/0": {}})
assert _is_included(bound, coord) is True