From 67f7de958c59ff58c3f2778815620611a3704bfd Mon Sep 17 00:00:00 2001 From: Teemu R Date: Sun, 20 Mar 2022 02:41:58 +0100 Subject: [PATCH] Move humidifier implementations to miio.integrations.humidifier package (#1365) --- miio/__init__.py | 13 ++++---- miio/discovery.py | 30 ++++++++----------- miio/integrations/humidifier/__init__.py | 4 +++ .../humidifier/deerma/__init__.py | 1 + .../humidifier/deerma}/airhumidifier_mjjsq.py | 5 ++-- .../deerma}/tests/test_airhumidifier_mjjsq.py | 8 ++--- .../integrations/humidifier/shuii/__init__.py | 2 ++ .../humidifier/shuii}/airhumidifier_jsq.py | 10 +++++-- .../humidifier/shuii/tests/__init__.py | 0 .../shuii}/tests/test_airhumidifier_jsq.py | 10 +++---- .../integrations/humidifier/zhimi/__init__.py | 3 ++ .../humidifier/zhimi}/airhumidifier.py | 5 ++-- .../humidifier/zhimi}/airhumidifier_miot.py | 5 ++-- .../humidifier/zhimi/tests/__init__.py | 0 .../zhimi}/tests/test_airhumidifier.py | 10 +++---- .../zhimi}/tests/test_airhumidifier_miot.py | 8 ++--- 16 files changed, 61 insertions(+), 53 deletions(-) rename miio/{ => integrations/humidifier/deerma}/airhumidifier_mjjsq.py (97%) rename miio/{ => integrations/humidifier/deerma}/tests/test_airhumidifier_mjjsq.py (97%) create mode 100644 miio/integrations/humidifier/shuii/__init__.py rename miio/{ => integrations/humidifier/shuii}/airhumidifier_jsq.py (97%) create mode 100644 miio/integrations/humidifier/shuii/tests/__init__.py rename miio/{ => integrations/humidifier/shuii}/tests/test_airhumidifier_jsq.py (98%) create mode 100644 miio/integrations/humidifier/zhimi/__init__.py rename miio/{ => integrations/humidifier/zhimi}/airhumidifier.py (98%) rename miio/{ => integrations/humidifier/zhimi}/airhumidifier_miot.py (98%) create mode 100644 miio/integrations/humidifier/zhimi/tests/__init__.py rename miio/{ => integrations/humidifier/zhimi}/tests/test_airhumidifier.py (98%) rename miio/{ => integrations/humidifier/zhimi}/tests/test_airhumidifier_miot.py (97%) diff --git a/miio/__init__.py b/miio/__init__.py index 7783446eb..b677f4bf0 100644 --- a/miio/__init__.py +++ b/miio/__init__.py @@ -12,6 +12,7 @@ from miio.device import Device, DeviceStatus # isort: skip from miio.exceptions import DeviceError, DeviceException # isort: skip from miio.miot_device import MiotDevice # isort: skip +from miio.deviceinfo import DeviceInfo # isort: skip # Integration imports from miio.airconditioner_miot import AirConditionerMiot @@ -21,10 +22,6 @@ ) from miio.airconditioningcompanionMCN import AirConditioningCompanionMcn02 from miio.airdehumidifier import AirDehumidifier -from miio.airhumidifier import AirHumidifier -from miio.airhumidifier_jsq import AirHumidifierJsq -from miio.airhumidifier_miot import AirHumidifierMiot -from miio.airhumidifier_mjjsq import AirHumidifierMjjsq from miio.airqualitymonitor import AirQualityMonitor from miio.airqualitymonitor_miot import AirQualityMonitorCGDN1 from miio.aqaracamera import AqaraCamera @@ -43,7 +40,13 @@ from miio.integrations.fan.dmaker import Fan1C, FanMiot, FanP5 from miio.integrations.fan.leshow import FanLeshow from miio.integrations.fan.zhimi import Fan, FanZA5 -from miio.integrations.humidifier.deerma import AirHumidifierJsqs +from miio.integrations.humidifier import ( + AirHumidifier, + AirHumidifierJsq, + AirHumidifierJsqs, + AirHumidifierMiot, + AirHumidifierMjjsq, +) from miio.integrations.light.philips import ( Ceil, PhilipsBulb, diff --git a/miio/discovery.py b/miio/discovery.py index 98d219e6a..68be7f3a6 100644 --- a/miio/discovery.py +++ b/miio/discovery.py @@ -15,16 +15,18 @@ AirPurifier, AirPurifierMiot, ) +from miio.integrations.humidifier import ( + AirHumidifier, + AirHumidifierJsq, + AirHumidifierJsqs, + AirHumidifierMjjsq, +) from miio.integrations.yeelight import Yeelight from . import ( AirConditionerMiot, AirConditioningCompanion, AirConditioningCompanionMcn02, - AirHumidifier, - AirHumidifierJsq, - AirHumidifierJsqs, - AirHumidifierMjjsq, AirQualityMonitor, AqaraCamera, Ceil, @@ -57,12 +59,6 @@ MODEL_ACPARTNER_V3, ) from .airconditioningcompanionMCN import MODEL_ACPARTNER_MCN02 -from .airhumidifier import ( - MODEL_HUMIDIFIER_CA1, - MODEL_HUMIDIFIER_CB1, - MODEL_HUMIDIFIER_V1, -) -from .airhumidifier_mjjsq import MODEL_HUMIDIFIER_JSQ1, MODEL_HUMIDIFIER_MJJSQ from .airqualitymonitor import ( MODEL_AIRQUALITYMONITOR_B1, MODEL_AIRQUALITYMONITOR_S1, @@ -130,14 +126,12 @@ "chuangmi-camera-ipc019": ChuangmiCamera, "chuangmi-ir-v2": ChuangmiIr, "chuangmi-remote-h102a03_": ChuangmiIr, - "zhimi-humidifier-v1": partial(AirHumidifier, model=MODEL_HUMIDIFIER_V1), - "zhimi-humidifier-ca1": partial(AirHumidifier, model=MODEL_HUMIDIFIER_CA1), - "zhimi-humidifier-cb1": partial(AirHumidifier, model=MODEL_HUMIDIFIER_CB1), - "shuii-humidifier-jsq001": partial(AirHumidifierJsq, model=MODEL_HUMIDIFIER_MJJSQ), - "deerma-humidifier-mjjsq": partial( - AirHumidifierMjjsq, model=MODEL_HUMIDIFIER_MJJSQ - ), - "deerma-humidifier-jsq1": partial(AirHumidifierMjjsq, model=MODEL_HUMIDIFIER_JSQ1), + "zhimi-humidifier-v1": AirHumidifier, + "zhimi-humidifier-ca1": AirHumidifier, + "zhimi-humidifier-cb1": AirHumidifier, + "shuii-humidifier-jsq001": AirHumidifierJsq, + "deerma-humidifier-mjjsq": AirHumidifierMjjsq, + "deerma-humidifier-jsq1": AirHumidifierMjjsq, "deerma-humidifier-jsqs": AirHumidifierJsqs, "yunmi-waterpuri-v2": WaterPurifier, "yunmi.waterpuri.lx9": WaterPurifierYunmi, diff --git a/miio/integrations/humidifier/__init__.py b/miio/integrations/humidifier/__init__.py index e69de29bb..3320258f1 100644 --- a/miio/integrations/humidifier/__init__.py +++ b/miio/integrations/humidifier/__init__.py @@ -0,0 +1,4 @@ +# flake8: noqa +from .deerma import * +from .shuii import * +from .zhimi import * diff --git a/miio/integrations/humidifier/deerma/__init__.py b/miio/integrations/humidifier/deerma/__init__.py index d07fde6a4..d79df97ad 100644 --- a/miio/integrations/humidifier/deerma/__init__.py +++ b/miio/integrations/humidifier/deerma/__init__.py @@ -1,2 +1,3 @@ # flake8: noqa from .airhumidifier_jsqs import AirHumidifierJsqs +from .airhumidifier_mjjsq import AirHumidifierMjjsq diff --git a/miio/airhumidifier_mjjsq.py b/miio/integrations/humidifier/deerma/airhumidifier_mjjsq.py similarity index 97% rename from miio/airhumidifier_mjjsq.py rename to miio/integrations/humidifier/deerma/airhumidifier_mjjsq.py index 2eeda2ebb..4c85823ac 100644 --- a/miio/airhumidifier_mjjsq.py +++ b/miio/integrations/humidifier/deerma/airhumidifier_mjjsq.py @@ -5,9 +5,8 @@ import click -from .click_common import EnumType, command, format_output -from .device import Device, DeviceStatus -from .exceptions import DeviceException +from miio import Device, DeviceException, DeviceStatus +from miio.click_common import EnumType, command, format_output _LOGGER = logging.getLogger(__name__) diff --git a/miio/tests/test_airhumidifier_mjjsq.py b/miio/integrations/humidifier/deerma/tests/test_airhumidifier_mjjsq.py similarity index 97% rename from miio/tests/test_airhumidifier_mjjsq.py rename to miio/integrations/humidifier/deerma/tests/test_airhumidifier_mjjsq.py index 54f7e3746..dc1504d8a 100644 --- a/miio/tests/test_airhumidifier_mjjsq.py +++ b/miio/integrations/humidifier/deerma/tests/test_airhumidifier_mjjsq.py @@ -2,16 +2,16 @@ import pytest -from miio import AirHumidifierMjjsq -from miio.airhumidifier_mjjsq import ( +from miio.tests.dummies import DummyDevice + +from .. import AirHumidifierMjjsq +from ..airhumidifier_mjjsq import ( MODEL_HUMIDIFIER_JSQ1, AirHumidifierException, AirHumidifierStatus, OperationMode, ) -from .dummies import DummyDevice - class DummyAirHumidifierMjjsq(DummyDevice, AirHumidifierMjjsq): def __init__(self, *args, **kwargs): diff --git a/miio/integrations/humidifier/shuii/__init__.py b/miio/integrations/humidifier/shuii/__init__.py new file mode 100644 index 000000000..51fe66de8 --- /dev/null +++ b/miio/integrations/humidifier/shuii/__init__.py @@ -0,0 +1,2 @@ +# flake8: noqa +from .airhumidifier_jsq import AirHumidifierJsq diff --git a/miio/airhumidifier_jsq.py b/miio/integrations/humidifier/shuii/airhumidifier_jsq.py similarity index 97% rename from miio/airhumidifier_jsq.py rename to miio/integrations/humidifier/shuii/airhumidifier_jsq.py index 398f4aedf..c7bfe2513 100644 --- a/miio/airhumidifier_jsq.py +++ b/miio/integrations/humidifier/shuii/airhumidifier_jsq.py @@ -4,12 +4,16 @@ import click -from .airhumidifier import AirHumidifierException -from .click_common import EnumType, command, format_output -from .device import Device, DeviceStatus +from miio import Device, DeviceException, DeviceStatus +from miio.click_common import EnumType, command, format_output _LOGGER = logging.getLogger(__name__) + +class AirHumidifierException(DeviceException): + pass + + # Xiaomi Zero Fog Humidifier MODEL_HUMIDIFIER_JSQ001 = "shuii.humidifier.jsq001" diff --git a/miio/integrations/humidifier/shuii/tests/__init__.py b/miio/integrations/humidifier/shuii/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/miio/tests/test_airhumidifier_jsq.py b/miio/integrations/humidifier/shuii/tests/test_airhumidifier_jsq.py similarity index 98% rename from miio/tests/test_airhumidifier_jsq.py rename to miio/integrations/humidifier/shuii/tests/test_airhumidifier_jsq.py index 60f3e2536..6c87cbd2a 100644 --- a/miio/tests/test_airhumidifier_jsq.py +++ b/miio/integrations/humidifier/shuii/tests/test_airhumidifier_jsq.py @@ -3,17 +3,17 @@ import pytest -from miio import AirHumidifierJsq -from miio.airhumidifier import AirHumidifierException -from miio.airhumidifier_jsq import ( +from miio.tests.dummies import DummyDevice + +from .. import AirHumidifierJsq +from ..airhumidifier_jsq import ( MODEL_HUMIDIFIER_JSQ001, + AirHumidifierException, AirHumidifierStatus, LedBrightness, OperationMode, ) -from .dummies import DummyDevice - class DummyAirHumidifierJsq(DummyDevice, AirHumidifierJsq): def __init__(self, *args, **kwargs): diff --git a/miio/integrations/humidifier/zhimi/__init__.py b/miio/integrations/humidifier/zhimi/__init__.py new file mode 100644 index 000000000..26b999c4f --- /dev/null +++ b/miio/integrations/humidifier/zhimi/__init__.py @@ -0,0 +1,3 @@ +# flake8: noqa +from .airhumidifier import AirHumidifier +from .airhumidifier_miot import AirHumidifierMiot diff --git a/miio/airhumidifier.py b/miio/integrations/humidifier/zhimi/airhumidifier.py similarity index 98% rename from miio/airhumidifier.py rename to miio/integrations/humidifier/zhimi/airhumidifier.py index c02079fde..ff7a13d76 100644 --- a/miio/airhumidifier.py +++ b/miio/integrations/humidifier/zhimi/airhumidifier.py @@ -5,9 +5,8 @@ import click -from .click_common import EnumType, command, format_output -from .device import Device, DeviceInfo, DeviceStatus -from .exceptions import DeviceError, DeviceException +from miio import Device, DeviceError, DeviceException, DeviceInfo, DeviceStatus +from miio.click_common import EnumType, command, format_output _LOGGER = logging.getLogger(__name__) diff --git a/miio/airhumidifier_miot.py b/miio/integrations/humidifier/zhimi/airhumidifier_miot.py similarity index 98% rename from miio/airhumidifier_miot.py rename to miio/integrations/humidifier/zhimi/airhumidifier_miot.py index 577c0db1d..6cce08a6c 100644 --- a/miio/airhumidifier_miot.py +++ b/miio/integrations/humidifier/zhimi/airhumidifier_miot.py @@ -4,9 +4,8 @@ import click -from .click_common import EnumType, command, format_output -from .exceptions import DeviceException -from .miot_device import DeviceStatus, MiotDevice +from miio import DeviceException, DeviceStatus, MiotDevice +from miio.click_common import EnumType, command, format_output _LOGGER = logging.getLogger(__name__) diff --git a/miio/integrations/humidifier/zhimi/tests/__init__.py b/miio/integrations/humidifier/zhimi/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/miio/tests/test_airhumidifier.py b/miio/integrations/humidifier/zhimi/tests/test_airhumidifier.py similarity index 98% rename from miio/tests/test_airhumidifier.py rename to miio/integrations/humidifier/zhimi/tests/test_airhumidifier.py index 71f54235f..f8f65e864 100644 --- a/miio/tests/test_airhumidifier.py +++ b/miio/integrations/humidifier/zhimi/tests/test_airhumidifier.py @@ -1,7 +1,10 @@ import pytest -from miio import AirHumidifier, DeviceException -from miio.airhumidifier import ( +from miio import DeviceException, DeviceInfo +from miio.tests.dummies import DummyDevice + +from .. import AirHumidifier +from ..airhumidifier import ( MODEL_HUMIDIFIER_CA1, MODEL_HUMIDIFIER_CB1, MODEL_HUMIDIFIER_V1, @@ -9,9 +12,6 @@ LedBrightness, OperationMode, ) -from miio.device import DeviceInfo - -from .dummies import DummyDevice class DummyAirHumidifier(DummyDevice, AirHumidifier): diff --git a/miio/tests/test_airhumidifier_miot.py b/miio/integrations/humidifier/zhimi/tests/test_airhumidifier_miot.py similarity index 97% rename from miio/tests/test_airhumidifier_miot.py rename to miio/integrations/humidifier/zhimi/tests/test_airhumidifier_miot.py index 317234eac..507870862 100644 --- a/miio/tests/test_airhumidifier_miot.py +++ b/miio/integrations/humidifier/zhimi/tests/test_airhumidifier_miot.py @@ -1,15 +1,15 @@ import pytest -from miio import AirHumidifierMiot -from miio.airhumidifier_miot import ( +from miio.tests.dummies import DummyMiotDevice + +from .. import AirHumidifierMiot +from ..airhumidifier_miot import ( AirHumidifierMiotException, LedBrightness, OperationMode, PressedButton, ) -from .dummies import DummyMiotDevice - _INITIAL_STATE = { "power": True, "fault": 0,