diff --git a/miio/airdehumidifier.py b/miio/airdehumidifier.py index 5fd8ccd04..2b5906241 100644 --- a/miio/airdehumidifier.py +++ b/miio/airdehumidifier.py @@ -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( "", @@ -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")) diff --git a/miio/airfresh.py b/miio/airfresh.py index e346c8140..084322c01 100644 --- a/miio/airfresh.py +++ b/miio/airfresh.py @@ -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__) @@ -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( "", @@ -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( @@ -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.""" diff --git a/miio/airfresh_t2017.py b/miio/airfresh_t2017.py index 2843c6a19..1bf6800c4 100644 --- a/miio/airfresh_t2017.py +++ b/miio/airfresh_t2017.py @@ -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( "", @@ -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))) @@ -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( "", @@ -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}"), diff --git a/miio/airhumidifier.py b/miio/airhumidifier.py index c46856b30..fc69c31d8 100644 --- a/miio/airhumidifier.py +++ b/miio/airhumidifier.py @@ -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__) @@ -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( "", @@ -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 @@ -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")) @@ -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, @@ -421,6 +409,7 @@ def __init__( ) +@deprecated("Use AirHumidifer(model='zhimi.humidifier.cb1") class AirHumidifierCB1(AirHumidifier): def __init__( self, @@ -435,6 +424,7 @@ def __init__( ) +@deprecated("Use AirHumidifier(model='zhimi.humidifier.cb2')") class AirHumidifierCB2(AirHumidifier): def __init__( self, diff --git a/miio/airhumidifier_mjjsq.py b/miio/airhumidifier_mjjsq.py index 51ef7a8cb..454deff07 100644 --- a/miio/airhumidifier_mjjsq.py +++ b/miio/airhumidifier_mjjsq.py @@ -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( @@ -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))) diff --git a/miio/airpurifier_airdog.py b/miio/airpurifier_airdog.py index c8bfaa64c..9ce047a58 100644 --- a/miio/airpurifier_airdog.py +++ b/miio/airpurifier_airdog.py @@ -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__) @@ -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( "", @@ -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))) @@ -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, @@ -199,6 +192,7 @@ def __init__( class AirDogX7SM(AirDogX3): + @deprecated("Use AirDogX3(model='airdog.airpurifier.x7sm')") def __init__( self, ip: str = None, diff --git a/miio/airqualitymonitor.py b/miio/airqualitymonitor.py index 0f3b92ff4..5d97db0a4 100644 --- a/miio/airqualitymonitor.py +++ b/miio/airqualitymonitor.py @@ -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( "", @@ -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") diff --git a/miio/fan_leshow.py b/miio/fan_leshow.py index 2c03daa26..4b083f421 100644 --- a/miio/fan_leshow.py +++ b/miio/fan_leshow.py @@ -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( "", @@ -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))) diff --git a/miio/g1vacuum.py b/miio/g1vacuum.py index 10652ac14..bc9307108 100644 --- a/miio/g1vacuum.py +++ b/miio/g1vacuum.py @@ -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( "", diff --git a/miio/heater.py b/miio/heater.py index 5fd366b66..e0c98518f 100644 --- a/miio/heater.py +++ b/miio/heater.py @@ -127,17 +127,6 @@ def delay_off_countdown(self) -> Optional[int]: class Heater(Device): """Main class representing the Smartmi Zhimi Heater.""" - def __init__( - self, - ip: str = None, - token: str = None, - start_id: int = 0, - debug: int = 0, - lazy_discover: bool = True, - model: str = MODEL_HEATER_ZA1, - ) -> None: - super().__init__(ip, token, start_id, debug, lazy_discover, model=model) - @command( default_output=format_output( "", @@ -153,7 +142,9 @@ def __init__( ) def status(self) -> HeaterStatus: """Retrieve properties.""" - properties = SUPPORTED_MODELS[self.model]["available_properties"] + properties = SUPPORTED_MODELS.get( + self.model, SUPPORTED_MODELS[MODEL_HEATER_ZA1] + )["available_properties"] # A single request is limited to 16 properties. Therefore the # properties are divided into multiple requests @@ -185,7 +176,9 @@ def set_target_temperature(self, temperature: int): """Set target temperature.""" min_temp: int max_temp: int - min_temp, max_temp = SUPPORTED_MODELS[self.model]["temperature_range"] + min_temp, max_temp = SUPPORTED_MODELS.get( + self.model, SUPPORTED_MODELS[MODEL_HEATER_ZA1] + )["temperature_range"] if not min_temp <= temperature <= max_temp: raise HeaterException("Invalid target temperature: %s" % temperature) @@ -233,7 +226,9 @@ def delay_off(self, seconds: int): """Set delay off seconds.""" min_delay: int max_delay: int - min_delay, max_delay = SUPPORTED_MODELS[self.model]["delay_off_range"] + min_delay, max_delay = SUPPORTED_MODELS.get( + self.model, SUPPORTED_MODELS[MODEL_HEATER_ZA1] + )["delay_off_range"] if not min_delay <= seconds <= max_delay: raise HeaterException("Invalid delay time: %s" % seconds) diff --git a/miio/philips_bulb.py b/miio/philips_bulb.py index 2b409c789..a70a0ef26 100644 --- a/miio/philips_bulb.py +++ b/miio/philips_bulb.py @@ -68,17 +68,6 @@ def delay_off_countdown(self) -> int: class PhilipsWhiteBulb(Device): """Main class representing Xiaomi Philips White LED Ball Lamp.""" - def __init__( - self, - ip: str = None, - token: str = None, - start_id: int = 0, - debug: int = 0, - lazy_discover: bool = True, - model: str = MODEL_PHILIPS_LIGHT_HBULB, - ) -> None: - super().__init__(ip, token, start_id, debug, lazy_discover, model=model) - @command( default_output=format_output( "", @@ -92,7 +81,9 @@ def __init__( def status(self) -> PhilipsBulbStatus: """Retrieve properties.""" - properties = AVAILABLE_PROPERTIES[self.model] + properties = AVAILABLE_PROPERTIES.get( + self.model, AVAILABLE_PROPERTIES[MODEL_PHILIPS_LIGHT_HBULB] + ) values = self.get_properties(properties) return PhilipsBulbStatus(defaultdict(lambda: None, zip(properties, values))) @@ -134,17 +125,6 @@ def delay_off(self, seconds: int): class PhilipsBulb(PhilipsWhiteBulb): - def __init__( - self, - ip: str = None, - token: str = None, - start_id: int = 0, - debug: int = 0, - lazy_discover: bool = True, - model: str = MODEL_PHILIPS_LIGHT_BULB, - ) -> None: - super().__init__(ip, token, start_id, debug, lazy_discover, model=model) - @command( click.argument("level", type=int), default_output=format_output("Setting color temperature to {level}"), diff --git a/miio/philips_rwread.py b/miio/philips_rwread.py index ff6d4b355..9b1b42a81 100644 --- a/miio/philips_rwread.py +++ b/miio/philips_rwread.py @@ -83,17 +83,6 @@ def child_lock(self) -> bool: class PhilipsRwread(Device): """Main class representing Xiaomi Philips RW Read.""" - def __init__( - self, - ip: str = None, - token: str = None, - start_id: int = 0, - debug: int = 0, - lazy_discover: bool = True, - model: str = MODEL_PHILIPS_LIGHT_RWREAD, - ) -> None: - super().__init__(ip, token, start_id, debug, lazy_discover, model=model) - @command( default_output=format_output( "", @@ -108,7 +97,9 @@ def __init__( ) def status(self) -> PhilipsRwreadStatus: """Retrieve properties.""" - properties = AVAILABLE_PROPERTIES[self.model] + properties = AVAILABLE_PROPERTIES.get( + self.model, AVAILABLE_PROPERTIES[MODEL_PHILIPS_LIGHT_RWREAD] + ) values = self.get_properties(properties) return PhilipsRwreadStatus(defaultdict(lambda: None, zip(properties, values))) diff --git a/miio/powerstrip.py b/miio/powerstrip.py index e628ec474..469c8ddfe 100644 --- a/miio/powerstrip.py +++ b/miio/powerstrip.py @@ -138,17 +138,6 @@ class PowerStrip(Device): _supported_models = [MODEL_POWER_STRIP_V1, MODEL_POWER_STRIP_V2] - def __init__( - self, - ip: str = None, - token: str = None, - start_id: int = 0, - debug: int = 0, - lazy_discover: bool = True, - model: str = MODEL_POWER_STRIP_V1, - ) -> None: - super().__init__(ip, token, start_id, debug, lazy_discover, model=model) - @command( default_output=format_output( "", @@ -166,7 +155,9 @@ def __init__( ) def status(self) -> PowerStripStatus: """Retrieve properties.""" - properties = AVAILABLE_PROPERTIES[self.model] + properties = AVAILABLE_PROPERTIES.get( + self.model, AVAILABLE_PROPERTIES[MODEL_POWER_STRIP_V1] + ) values = self.get_properties(properties) return PowerStripStatus(defaultdict(lambda: None, zip(properties, values))) diff --git a/miio/pwzn_relay.py b/miio/pwzn_relay.py index c0d3871bb..8d268a564 100644 --- a/miio/pwzn_relay.py +++ b/miio/pwzn_relay.py @@ -99,22 +99,13 @@ def on_count(self) -> Optional[int]: class PwznRelay(Device): """Main class representing the PWZN Relay.""" - def __init__( - self, - ip: str = None, - token: str = None, - start_id: int = 0, - debug: int = 0, - lazy_discover: bool = True, - model: str = MODEL_PWZN_RELAY_APPLE, - ) -> None: - super().__init__(ip, token, start_id, debug, lazy_discover, model=model) - @command(default_output=format_output("", "on_count: {result.on_count}\n")) def status(self) -> PwznRelayStatus: """Retrieve properties.""" - properties = AVAILABLE_PROPERTIES[self.model].copy() + properties = AVAILABLE_PROPERTIES.get( + self.model, AVAILABLE_PROPERTIES[MODEL_PWZN_RELAY_APPLE] + ).copy() values = self.get_properties(properties) return PwznRelayStatus(defaultdict(lambda: None, zip(properties, values))) diff --git a/miio/toiletlid.py b/miio/toiletlid.py index 3cd99dd1b..4f78927e6 100644 --- a/miio/toiletlid.py +++ b/miio/toiletlid.py @@ -71,17 +71,6 @@ def ambient_light(self) -> str: class Toiletlid(Device): - def __init__( - self, - ip: str = None, - token: str = None, - start_id: int = 0, - debug: int = 0, - lazy_discover: bool = True, - model: str = MODEL_TOILETLID_V1, - ) -> None: - super().__init__(ip, token, start_id, debug, lazy_discover, model=model) - @command( default_output=format_output( "", @@ -95,7 +84,9 @@ def __init__( ) def status(self) -> ToiletlidStatus: """Retrieve properties.""" - properties = AVAILABLE_PROPERTIES[self.model] + properties = AVAILABLE_PROPERTIES.get( + self.model, AVAILABLE_PROPERTIES[MODEL_TOILETLID_V1] + ) values = self.get_properties(properties) color = self.get_ambient_light() diff --git a/miio/wifispeaker.py b/miio/wifispeaker.py index b7e274063..0cc1af45c 100644 --- a/miio/wifispeaker.py +++ b/miio/wifispeaker.py @@ -1,6 +1,5 @@ import enum import logging -import warnings import click @@ -95,15 +94,6 @@ def transport_channel(self) -> TransportChannel: class WifiSpeaker(Device): """Device class for Xiaomi Smart Wifi Speaker.""" - def __init__(self, *args, **kwargs): - warnings.warn( - "Please help to complete this by providing more " - "information about possible values for `state`, " - "`play_mode` and `transport_channel`.", - stacklevel=2, - ) - super().__init__(*args, **kwargs) - @command( default_output=format_output( "",