Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure miotdevice implementations define supported models #1345

Merged
merged 2 commits into from
Mar 4, 2022
Merged
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
1 change: 1 addition & 0 deletions miio/curtain_youpin.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class CurtainMiot(MiotDevice):
"""Main class representing the lumi.curtain.hagl05 curtain."""

mapping = _MAPPING
_supported_models = ["lumi.curtain.hagl05"]

@command(
default_output=format_output(
Expand Down
1 change: 1 addition & 0 deletions miio/heater_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class HeaterMiot(MiotDevice):
(zhimi.heater.za2)."""

_mappings = _MAPPINGS
_supported_models = list(_MAPPINGS.keys())

@command(
default_output=format_output(
Expand Down
1 change: 1 addition & 0 deletions miio/huizuo.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class Huizuo(MiotDevice):
"""

mapping = _MAPPING
_supported_models = MODELS_SUPPORTED

def __init__(
self,
Expand Down
3 changes: 3 additions & 0 deletions miio/integrations/fan/dmaker/fan_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ def child_lock(self) -> bool:

class FanMiot(MiotDevice):
_mappings = MIOT_MAPPING
# TODO Fan1C should be merged to FanMiot
_supported_models = list(set(MIOT_MAPPING) - {MODEL_FAN_1C})

@command(
default_output=format_output(
Expand Down Expand Up @@ -372,6 +374,7 @@ def set_rotate(self, direction: MoveDirection):

class Fan1C(MiotDevice):
mapping = MIOT_MAPPING[MODEL_FAN_1C]
_supported_models = [MODEL_FAN_1C]

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions miio/integrations/fan/zhimi/zhimi_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def temperature(self) -> Any:

class FanZA5(MiotDevice):
mapping = MIOT_MAPPING
_supported_models = list(MIOT_MAPPING.keys())

@command(
default_output=format_output(
Expand Down
1 change: 1 addition & 0 deletions miio/integrations/vacuum/roidmi/roidmivacuum_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ class RoidmiVacuumMiot(MiotDevice):
"""Interface for Vacuum Eve Plus (roidmi.vacuum.v60)"""

mapping = _MAPPING
_supported_models = ["roidmi.vacuum.v60"]

@command()
def status(self) -> RoidmiVacuumStatus:
Expand Down
9 changes: 6 additions & 3 deletions miio/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from miio import Device, MiotDevice, RoborockVacuum
from miio.exceptions import DeviceInfoUnavailableException, PayloadDecodeException

DEVICE_CLASSES = Device.__subclasses__() + MiotDevice.__subclasses__() # type: ignore


@pytest.mark.parametrize("max_properties", [None, 1, 15])
def test_get_properties_splitting(mocker, max_properties):
Expand Down Expand Up @@ -101,10 +103,11 @@ def test_missing_supported(mocker, caplog, cls, hidden):
assert f"for class '{cls.__name__}'" in caplog.text


@pytest.mark.parametrize("cls", Device.__subclasses__())
@pytest.mark.parametrize("cls", DEVICE_CLASSES)
def test_device_ctor_model(cls):
"""Make sure that every device subclass ctor accepts model kwarg."""
ignore_classes = ["GatewayDevice", "CustomDevice"]
# TODO Huizuo implements custom model fallback, so it needs to be ignored for now
ignore_classes = ["GatewayDevice", "CustomDevice", "Huizuo"]
if cls.__name__ in ignore_classes:
return

Expand All @@ -113,7 +116,7 @@ def test_device_ctor_model(cls):
assert dev.model == dummy_model


@pytest.mark.parametrize("cls", Device.__subclasses__())
@pytest.mark.parametrize("cls", DEVICE_CLASSES)
def test_device_supported_models(cls):
"""Make sure that every device subclass has a non-empty supported models."""
if cls.__name__ == "MiotDevice": # skip miotdevice
Expand Down
1 change: 1 addition & 0 deletions miio/yeelight_dual_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class YeelightDualControlModule(MiotDevice):
which uses MIoT protocol."""

mapping = _MAPPING
_supported_models = ["yeelink.switch.sw1"]

@command(
default_output=format_output(
Expand Down