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
@@ -2,17 +2,17 @@
|
||||
issue #210) -- a standalone, battery-powered air-quality sensor puck. No
|
||||
controllable appliance state at all beyond the do-not-disturb window.
|
||||
"""
|
||||
|
||||
from datetime import time as dt_time
|
||||
|
||||
from custom_components.localthings.registry.adapter import flatten
|
||||
from custom_components.localthings.registry.by_type import for_device_by_oic_type, resolve
|
||||
from custom_components.localthings.registry.discovery import discover
|
||||
|
||||
from tests.conftest import _load_device
|
||||
|
||||
|
||||
def _air_monitor():
|
||||
resources = _load_device('air_monitor')
|
||||
resources = _load_device("air_monitor")
|
||||
reg = resolve(resources)
|
||||
return reg, resources
|
||||
|
||||
@@ -34,15 +34,15 @@ def _desc(key):
|
||||
|
||||
def test_resolves_to_air_monitor_registry():
|
||||
reg, _ = _air_monitor()
|
||||
assert reg is not None and reg.name == 'air_monitor'
|
||||
assert reg is not None and reg.name == "air_monitor"
|
||||
|
||||
|
||||
def test_resolves_via_oic_type_too():
|
||||
"""This board's real dump carries /oic/d's device type
|
||||
('x.com.st.d.airqualitysensor') as well as the 'ASM' modelNum token --
|
||||
both paths must agree."""
|
||||
reg = for_device_by_oic_type(('x.com.st.d.airqualitysensor',))
|
||||
assert reg is not None and reg.name == 'air_monitor'
|
||||
reg = for_device_by_oic_type(("x.com.st.d.airqualitysensor",))
|
||||
assert reg is not None and reg.name == "air_monitor"
|
||||
|
||||
|
||||
def test_no_unbound_hrefs():
|
||||
@@ -57,12 +57,12 @@ def test_air_quality_sensors_read_from_shared_items_decode():
|
||||
decode air_purifier.AIR_QUALITY already uses -- this board adds CO2,
|
||||
which neither air_purifier nor range_hood report."""
|
||||
state = _state()
|
||||
assert state['dust'] == 31
|
||||
assert state['fine_dust'] == 23
|
||||
assert state['super_fine_dust'] == 18
|
||||
assert state['odor'] == 1
|
||||
assert state['clean_level'] == 2
|
||||
assert state['co2'] == 498
|
||||
assert state["dust"] == 31
|
||||
assert state["fine_dust"] == 23
|
||||
assert state["super_fine_dust"] == 18
|
||||
assert state["odor"] == 1
|
||||
assert state["clean_level"] == 2
|
||||
assert state["co2"] == 498
|
||||
|
||||
|
||||
def test_second_value_slot_is_not_exposed():
|
||||
@@ -72,27 +72,27 @@ def test_second_value_slot_is_not_exposed():
|
||||
nothing' rule, only the raw reading (value[0]) is bound, not a second
|
||||
'dust_level' or similar entity for that code."""
|
||||
state = _state()
|
||||
assert 'dust_level' not in state
|
||||
assert 'dust_grade' not in state
|
||||
assert "dust_level" not in state
|
||||
assert "dust_grade" not in state
|
||||
|
||||
|
||||
def test_humidity_and_battery_present():
|
||||
state = _state()
|
||||
assert state['humidity'] == 57
|
||||
assert state['battery'] == 80
|
||||
assert state['battery_charging'] is False
|
||||
assert state["humidity"] == 57
|
||||
assert state["battery"] == 80
|
||||
assert state["battery_charging"] is False
|
||||
|
||||
|
||||
def test_air_quality_standard_present():
|
||||
state = _state()
|
||||
assert state['air_quality_standard'] == 'AirCleanAssociation'
|
||||
assert state["air_quality_standard"] == "AirCleanAssociation"
|
||||
|
||||
|
||||
def test_dnd_read_contract():
|
||||
state = _state()
|
||||
assert state['dnd'] is False
|
||||
assert state['dnd_start'] == dt_time(14, 0)
|
||||
assert state['dnd_end'] == dt_time(22, 0)
|
||||
assert state["dnd"] is False
|
||||
assert state["dnd_start"] == dt_time(14, 0)
|
||||
assert state["dnd_end"] == dt_time(22, 0)
|
||||
|
||||
|
||||
def test_dnd_write_contracts_are_flagged_educated_guesses():
|
||||
@@ -102,14 +102,14 @@ def test_dnd_write_contracts_are_flagged_educated_guesses():
|
||||
string/time-format shape, not invented from nothing, but still
|
||||
unconfirmed on real hardware. Only the wiring is tested here; whether
|
||||
the device actually accepts these writes needs a reporter to confirm."""
|
||||
dnd = _desc('dnd')
|
||||
path, body = dnd.write_fn('On', {})
|
||||
assert path == ['dnd', 'vs', '0']
|
||||
assert body == {'x.com.samsung.da.value': 'true'}
|
||||
path, body = dnd.write_fn('Off', {})
|
||||
assert body == {'x.com.samsung.da.value': 'false'}
|
||||
dnd = _desc("dnd")
|
||||
path, body = dnd.write_fn("On", {})
|
||||
assert path == ["dnd", "vs", "0"]
|
||||
assert body == {"x.com.samsung.da.value": "true"}
|
||||
path, body = dnd.write_fn("Off", {})
|
||||
assert body == {"x.com.samsung.da.value": "false"}
|
||||
|
||||
start = _desc('dnd_start')
|
||||
start = _desc("dnd_start")
|
||||
path, body = start.write_fn(dt_time(9, 30), {})
|
||||
assert path == ['dnd', 'vs', '0']
|
||||
assert body == {'x.com.samsung.da.startTime': '09:30:00'}
|
||||
assert path == ["dnd", "vs", "0"]
|
||||
assert body == {"x.com.samsung.da.startTime": "09:30:00"}
|
||||
Reference in new issue
Block a user