Add ruff (lint + format) and ty (type checking) to the project
Adds [tool.ruff] and [tool.ty] config to pyproject.toml with a curated ruff rule set (E, F, W, I, UP, B, C4, SIM, RUF, ASYNC, LOG, G, PIE, RET, PERF, N), pins ruff/ty in requirements-dev.txt, reformats the whole tree with `ruff format`, and fixes the pre-existing lint and type-check debt those tools surfaced so both run clean. Production-code type fixes include: HA's ConfigFlowResult vs. the generic FlowResult in config_flow.py, narrowing BoundEntity.desc to its platform-specific subclass (SelectDesc/NumberDesc/SensorDesc/etc.) via cast() instead of an unchecked annotation, converting HA device_class strings to their proper enum types, a resolve_registry callback typed as `object` instead of `DeviceRegistry | None`, and a couple of other narrow correctness fixes (CA key type validation, an index-out-of-bounds false positive from an empty-tuple fallback, a bool/dict argument swap). Test-file fixes are mechanical: narrowing SamsungEntityDescription to the correct subclass via isinstance()/cast() before accessing subclass-only fields, and asserting Optional write_fn/unit_fn fields are set before calling them.
This commit is contained in:
147 files changed
+9977
-7584
No files matched your search
@@ -5,31 +5,32 @@ ice-maker resources (/icemaker/one/vs/0, /icemaker/two/vs/0) use named path
|
||||
segments rather than numeric indices, so they are modelled via DOOR_GENERIC
|
||||
pattern capability that auto-derives distinct keys from the href segments.
|
||||
"""
|
||||
from tests.conftest import _load_resources
|
||||
|
||||
from custom_components.localthings.registry.adapter import _key
|
||||
from custom_components.localthings.registry.by_type import refrigerator
|
||||
from custom_components.localthings.registry.discovery import discover
|
||||
from tests.conftest import _load_resources
|
||||
|
||||
|
||||
def test_two_doors_get_distinct_keys():
|
||||
resources = _load_resources('10.0.0.254')
|
||||
resources = _load_resources("10.0.0.254")
|
||||
reg = refrigerator.REGISTRY
|
||||
bound = discover(resources, reg.capabilities, reg.pattern_capabilities)
|
||||
door_keys = sorted(_key(b) for b in bound if _key(b).startswith('door'))
|
||||
door_keys = sorted(_key(b) for b in bound if _key(b).startswith("door"))
|
||||
# at least the two physical doors (cooler + freezer) produce distinct keys
|
||||
assert len(set(door_keys)) >= 2, f"Expected >= 2 distinct door keys, got: {door_keys}"
|
||||
|
||||
|
||||
def test_two_iceMakers_get_distinct_keys():
|
||||
resources = _load_resources('10.0.0.254')
|
||||
def test_two_ice_makers_get_distinct_keys():
|
||||
resources = _load_resources("10.0.0.254")
|
||||
reg = refrigerator.REGISTRY
|
||||
bound = discover(resources, reg.capabilities, reg.pattern_capabilities)
|
||||
ice_keys = sorted(_key(b) for b in bound if _key(b).startswith('icemaker_'))
|
||||
ice_keys = sorted(_key(b) for b in bound if _key(b).startswith("icemaker_"))
|
||||
# icemaker_one_* and icemaker_two_* are distinct
|
||||
ice_one_keys = [k for k in ice_keys if k.startswith('icemaker_one_')]
|
||||
ice_two_keys = [k for k in ice_keys if k.startswith('icemaker_two_')]
|
||||
ice_one_keys = [k for k in ice_keys if k.startswith("icemaker_one_")]
|
||||
ice_two_keys = [k for k in ice_keys if k.startswith("icemaker_two_")]
|
||||
assert ice_one_keys, "No icemaker_one_* keys found"
|
||||
assert ice_two_keys, "No icemaker_two_* keys found"
|
||||
assert set(ice_one_keys).isdisjoint(set(ice_two_keys)), \
|
||||
assert set(ice_one_keys).isdisjoint(set(ice_two_keys)), (
|
||||
f"icemaker_one and icemaker_two keys overlap: {ice_one_keys} vs {ice_two_keys}"
|
||||
)
|
||||
Reference in new issue
Block a user