Skip to content

Commit

Permalink
Add support for dmaker.fan.p45
Browse files Browse the repository at this point in the history
  • Loading branch information
saxel committed Oct 21, 2023
1 parent 501a7d7 commit f2cf743
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -267,7 +267,7 @@ integration, this library supports also the following devices:
* Xiaomi Philips Zhirui Bedroom Smart Lamp
* Huayi Huizuo Lamps
* Xiaomi Universal IR Remote Controller (Chuangmi IR)
* Xiaomi Mi Smart Pedestal Fan V2, V3, SA1, ZA1, ZA3, ZA4, ZA5 1C, P5, P9, P10, P11, P15, P18, P33
* Xiaomi Mi Smart Pedestal Fan V2, V3, SA1, ZA1, ZA3, ZA4, ZA5 1C, P5, P9, P10, P11, P15, P18, P33, P45
* Xiaomi Rosou SS4 Ventilator (leshow.fan.ss4)
* Xiaomi Mi Air Humidifier V1, CA1, CA4, CB1, MJJSQ, JSQ, JSQ1, JSQ001
* Xiaomi Mi Water Purifier (Basic support: Turn on & off)
Expand Down
33 changes: 31 additions & 2 deletions miio/integrations/dmaker/fan/fan_miot.py
Expand Up @@ -10,6 +10,7 @@
class OperationMode(enum.Enum):
Normal = "normal"
Nature = "nature"
Sleep = "sleep"


class MoveDirection(enum.Enum):
Expand All @@ -23,6 +24,7 @@ class MoveDirection(enum.Enum):
MODEL_FAN_P15 = "dmaker.fan.p15"
MODEL_FAN_P18 = "dmaker.fan.p18"
MODEL_FAN_P33 = "dmaker.fan.p33"
MODEL_FAN_P45 = "dmaker.fan.p45"
MODEL_FAN_1C = "dmaker.fan.1c"


Expand Down Expand Up @@ -85,6 +87,19 @@ class MoveDirection(enum.Enum):
"power_off_time": {"siid": 3, "piid": 1},
"set_move": {"siid": 6, "piid": 1},
},
MODEL_FAN_P45: {
# Source https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:fan:0000A005:dmaker-p45:1
"power": {"siid": 2, "piid": 1},
"fan_level": {"siid": 2, "piid": 2},
"mode": {"siid": 2, "piid": 3},
"swing_mode": {"siid": 2, "piid": 4},
"swing_mode_angle": {"siid": 2, "piid": 5},
"power_off_time": {"siid": 3, "piid": 1},
"light": {"siid": 4, "piid": 1},
"buzzer": {"siid": 5, "piid": 1},
"child_lock": {"siid": 7, "piid": 1},
"fan_speed": {"siid": 8, "piid": 1},
},
}


Expand Down Expand Up @@ -114,6 +129,7 @@ class MoveDirection(enum.Enum):
MODEL_FAN_P15: [30, 60, 90, 120, 140], # mapped to P11
MODEL_FAN_P18: [30, 60, 90, 120, 140], # mapped to P10
MODEL_FAN_P33: [30, 60, 90, 120, 140],
MODEL_FAN_P45: [30, 60, 90, 120, 150],
}


Expand All @@ -122,10 +138,16 @@ class OperationModeMiot(enum.Enum):
Nature = 1


class OperationModeMiotP45(enum.Enum):
Normal = 0
Nature = 1
Sleep = 2


class FanStatusMiot(DeviceStatus):
"""Container for status reports for Xiaomi Mi Smart Pedestal Fan DMaker P9/P10."""

def __init__(self, data: Dict[str, Any]) -> None:
def __init__(self, data: Dict[str, Any], model: str) -> None:
"""
Response of a FanMiot (dmaker.fan.p10):
Expand All @@ -148,6 +170,7 @@ def __init__(self, data: Dict[str, Any]) -> None:
}
"""
self.data = data
self.model = model

@property
def power(self) -> str:
Expand All @@ -162,6 +185,8 @@ def is_on(self) -> bool:
@property
def mode(self) -> OperationMode:
"""Operation mode."""
if self.model == MODEL_FAN_P45:
return OperationMode[OperationModeMiotP45(self.data["mode"]).name]

Check warning on line 189 in miio/integrations/dmaker/fan/fan_miot.py

View check run for this annotation

Codecov / codecov/patch

miio/integrations/dmaker/fan/fan_miot.py#L189

Added line #L189 was not covered by tests
return OperationMode[OperationModeMiot(self.data["mode"]).name]

@property
Expand Down Expand Up @@ -292,7 +317,8 @@ def status(self) -> FanStatusMiot:
{
prop["did"]: prop["value"] if prop["code"] == 0 else None
for prop in self.get_properties_for_mapping()
}
},
self.model,
)

@command(default_output=format_output("Powering on"))
Expand All @@ -311,6 +337,9 @@ def off(self):
)
def set_mode(self, mode: OperationMode):
"""Set mode."""
if self.model == MODEL_FAN_P45:
return self.set_property("mode", OperationModeMiotP45[mode.name].value)

Check warning on line 341 in miio/integrations/dmaker/fan/fan_miot.py

View check run for this annotation

Codecov / codecov/patch

miio/integrations/dmaker/fan/fan_miot.py#L341

Added line #L341 was not covered by tests

return self.set_property("mode", OperationModeMiot[mode.name].value)

@command(
Expand Down

0 comments on commit f2cf743

Please sign in to comment.