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
@@ -1,17 +1,18 @@
|
||||
"""Tests for dryer support and washer/dryer consistency (issue #14)."""
|
||||
|
||||
from custom_components.localthings.registry.adapter import flatten
|
||||
from custom_components.localthings.registry.by_type import for_device_by_model
|
||||
from custom_components.localthings.registry.capabilities import dryer, ignored, laundry
|
||||
from custom_components.localthings.registry.discovery import discover
|
||||
|
||||
from tests.conftest import _load_device
|
||||
|
||||
|
||||
def _dryer():
|
||||
resources = _load_device('dryer')
|
||||
info = resources['/information/vs/0']
|
||||
resources = _load_device("dryer")
|
||||
info = resources["/information/vs/0"]
|
||||
reg = for_device_by_model(
|
||||
info['x.com.samsung.da.modelNum'], info['x.com.samsung.da.description'],
|
||||
info["x.com.samsung.da.modelNum"],
|
||||
info["x.com.samsung.da.description"],
|
||||
)
|
||||
return reg, resources
|
||||
|
||||
@@ -24,7 +25,7 @@ def _state():
|
||||
|
||||
def test_dryer_model_resolves_to_dryer_registry():
|
||||
reg, _ = _dryer()
|
||||
assert reg is not None and reg.name == 'dryer'
|
||||
assert reg is not None and reg.name == "dryer"
|
||||
|
||||
|
||||
def test_no_unbound_hrefs():
|
||||
@@ -38,8 +39,16 @@ def test_no_unbound_hrefs():
|
||||
|
||||
def test_expected_entities_present():
|
||||
state = _state()
|
||||
for key in ('buzzer_sound', 'cycle', 'power_switch', 'child_lock',
|
||||
'remote_control', 'dry_level', 'wrinkle_prevent', 'energy_kwh'):
|
||||
for key in (
|
||||
"buzzer_sound",
|
||||
"cycle",
|
||||
"power_switch",
|
||||
"child_lock",
|
||||
"remote_control",
|
||||
"dry_level",
|
||||
"wrinkle_prevent",
|
||||
"energy_kwh",
|
||||
):
|
||||
assert key in state, key
|
||||
|
||||
|
||||
@@ -47,15 +56,15 @@ def test_job_beginning_status_reads_current_status():
|
||||
"""The dump carries x.com.samsung.da.currentStatus (not the old
|
||||
jobBeginingStatus field the dryer descriptor used to read), so the sensor
|
||||
is populated instead of blank."""
|
||||
assert _state()['job_beginning_status'] == 'None' # the dump's currentStatus value
|
||||
assert _state()["job_beginning_status"] == "None" # the dump's currentStatus value
|
||||
|
||||
|
||||
def test_power_watts_gated_for_dead_sentinel():
|
||||
"""instantaneousPower is the dead '-500' sentinel on this dryer, so the
|
||||
misleading 0 W power sensor is suppressed; cumulative energy still shows."""
|
||||
state = _state()
|
||||
assert 'power_watts' not in state
|
||||
assert 'energy_kwh' in state
|
||||
assert "power_watts" not in state
|
||||
assert "energy_kwh" in state
|
||||
|
||||
|
||||
def test_course_bound_to_shared_course_vs_0():
|
||||
@@ -64,20 +73,20 @@ def test_course_bound_to_shared_course_vs_0():
|
||||
laundry.cycle_select) -- confirmed dryers report Table_03, matching
|
||||
the shipped dryer_cycle_table_03 translations, consistent with
|
||||
washer/dishwasher."""
|
||||
assert dryer.DRYER_COURSE.href == '/course/vs/0'
|
||||
desc = next(e for e in dryer.DRYER_COURSE.entities if e.key == 'cycle')
|
||||
assert dryer.DRYER_COURSE.href == "/course/vs/0"
|
||||
desc = next(e for e in dryer.DRYER_COURSE.entities if e.key == "cycle")
|
||||
assert callable(desc.translation_key)
|
||||
table_03 = {'/st/dryercourse/vs/0': {'x.com.samsung.da.st.courseTable': 'Table_03'}}
|
||||
assert desc.translation_key(table_03) == 'dryer_cycle_table_03'
|
||||
assert desc.translation_key({}) == 'cycle'
|
||||
table_03 = {"/st/dryercourse/vs/0": {"x.com.samsung.da.st.courseTable": "Table_03"}}
|
||||
assert desc.translation_key(table_03) == "dryer_cycle_table_03"
|
||||
assert desc.translation_key({}) == "cycle"
|
||||
assert desc.options is laundry.cycle_options
|
||||
rep = {'x.com.samsung.da.options': ['Course_16', 'GMT_02']}
|
||||
assert desc.rep_fn(rep) == '16'
|
||||
rep = {"x.com.samsung.da.options": ["Course_16", "GMT_02"]}
|
||||
assert desc.rep_fn(rep) == "16"
|
||||
|
||||
|
||||
def test_st_dryercourse_is_ignored():
|
||||
"""/st/dryercourse/vs/0 re-encodes the course exposed via /course/vs/0 and
|
||||
is globally ignored -- the mirror of /st/washercourse/vs/0."""
|
||||
ignored_hrefs = {c.href for c in ignored.IGNORED}
|
||||
assert '/st/dryercourse/vs/0' in ignored_hrefs
|
||||
assert '/st/washercourse/vs/0' in ignored_hrefs
|
||||
assert "/st/dryercourse/vs/0" in ignored_hrefs
|
||||
assert "/st/washercourse/vs/0" in ignored_hrefs
|
||||
Reference in new issue
Block a user