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

Add support for dmaker.fan.p9 and dmaker.fan.p10 #819

Merged
merged 6 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Supported devices
- Xiaomi Philips Zhirui Smart LED Bulb E14 Candle Lamp
- Xiaomi Philips Zhirui Bedroom Smart Lamp
- Xiaomi Universal IR Remote Controller (Chuangmi IR)
- Xiaomi Mi Smart Pedestal Fan V2, V3, SA1, ZA1, ZA3, ZA4, P5
- Xiaomi Mi Smart Pedestal Fan V2, V3, SA1, ZA1, ZA3, ZA4, P5, P9, P10
- Xiaomi Mi Air Humidifier V1, CA1, CA4, CB1, MJJSQ, JSQ001
- Xiaomi Mi Water Purifier (Basic support: Turn on & off)
- Xiaomi PM2.5 Air Quality Monitor V1, B1, S1
Expand Down
7 changes: 7 additions & 0 deletions docs/api/miio.airconditioningcompanionMCN.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
miio.airconditioningcompanionMCN module
=======================================

.. automodule:: miio.airconditioningcompanionMCN
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/api/miio.fan_common.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
miio.fan\_common module
=======================

.. automodule:: miio.fan_common
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/api/miio.fan_miot.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
miio.fan\_miot module
=====================

.. automodule:: miio.fan_miot
:members:
:undoc-members:
:show-inheritance:
2 changes: 2 additions & 0 deletions docs/api/miio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Submodules
miio.exceptions
miio.extract_tokens
miio.fan
miio.fan_common
miio.fan_miot
miio.gateway
miio.heater
miio.miioprotocol
Expand Down
2 changes: 1 addition & 1 deletion miio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from miio.cooker import Cooker
from miio.device import Device
from miio.exceptions import DeviceError, DeviceException
from miio.fan import Fan, FanP5, FanSA1, FanV2, FanZA1, FanZA4
from miio.fan import Fan, FanP5, FanP9, FanP10, FanSA1, FanV2, FanZA1, FanZA4
from miio.gateway import Gateway
from miio.heater import Heater
from miio.philips_bulb import PhilipsBulb, PhilipsWhiteBulb
Expand Down
48 changes: 26 additions & 22 deletions miio/fan.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import enum
import logging
from typing import Any, Dict, Optional

import click

from .click_common import EnumType, command, format_output
from .device import Device
from .exceptions import DeviceException
from .fan_common import FanException, LedBrightness, MoveDirection, OperationMode
from .fan_miot import MODEL_FAN_P9, MODEL_FAN_P10, FanMiot

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -64,26 +64,6 @@
}


class FanException(DeviceException):
pass


class OperationMode(enum.Enum):
Normal = "normal"
Nature = "nature"


class LedBrightness(enum.Enum):
Bright = 0
Dim = 1
Off = 2


class MoveDirection(enum.Enum):
Left = "left"
Right = "right"


class FanStatus:
"""Container for status reports from the Xiaomi Mi Smart Pedestal Fan."""

Expand Down Expand Up @@ -767,3 +747,27 @@ def delay_off(self, minutes: int):
def set_rotate(self, direction: MoveDirection):
"""Rotate the fan by -5/+5 degrees left/right."""
return self.send("m_roll", [direction.value])


class FanP9(FanMiot):
swim2sun marked this conversation as resolved.
Show resolved Hide resolved
def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=MODEL_FAN_P9)


class FanP10(FanMiot):
def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=MODEL_FAN_P10)
23 changes: 23 additions & 0 deletions miio/fan_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import enum
swim2sun marked this conversation as resolved.
Show resolved Hide resolved

from .exceptions import DeviceException


class FanException(DeviceException):
pass


class OperationMode(enum.Enum):
Normal = "normal"
Nature = "nature"


class LedBrightness(enum.Enum):
Bright = 0
Dim = 1
Off = 2


class MoveDirection(enum.Enum):
Left = "left"
Right = "right"
Loading