Skip to content

Commit

Permalink
Split fan_miot.py to vendor-specific fan integrations (#1303)
Browse files Browse the repository at this point in the history
* Split fan_miot.py to vendor-specific integrations

* The main implementation is now under miio/integrations/fan/dmaker/
* The FanZA5 (zhimi) is now under miio/integrations/fan/zhimi/

* Fix tests by keeping library imports to top of the module

Makes isort to skip reordering of the core library imports to
avoid causing problems with circular dependencies later on.
  • Loading branch information
rytilahti authored Jan 16, 2022
1 parent a896581 commit b06aca6
Show file tree
Hide file tree
Showing 10 changed files with 512 additions and 496 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ repos:
rev: 1.7.1
hooks:
- id: bandit
args: [-x, 'tests']
args: [-x, 'tests', -x, '**/test_*.py']


- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
14 changes: 10 additions & 4 deletions miio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
# python 3.8 and later
from importlib.metadata import version # type: ignore

# Library imports need to be on top to avoid problems with
# circular dependencies. As these do not change that often
# they can be marked to be skipped for isort runs.
from miio.device import Device, DeviceStatus # isort: skip
from miio.exceptions import DeviceError, DeviceException # isort: skip
from miio.miot_device import MiotDevice # isort: skip

# Integration imports
from miio.airconditioner_miot import AirConditionerMiot
from miio.airconditioningcompanion import (
AirConditioningCompanion,
Expand All @@ -31,15 +39,14 @@
from miio.chuangmi_plug import ChuangmiPlug, Plug, PlugV1, PlugV3
from miio.cooker import Cooker
from miio.curtain_youpin import CurtainMiot
from miio.device import Device, DeviceStatus
from miio.exceptions import DeviceError, DeviceException
from miio.fan import Fan, FanP5, FanSA1, FanV2, FanZA1, FanZA4
from miio.fan_leshow import FanLeshow
from miio.fan_miot import Fan1C, FanMiot, FanP9, FanP10, FanP11, FanZA5
from miio.gateway import Gateway
from miio.heater import Heater
from miio.heater_miot import HeaterMiot
from miio.huizuo import Huizuo, HuizuoLampFan, HuizuoLampHeater, HuizuoLampScene
from miio.integrations.fan.dmaker import Fan1C, FanMiot, FanP9, FanP10, FanP11
from miio.integrations.fan.zhimi import FanZA5
from miio.integrations.petwaterdispenser import PetWaterDispenser
from miio.integrations.vacuum.dreame.dreamevacuum_miot import DreameVacuumMiot
from miio.integrations.vacuum.mijia import G1Vacuum
Expand All @@ -55,7 +62,6 @@
from miio.integrations.vacuum.roidmi.roidmivacuum_miot import RoidmiVacuumMiot
from miio.integrations.vacuum.viomi.viomivacuum import ViomiVacuum
from miio.integrations.yeelight import Yeelight
from miio.miot_device import MiotDevice
from miio.philips_bulb import PhilipsBulb, PhilipsWhiteBulb
from miio.philips_eyecare import PhilipsEyecare
from miio.philips_moonlight import PhilipsMoonlight
Expand Down
20 changes: 7 additions & 13 deletions miio/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
Device,
Fan,
FanLeshow,
FanMiot,
Gateway,
Heater,
PhilipsBulb,
Expand Down Expand Up @@ -88,14 +87,9 @@
MODEL_FAN_ZA3,
MODEL_FAN_ZA4,
)
from .fan_miot import (
MODEL_FAN_1C,
MODEL_FAN_P9,
MODEL_FAN_P10,
MODEL_FAN_P11,
MODEL_FAN_ZA5,
)
from .heater import MODEL_HEATER_MA1, MODEL_HEATER_ZA1
from .integrations.fan.dmaker import FanMiot
from .integrations.fan.zhimi import FanZA5
from .powerstrip import MODEL_POWER_STRIP_V1, MODEL_POWER_STRIP_V2
from .toiletlid import MODEL_TOILETLID_V1

Expand Down Expand Up @@ -190,12 +184,12 @@
"zhimi-fan-za1": partial(Fan, model=MODEL_FAN_ZA1),
"zhimi-fan-za3": partial(Fan, model=MODEL_FAN_ZA3),
"zhimi-fan-za4": partial(Fan, model=MODEL_FAN_ZA4),
"dmaker-fan-1c": partial(FanMiot, model=MODEL_FAN_1C),
"dmaker-fan-1c": FanMiot,
"dmaker-fan-p5": partial(Fan, model=MODEL_FAN_P5),
"dmaker-fan-p9": partial(FanMiot, model=MODEL_FAN_P9),
"dmaker-fan-p10": partial(FanMiot, model=MODEL_FAN_P10),
"dmaker-fan-p11": partial(FanMiot, model=MODEL_FAN_P11),
"zhimi-fan-za5": partial(FanMiot, model=MODEL_FAN_ZA5),
"dmaker-fan-p9": FanMiot,
"dmaker-fan-p10": FanMiot,
"dmaker-fan-p11": FanMiot,
"zhimi-fan-za5": FanZA5,
"tinymu-toiletlid-v1": partial(Toiletlid, model=MODEL_TOILETLID_V1),
"zhimi-airfresh-va2": partial(AirFresh, model=MODEL_AIRFRESH_VA2),
"zhimi-airfresh-va4": partial(AirFresh, model=MODEL_AIRFRESH_VA4),
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions miio/integrations/fan/dmaker/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# flake8: noqa
from .fan_miot import Fan1C, FanMiot, FanP9, FanP10, FanP11
Loading

0 comments on commit b06aca6

Please sign in to comment.