Require explicit feature type (#1006)

Explicit > implicit. Having this previously would have avoided using a
wrong type for water_alert in the first place.
This commit is contained in:
Teemu R
2024-06-25 18:30:36 +02:00
committed by GitHub
parent 5846bbdbbb
commit 0f5bafaa43
15 changed files with 45 additions and 10 deletions

View File

@@ -44,8 +44,11 @@ def test_feature_api(dummy_feature: Feature):
assert dummy_feature.unit == "dummyunit"
def test_feature_missing_type():
"""Test that creating a feature with a setter but without type causes an error."""
@pytest.mark.parametrize(
"read_only_type", [Feature.Type.Sensor, Feature.Type.BinarySensor]
)
def test_feature_setter_on_sensor(read_only_type):
"""Test that creating a sensor feature with a setter causes an error."""
with pytest.raises(ValueError):
Feature(
device=DummyDevice(), # type: ignore[arg-type]
@@ -53,6 +56,7 @@ def test_feature_missing_type():
name="dummy error",
attribute_getter="dummygetter",
attribute_setter="dummysetter",
type=read_only_type,
)