Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion miio/integrations/dmaker/fan/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def __init__(
debug: int = 0,
lazy_discover: bool = True,
timeout: Optional[int] = None,
model: str = MODEL_FAN_P5,
*,
model: Optional[str] = MODEL_FAN_P5,
) -> None:
super().__init__(
ip, token, start_id, debug, lazy_discover, timeout=timeout, model=model
Expand Down
3 changes: 2 additions & 1 deletion miio/integrations/dmaker/fan/fan_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ def __init__(
debug: int = 0,
lazy_discover: bool = True,
timeout: Optional[int] = None,
model: str = MODEL_FAN_1C,
*,
model: Optional[str] = MODEL_FAN_1C,
) -> None:
super().__init__(
ip, token, start_id, debug, lazy_discover, timeout=timeout, model=model
Expand Down
3 changes: 2 additions & 1 deletion miio/integrations/huayi/light/huizuo.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def __init__(
debug: int = 0,
lazy_discover: bool = True,
timeout: Optional[int] = None,
model: str = MODEL_HUIZUO_PIS123,
*,
model: Optional[str] = MODEL_HUIZUO_PIS123,
) -> None:
if model in MODELS_WITH_FAN_WY:
self.mapping.update(_ADDITIONAL_MAPPING_FAN_WY)
Expand Down
3 changes: 2 additions & 1 deletion miio/integrations/lumi/acpartner/airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def __init__(
debug: int = 0,
lazy_discover: bool = True,
timeout: Optional[int] = None,
model: str = MODEL_ACPARTNER_V2,
*,
model: Optional[str] = MODEL_ACPARTNER_V2,
) -> None:
super().__init__(
ip, token, start_id, debug, lazy_discover, timeout=timeout, model=model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def __init__(
debug: int = 0,
lazy_discover: bool = True,
timeout: Optional[int] = None,
model: str = MODEL_ACPARTNER_MCN02,
*,
model: Optional[str] = MODEL_ACPARTNER_MCN02,
) -> None:
if start_id is None:
start_id = random.randint(0, 999) # nosec
Expand Down
1 change: 1 addition & 0 deletions miio/integrations/yeelight/light/yeelight.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def __init__(
debug: int = 0,
lazy_discover: bool = True,
timeout: Optional[int] = None,
*,
model: Optional[str] = None,
) -> None:
super().__init__(
Expand Down
22 changes: 22 additions & 0 deletions miio/tests/test_device.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import math

import pytest
Expand Down Expand Up @@ -162,6 +163,27 @@ def test_init_signature(cls, mocker):
assert total_args == 8


@pytest.mark.parametrize("cls", DEVICE_CLASSES)
def test_model_is_keyword_only(cls: type) -> None:
"""Ensure 'model' is keyword-only in all Device subclasses.

The base Device class defines model as keyword-only (after *). Subclasses
that make it positional break Liskov substitution and can cause subtle bugs
when classes are used interchangeably via DeviceFactory.
"""
sig: inspect.Signature = inspect.signature(cls.__init__)
params: dict[str, inspect.Parameter] = dict(sig.parameters)

if "model" not in params:
return

param: inspect.Parameter = params["model"]
assert param.kind == inspect.Parameter.KEYWORD_ONLY, (
f"{cls.__name__}.__init__ has 'model' as positional parameter, "
f"it should be keyword-only (after *)"
)


@pytest.mark.parametrize("cls", DEVICE_CLASSES)
def test_status_return_type(cls):
"""Make sure that all status methods have a type hint."""
Expand Down
Loading