Skip to content

Commit 2286e58

Browse files
authored
Make sure miotdevice implementations define supported models (#1345)
* Add zhimi.fan.za5 as supported to zhimi_miot * Make sure miotdevice implementations define supported models Add model information to: * CurtainMiot * Huizuo * FanMiot, Fan1C * FanZA5 * RoidmiVacuumMiot * YeelightDualControlModule
1 parent 7cc167f commit 2286e58

8 files changed

Lines changed: 15 additions & 3 deletions

File tree

miio/curtain_youpin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class CurtainMiot(MiotDevice):
115115
"""Main class representing the lumi.curtain.hagl05 curtain."""
116116

117117
mapping = _MAPPING
118+
_supported_models = ["lumi.curtain.hagl05"]
118119

119120
@command(
120121
default_output=format_output(

miio/heater_miot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class HeaterMiot(MiotDevice):
143143
(zhimi.heater.za2)."""
144144

145145
_mappings = _MAPPINGS
146+
_supported_models = list(_MAPPINGS.keys())
146147

147148
@command(
148149
default_output=format_output(

miio/huizuo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class Huizuo(MiotDevice):
211211
"""
212212

213213
mapping = _MAPPING
214+
_supported_models = MODELS_SUPPORTED
214215

215216
def __init__(
216217
self,

miio/integrations/fan/dmaker/fan_miot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ def child_lock(self) -> bool:
231231

232232
class FanMiot(MiotDevice):
233233
_mappings = MIOT_MAPPING
234+
# TODO Fan1C should be merged to FanMiot
235+
_supported_models = list(set(MIOT_MAPPING) - {MODEL_FAN_1C})
234236

235237
@command(
236238
default_output=format_output(
@@ -372,6 +374,7 @@ def set_rotate(self, direction: MoveDirection):
372374

373375
class Fan1C(MiotDevice):
374376
mapping = MIOT_MAPPING[MODEL_FAN_1C]
377+
_supported_models = [MODEL_FAN_1C]
375378

376379
def __init__(
377380
self,

miio/integrations/fan/zhimi/zhimi_miot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def temperature(self) -> Any:
170170

171171
class FanZA5(MiotDevice):
172172
mapping = MIOT_MAPPING
173+
_supported_models = list(MIOT_MAPPING.keys())
173174

174175
@command(
175176
default_output=format_output(

miio/integrations/vacuum/roidmi/roidmivacuum_miot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ class RoidmiVacuumMiot(MiotDevice):
536536
"""Interface for Vacuum Eve Plus (roidmi.vacuum.v60)"""
537537

538538
mapping = _MAPPING
539+
_supported_models = ["roidmi.vacuum.v60"]
539540

540541
@command()
541542
def status(self) -> RoidmiVacuumStatus:

miio/tests/test_device.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from miio import Device, MiotDevice, RoborockVacuum
66
from miio.exceptions import DeviceInfoUnavailableException, PayloadDecodeException
77

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

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

103105

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

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

115118

116-
@pytest.mark.parametrize("cls", Device.__subclasses__())
119+
@pytest.mark.parametrize("cls", DEVICE_CLASSES)
117120
def test_device_supported_models(cls):
118121
"""Make sure that every device subclass has a non-empty supported models."""
119122
if cls.__name__ == "MiotDevice": # skip miotdevice

miio/yeelight_dual_switch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class YeelightDualControlModule(MiotDevice):
108108
which uses MIoT protocol."""
109109

110110
mapping = _MAPPING
111+
_supported_models = ["yeelink.switch.sw1"]
111112

112113
@command(
113114
default_output=format_output(

0 commit comments

Comments
 (0)