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,6 +5,7 @@ protect this (see DESIGN-177.md section 3/6). Run over the entire fixture
|
||||
set, not just the two new subdevice fixtures, so a future dump -- subdevice-
|
||||
capable or not -- exercises it automatically.
|
||||
"""
|
||||
|
||||
from collections import Counter
|
||||
|
||||
import pytest
|
||||
@@ -12,12 +13,9 @@ import pytest
|
||||
from custom_components.localthings.entity import _is_included
|
||||
from custom_components.localthings.registry.adapter import _key
|
||||
from custom_components.localthings.registry.entities import PLATFORM_OF
|
||||
|
||||
from tests.conftest import FIXTURES, _discover_full, _load_device_full
|
||||
|
||||
_FIXTURE_NAMES = sorted(
|
||||
p.name[:-len('_device.json')] for p in FIXTURES.glob('*_device.json')
|
||||
)
|
||||
_FIXTURE_NAMES = sorted(p.name[: -len("_device.json")] for p in FIXTURES.glob("*_device.json"))
|
||||
|
||||
|
||||
class _FakeCoordinator:
|
||||
@@ -31,10 +29,11 @@ class _FakeCoordinator:
|
||||
|
||||
def canonical_resources(self, subdevice):
|
||||
from custom_components.localthings.registry.subdevices import canonical_view
|
||||
|
||||
return canonical_view(subdevice, self.last_resources, self._subdevices)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', _FIXTURE_NAMES)
|
||||
@pytest.mark.parametrize("name", _FIXTURE_NAMES)
|
||||
def test_key_is_unique_across_all_bound_entities(name):
|
||||
"""`_key(b)` only has to be unique among entities `_is_included` would
|
||||
actually register -- discover() alone can (deliberately) produce two
|
||||
@@ -53,8 +52,10 @@ def test_key_is_unique_across_all_bound_entities(name):
|
||||
BinarySensorDesc both named 'power_switch' on /power/0).
|
||||
"""
|
||||
resources, oic_res, seeds = _load_device_full(name)
|
||||
bound, materialized, skipped, full_resources, device_type_name = _discover_full(
|
||||
resources, oic_res, seeds,
|
||||
bound, materialized, _skipped, full_resources, _device_type_name = _discover_full(
|
||||
resources,
|
||||
oic_res,
|
||||
seeds,
|
||||
)
|
||||
coordinator = _FakeCoordinator(full_resources, materialized)
|
||||
included = [b for b in bound if _is_included(b, coordinator)]
|
||||
@@ -75,8 +76,7 @@ def test_subdevice_capable_fixtures_actually_exercise_a_subdevice():
|
||||
the two fixtures this design added actually produce a materialized
|
||||
subdevice, so that silent-vacuous-pass failure mode is caught here
|
||||
instead."""
|
||||
for name in ('airconditioner_artik051_dongle_fac_18k',
|
||||
'airconditioner_fac_bora_2in1'):
|
||||
for name in ("airconditioner_artik051_dongle_fac_18k", "airconditioner_fac_bora_2in1"):
|
||||
resources, oic_res, seeds = _load_device_full(name)
|
||||
_, materialized, _, _, _ = _discover_full(resources, oic_res, seeds)
|
||||
assert materialized, f"{name}: expected at least one materialized subdevice"
|
||||
Reference in new issue
Block a user