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

Remove unnecessary subclass constructors, deprecate subclasses only setting the model #1146

Merged
merged 3 commits into from
Sep 18, 2021
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
22 changes: 4 additions & 18 deletions miio/airdehumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,6 @@ def alarm(self) -> str:
class AirDehumidifier(Device):
"""Implementation of Xiaomi Mi Air Dehumidifier."""

def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_DEHUMIDIFIER_V1,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)

self.device_info: DeviceInfo

@command(
default_output=format_output(
"",
Expand All @@ -193,15 +180,14 @@ def __init__(
def status(self) -> AirDehumidifierStatus:
"""Retrieve properties."""

if self.device_info is None:
self.device_info = self.info()

properties = AVAILABLE_PROPERTIES[self.model]
properties = AVAILABLE_PROPERTIES.get(
self.model, AVAILABLE_PROPERTIES[MODEL_DEHUMIDIFIER_V1]
)

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

return AirDehumidifierStatus(
defaultdict(lambda: None, zip(properties, values)), self.device_info
defaultdict(lambda: None, zip(properties, values)), self.info()
)

@command(default_output=format_output("Powering on"))
Expand Down
19 changes: 7 additions & 12 deletions miio/airfresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .click_common import EnumType, command, format_output
from .device import Device, DeviceStatus
from .exceptions import DeviceException
from .utils import deprecated

_LOGGER = logging.getLogger(__name__)

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

def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_AIRFRESH_VA2,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)

@command(
default_output=format_output(
"",
Expand All @@ -254,7 +244,9 @@ def __init__(
def status(self) -> AirFreshStatus:
"""Retrieve properties."""

properties = AVAILABLE_PROPERTIES[self.model]
properties = AVAILABLE_PROPERTIES.get(
self.model, AVAILABLE_PROPERTIES[MODEL_AIRFRESH_VA2]
)
values = self.get_properties(properties, max_properties=15)

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


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

Expand Down
31 changes: 3 additions & 28 deletions miio/airfresh_t2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,6 @@ def display_orientation(self) -> Optional[DisplayOrientation]:
class AirFreshA1(Device):
"""Main class representing the air fresh a1."""

def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_AIRFRESH_A1,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)

@command(
default_output=format_output(
"",
Expand All @@ -257,7 +246,9 @@ def __init__(
def status(self) -> AirFreshStatus:
"""Retrieve properties."""

properties = AVAILABLE_PROPERTIES[self.model]
properties = AVAILABLE_PROPERTIES.get(
self.model, AVAILABLE_PROPERTIES[MODEL_AIRFRESH_A1]
)
values = self.get_properties(properties, max_properties=15)

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

def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_AIRFRESH_T2017,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)

@command(
default_output=format_output(
"",
Expand All @@ -400,11 +380,6 @@ def __init__(
"Display orientation: {result.display_orientation}\n",
)
)
def status(self) -> AirFreshStatus:
"""Retrieve properties."""

return super().status()

@command(
click.argument("speed", type=int),
default_output=format_output("Setting favorite speed to {speed}"),
Expand Down
26 changes: 8 additions & 18 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .click_common import EnumType, command, format_output
from .device import Device, DeviceInfo, DeviceStatus
from .exceptions import DeviceError, DeviceException
from .utils import deprecated

_LOGGER = logging.getLogger(__name__)

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

def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_HUMIDIFIER_V1,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)

# TODO: convert to use generic device info in the future
self.device_info: Optional[DeviceInfo] = None

@command(
default_output=format_output(
"",
Expand All @@ -284,10 +271,10 @@ def __init__(
)
def status(self) -> AirHumidifierStatus:
"""Retrieve properties."""
if self.device_info is None:
self.device_info = self.info()

properties = AVAILABLE_PROPERTIES[self.model]
properties = AVAILABLE_PROPERTIES.get(
self.model, AVAILABLE_PROPERTIES[MODEL_HUMIDIFIER_V1]
)

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

return AirHumidifierStatus(
defaultdict(lambda: None, zip(properties, values)), self.device_info
defaultdict(lambda: None, zip(properties, values)), self.info()
)

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


@deprecated("Use AirHumidifer(model='zhimi.humidifier.ca1")
class AirHumidifierCA1(AirHumidifier):
def __init__(
self,
Expand All @@ -421,6 +409,7 @@ def __init__(
)


@deprecated("Use AirHumidifer(model='zhimi.humidifier.cb1")
class AirHumidifierCB1(AirHumidifier):
def __init__(
self,
Expand All @@ -435,6 +424,7 @@ def __init__(
)


@deprecated("Use AirHumidifier(model='zhimi.humidifier.cb2')")
class AirHumidifierCB2(AirHumidifier):
def __init__(
self,
Expand Down
15 changes: 4 additions & 11 deletions miio/airhumidifier_mjjsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,7 @@ def wet_protection(self) -> Optional[bool]:


class AirHumidifierMjjsq(Device):
def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_HUMIDIFIER_MJJSQ,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)
"""Support for deerma.humidifier.(mj)jsq."""

@command(
default_output=format_output(
Expand All @@ -151,7 +142,9 @@ def __init__(
def status(self) -> AirHumidifierStatus:
"""Retrieve properties."""

properties = AVAILABLE_PROPERTIES[self.model]
properties = AVAILABLE_PROPERTIES.get(
self.model, AVAILABLE_PROPERTIES[MODEL_HUMIDIFIER_MJJSQ]
)
values = self.get_properties(properties, max_properties=1)

return AirHumidifierStatus(defaultdict(lambda: None, zip(properties, values)))
Expand Down
18 changes: 6 additions & 12 deletions miio/airpurifier_airdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .click_common import EnumType, command, format_output
from .device import Device, DeviceStatus
from .exceptions import DeviceException
from .utils import deprecated

_LOGGER = logging.getLogger(__name__)

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


class AirDogX3(Device):
def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_AIRDOG_X3,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)

@command(
default_output=format_output(
"",
Expand All @@ -126,7 +116,9 @@ def __init__(
def status(self) -> AirDogStatus:
"""Retrieve properties."""

properties = AVAILABLE_PROPERTIES[self.model]
properties = AVAILABLE_PROPERTIES.get(
self.model, AVAILABLE_PROPERTIES[MODEL_AIRDOG_X3]
)
values = self.get_properties(properties, max_properties=10)

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


class AirDogX5(AirDogX3):
@deprecated("Use AirDogX3(model='airdog.airpurifier.x5')")
def __init__(
self,
ip: str = None,
Expand All @@ -199,6 +192,7 @@ def __init__(


class AirDogX7SM(AirDogX3):
@deprecated("Use AirDogX3(model='airdog.airpurifier.x7sm')")
def __init__(
self,
ip: str = None,
Expand Down
20 changes: 3 additions & 17 deletions miio/airqualitymonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,6 @@ def tvoc(self) -> Optional[int]:
class AirQualityMonitor(Device):
"""Xiaomi PM2.5 Air Quality Monitor."""

def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_AIRQUALITYMONITOR_V1,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)

if model not in AVAILABLE_PROPERTIES:
_LOGGER.error(
"Device model %s unsupported. Falling back to %s.", model, self.model
)

@command(
default_output=format_output(
"",
Expand All @@ -185,7 +169,9 @@ def __init__(
)
def status(self) -> AirQualityMonitorStatus:
"""Return device status."""
properties = AVAILABLE_PROPERTIES[self.model]
properties = AVAILABLE_PROPERTIES.get(
self.model, AVAILABLE_PROPERTIES[MODEL_AIRQUALITYMONITOR_V1]
)

if self.model == MODEL_AIRQUALITYMONITOR_B1:
values = self.send("get_air_data")
Expand Down
15 changes: 3 additions & 12 deletions miio/fan_leshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ def error_detected(self) -> bool:
class FanLeshow(Device):
"""Main class representing the Xiaomi Rosou SS4 Ventilator."""

def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_FAN_LESHOW_SS4,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)

@command(
default_output=format_output(
"",
Expand All @@ -118,7 +107,9 @@ def __init__(
)
def status(self) -> FanLeshowStatus:
"""Retrieve properties."""
properties = AVAILABLE_PROPERTIES[self.model]
properties = AVAILABLE_PROPERTIES.get(
self.model, AVAILABLE_PROPERTIES[MODEL_FAN_LESHOW_SS4]
)
values = self.get_properties(properties, max_properties=15)

return FanLeshowStatus(dict(zip(properties, values)))
Expand Down
12 changes: 0 additions & 12 deletions miio/g1vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,6 @@ class G1Vacuum(MiotDevice):

mapping = MIOT_MAPPING[MIJIA_VACUUM_V2]

def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MIJIA_VACUUM_V2,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover)
self._model = model

@command(
default_output=format_output(
"",
Expand Down
Loading