Add generic typing support to features

This commit is contained in:
sdb9696
2024-05-21 16:03:21 +01:00
parent 5e619af29f
commit a3a5c5df55
11 changed files with 149 additions and 24 deletions

View File

@@ -1,5 +1,9 @@
import pytest
from typing import TYPE_CHECKING
import pytest
from typing_extensions import assert_type
from kasa import Feature
from kasa.iot import IotDevice
from kasa.smart import SmartDevice
from kasa.tests.conftest import dimmable_iot, parametrize
@@ -16,7 +20,9 @@ async def test_brightness_component(dev: SmartDevice):
assert "brightness" in dev._components
# Test getting the value
feature = dev.features["brightness"]
feature = dev.features[Feature.Id.BRIGHTNESS]
if TYPE_CHECKING:
assert_type(feature.value, int)
assert isinstance(feature.value, int)
assert feature.value > 1 and feature.value <= 100

View File

@@ -18,7 +18,7 @@ class DummyDevice:
def dummy_feature() -> Feature:
# create_autospec for device slows tests way too much, so we use a dummy here
feat = Feature(
feat: Feature = Feature(
device=DummyDevice(), # type: ignore[arg-type]
id="dummy_feature",
name="dummy_feature",