Skip to content

Commit 43d9eaf

Browse files
authored
Remove unnecessary subclass constructors, deprecate subclasses only setting the model (#1146)
* Remove unnecessary subclass constructors, deprecate subclasses only setting the model * Remove constructors that just called the super class constructor with the model information * Deprecate subclasses that were previously there to allow miiocli usage when no model parameter passing was possible * Move airdog deprecations to ctors to make tests pass * remove g1vacuum ctor
1 parent 48e45ae commit 43d9eaf

16 files changed

+62
-235
lines changed

miio/airdehumidifier.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,6 @@ def alarm(self) -> str:
158158
class AirDehumidifier(Device):
159159
"""Implementation of Xiaomi Mi Air Dehumidifier."""
160160

161-
def __init__(
162-
self,
163-
ip: str = None,
164-
token: str = None,
165-
start_id: int = 0,
166-
debug: int = 0,
167-
lazy_discover: bool = True,
168-
model: str = MODEL_DEHUMIDIFIER_V1,
169-
) -> None:
170-
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
171-
172-
self.device_info: DeviceInfo
173-
174161
@command(
175162
default_output=format_output(
176163
"",
@@ -193,15 +180,14 @@ def __init__(
193180
def status(self) -> AirDehumidifierStatus:
194181
"""Retrieve properties."""
195182

196-
if self.device_info is None:
197-
self.device_info = self.info()
198-
199-
properties = AVAILABLE_PROPERTIES[self.model]
183+
properties = AVAILABLE_PROPERTIES.get(
184+
self.model, AVAILABLE_PROPERTIES[MODEL_DEHUMIDIFIER_V1]
185+
)
200186

201187
values = self.get_properties(properties, max_properties=1)
202188

203189
return AirDehumidifierStatus(
204-
defaultdict(lambda: None, zip(properties, values)), self.device_info
190+
defaultdict(lambda: None, zip(properties, values)), self.info()
205191
)
206192

207193
@command(default_output=format_output("Powering on"))

miio/airfresh.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .click_common import EnumType, command, format_output
99
from .device import Device, DeviceStatus
1010
from .exceptions import DeviceException
11+
from .utils import deprecated
1112

1213
_LOGGER = logging.getLogger(__name__)
1314

@@ -218,17 +219,6 @@ def extra_features(self) -> Optional[int]:
218219
class AirFresh(Device):
219220
"""Main class representing the air fresh."""
220221

221-
def __init__(
222-
self,
223-
ip: str = None,
224-
token: str = None,
225-
start_id: int = 0,
226-
debug: int = 0,
227-
lazy_discover: bool = True,
228-
model: str = MODEL_AIRFRESH_VA2,
229-
) -> None:
230-
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
231-
232222
@command(
233223
default_output=format_output(
234224
"",
@@ -254,7 +244,9 @@ def __init__(
254244
def status(self) -> AirFreshStatus:
255245
"""Retrieve properties."""
256246

257-
properties = AVAILABLE_PROPERTIES[self.model]
247+
properties = AVAILABLE_PROPERTIES.get(
248+
self.model, AVAILABLE_PROPERTIES[MODEL_AIRFRESH_VA2]
249+
)
258250
values = self.get_properties(properties, max_properties=15)
259251

260252
return AirFreshStatus(
@@ -356,6 +348,9 @@ def set_ptc(self, ptc: bool):
356348
return self.send("set_ptc_state", ["off"])
357349

358350

351+
@deprecated(
352+
"This will be removed in the future, use AirFresh(..., model='zhimi.airfresh.va4'"
353+
)
359354
class AirFreshVA4(AirFresh):
360355
"""Main class representing the air fresh va4."""
361356

miio/airfresh_t2017.py

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,6 @@ def display_orientation(self) -> Optional[DisplayOrientation]:
224224
class AirFreshA1(Device):
225225
"""Main class representing the air fresh a1."""
226226

227-
def __init__(
228-
self,
229-
ip: str = None,
230-
token: str = None,
231-
start_id: int = 0,
232-
debug: int = 0,
233-
lazy_discover: bool = True,
234-
model: str = MODEL_AIRFRESH_A1,
235-
) -> None:
236-
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
237-
238227
@command(
239228
default_output=format_output(
240229
"",
@@ -257,7 +246,9 @@ def __init__(
257246
def status(self) -> AirFreshStatus:
258247
"""Retrieve properties."""
259248

260-
properties = AVAILABLE_PROPERTIES[self.model]
249+
properties = AVAILABLE_PROPERTIES.get(
250+
self.model, AVAILABLE_PROPERTIES[MODEL_AIRFRESH_A1]
251+
)
261252
values = self.get_properties(properties, max_properties=15)
262253

263254
return AirFreshStatus(defaultdict(lambda: None, zip(properties, values)))
@@ -366,17 +357,6 @@ def get_timer(self):
366357
class AirFreshT2017(AirFreshA1):
367358
"""Main class representing the air fresh t2017."""
368359

369-
def __init__(
370-
self,
371-
ip: str = None,
372-
token: str = None,
373-
start_id: int = 0,
374-
debug: int = 0,
375-
lazy_discover: bool = True,
376-
model: str = MODEL_AIRFRESH_T2017,
377-
) -> None:
378-
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
379-
380360
@command(
381361
default_output=format_output(
382362
"",
@@ -400,11 +380,6 @@ def __init__(
400380
"Display orientation: {result.display_orientation}\n",
401381
)
402382
)
403-
def status(self) -> AirFreshStatus:
404-
"""Retrieve properties."""
405-
406-
return super().status()
407-
408383
@command(
409384
click.argument("speed", type=int),
410385
default_output=format_output("Setting favorite speed to {speed}"),

miio/airhumidifier.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .click_common import EnumType, command, format_output
99
from .device import Device, DeviceInfo, DeviceStatus
1010
from .exceptions import DeviceError, DeviceException
11+
from .utils import deprecated
1112

1213
_LOGGER = logging.getLogger(__name__)
1314

@@ -246,20 +247,6 @@ def button_pressed(self) -> Optional[str]:
246247
class AirHumidifier(Device):
247248
"""Implementation of Xiaomi Mi Air Humidifier."""
248249

249-
def __init__(
250-
self,
251-
ip: str = None,
252-
token: str = None,
253-
start_id: int = 0,
254-
debug: int = 0,
255-
lazy_discover: bool = True,
256-
model: str = MODEL_HUMIDIFIER_V1,
257-
) -> None:
258-
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
259-
260-
# TODO: convert to use generic device info in the future
261-
self.device_info: Optional[DeviceInfo] = None
262-
263250
@command(
264251
default_output=format_output(
265252
"",
@@ -284,10 +271,10 @@ def __init__(
284271
)
285272
def status(self) -> AirHumidifierStatus:
286273
"""Retrieve properties."""
287-
if self.device_info is None:
288-
self.device_info = self.info()
289274

290-
properties = AVAILABLE_PROPERTIES[self.model]
275+
properties = AVAILABLE_PROPERTIES.get(
276+
self.model, AVAILABLE_PROPERTIES[MODEL_HUMIDIFIER_V1]
277+
)
291278

292279
# A single request is limited to 16 properties. Therefore the
293280
# properties are divided into multiple requests
@@ -304,7 +291,7 @@ def status(self) -> AirHumidifierStatus:
304291
values = self.get_properties(properties, max_properties=_props_per_request)
305292

306293
return AirHumidifierStatus(
307-
defaultdict(lambda: None, zip(properties, values)), self.device_info
294+
defaultdict(lambda: None, zip(properties, values)), self.info()
308295
)
309296

310297
@command(default_output=format_output("Powering on"))
@@ -407,6 +394,7 @@ def set_dry(self, dry: bool):
407394
return self.send("set_dry", ["off"])
408395

409396

397+
@deprecated("Use AirHumidifer(model='zhimi.humidifier.ca1")
410398
class AirHumidifierCA1(AirHumidifier):
411399
def __init__(
412400
self,
@@ -421,6 +409,7 @@ def __init__(
421409
)
422410

423411

412+
@deprecated("Use AirHumidifer(model='zhimi.humidifier.cb1")
424413
class AirHumidifierCB1(AirHumidifier):
425414
def __init__(
426415
self,
@@ -435,6 +424,7 @@ def __init__(
435424
)
436425

437426

427+
@deprecated("Use AirHumidifier(model='zhimi.humidifier.cb2')")
438428
class AirHumidifierCB2(AirHumidifier):
439429
def __init__(
440430
self,

miio/airhumidifier_mjjsq.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,7 @@ def wet_protection(self) -> Optional[bool]:
122122

123123

124124
class AirHumidifierMjjsq(Device):
125-
def __init__(
126-
self,
127-
ip: str = None,
128-
token: str = None,
129-
start_id: int = 0,
130-
debug: int = 0,
131-
lazy_discover: bool = True,
132-
model: str = MODEL_HUMIDIFIER_MJJSQ,
133-
) -> None:
134-
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
125+
"""Support for deerma.humidifier.(mj)jsq."""
135126

136127
@command(
137128
default_output=format_output(
@@ -151,7 +142,9 @@ def __init__(
151142
def status(self) -> AirHumidifierStatus:
152143
"""Retrieve properties."""
153144

154-
properties = AVAILABLE_PROPERTIES[self.model]
145+
properties = AVAILABLE_PROPERTIES.get(
146+
self.model, AVAILABLE_PROPERTIES[MODEL_HUMIDIFIER_MJJSQ]
147+
)
155148
values = self.get_properties(properties, max_properties=1)
156149

157150
return AirHumidifierStatus(defaultdict(lambda: None, zip(properties, values)))

miio/airpurifier_airdog.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .click_common import EnumType, command, format_output
99
from .device import Device, DeviceStatus
1010
from .exceptions import DeviceException
11+
from .utils import deprecated
1112

1213
_LOGGER = logging.getLogger(__name__)
1314

@@ -100,17 +101,6 @@ def hcho(self) -> Optional[int]:
100101

101102

102103
class AirDogX3(Device):
103-
def __init__(
104-
self,
105-
ip: str = None,
106-
token: str = None,
107-
start_id: int = 0,
108-
debug: int = 0,
109-
lazy_discover: bool = True,
110-
model: str = MODEL_AIRDOG_X3,
111-
) -> None:
112-
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
113-
114104
@command(
115105
default_output=format_output(
116106
"",
@@ -126,7 +116,9 @@ def __init__(
126116
def status(self) -> AirDogStatus:
127117
"""Retrieve properties."""
128118

129-
properties = AVAILABLE_PROPERTIES[self.model]
119+
properties = AVAILABLE_PROPERTIES.get(
120+
self.model, AVAILABLE_PROPERTIES[MODEL_AIRDOG_X3]
121+
)
130122
values = self.get_properties(properties, max_properties=10)
131123

132124
return AirDogStatus(defaultdict(lambda: None, zip(properties, values)))
@@ -186,6 +178,7 @@ def set_filters_cleaned(self):
186178

187179

188180
class AirDogX5(AirDogX3):
181+
@deprecated("Use AirDogX3(model='airdog.airpurifier.x5')")
189182
def __init__(
190183
self,
191184
ip: str = None,
@@ -199,6 +192,7 @@ def __init__(
199192

200193

201194
class AirDogX7SM(AirDogX3):
195+
@deprecated("Use AirDogX3(model='airdog.airpurifier.x7sm')")
202196
def __init__(
203197
self,
204198
ip: str = None,

miio/airqualitymonitor.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,6 @@ def tvoc(self) -> Optional[int]:
151151
class AirQualityMonitor(Device):
152152
"""Xiaomi PM2.5 Air Quality Monitor."""
153153

154-
def __init__(
155-
self,
156-
ip: str = None,
157-
token: str = None,
158-
start_id: int = 0,
159-
debug: int = 0,
160-
lazy_discover: bool = True,
161-
model: str = MODEL_AIRQUALITYMONITOR_V1,
162-
) -> None:
163-
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
164-
165-
if model not in AVAILABLE_PROPERTIES:
166-
_LOGGER.error(
167-
"Device model %s unsupported. Falling back to %s.", model, self.model
168-
)
169-
170154
@command(
171155
default_output=format_output(
172156
"",
@@ -185,7 +169,9 @@ def __init__(
185169
)
186170
def status(self) -> AirQualityMonitorStatus:
187171
"""Return device status."""
188-
properties = AVAILABLE_PROPERTIES[self.model]
172+
properties = AVAILABLE_PROPERTIES.get(
173+
self.model, AVAILABLE_PROPERTIES[MODEL_AIRQUALITYMONITOR_V1]
174+
)
189175

190176
if self.model == MODEL_AIRQUALITYMONITOR_B1:
191177
values = self.send("get_air_data")

miio/fan_leshow.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,6 @@ def error_detected(self) -> bool:
9393
class FanLeshow(Device):
9494
"""Main class representing the Xiaomi Rosou SS4 Ventilator."""
9595

96-
def __init__(
97-
self,
98-
ip: str = None,
99-
token: str = None,
100-
start_id: int = 0,
101-
debug: int = 0,
102-
lazy_discover: bool = True,
103-
model: str = MODEL_FAN_LESHOW_SS4,
104-
) -> None:
105-
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
106-
10796
@command(
10897
default_output=format_output(
10998
"",
@@ -118,7 +107,9 @@ def __init__(
118107
)
119108
def status(self) -> FanLeshowStatus:
120109
"""Retrieve properties."""
121-
properties = AVAILABLE_PROPERTIES[self.model]
110+
properties = AVAILABLE_PROPERTIES.get(
111+
self.model, AVAILABLE_PROPERTIES[MODEL_FAN_LESHOW_SS4]
112+
)
122113
values = self.get_properties(properties, max_properties=15)
123114

124115
return FanLeshowStatus(dict(zip(properties, values)))

miio/g1vacuum.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,6 @@ class G1Vacuum(MiotDevice):
275275

276276
mapping = MIOT_MAPPING[MIJIA_VACUUM_V2]
277277

278-
def __init__(
279-
self,
280-
ip: str = None,
281-
token: str = None,
282-
start_id: int = 0,
283-
debug: int = 0,
284-
lazy_discover: bool = True,
285-
model: str = MIJIA_VACUUM_V2,
286-
) -> None:
287-
super().__init__(ip, token, start_id, debug, lazy_discover)
288-
self._model = model
289-
290278
@command(
291279
default_output=format_output(
292280
"",

0 commit comments

Comments
 (0)