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

added support for zhimi.humidifier.cb2 #917

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Changes from all 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
30 changes: 28 additions & 2 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
MODEL_HUMIDIFIER_V1 = "zhimi.humidifier.v1"
MODEL_HUMIDIFIER_CA1 = "zhimi.humidifier.ca1"
MODEL_HUMIDIFIER_CB1 = "zhimi.humidifier.cb1"
MODEL_HUMIDIFIER_CB2 = "zhimi.humidifier.cb2"

AVAILABLE_PROPERTIES_COMMON = [
"power",
Expand All @@ -34,6 +35,8 @@
+ ["temp_dec", "speed", "depth", "dry"],
MODEL_HUMIDIFIER_CB1: AVAILABLE_PROPERTIES_COMMON
+ ["temperature", "speed", "depth", "dry"],
MODEL_HUMIDIFIER_CB2: AVAILABLE_PROPERTIES_COMMON
+ ["temperature", "speed", "depth", "dry"],
}


Expand Down Expand Up @@ -180,6 +183,11 @@ def motor_speed(self) -> Optional[int]:
@property
def depth(self) -> Optional[int]:
"""The remaining amount of water in percent."""

# MODEL_HUMIDIFIER_CB2 127 without water tank. 125 = 100% water
if self.device_info.model == MODEL_HUMIDIFIER_CB2:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could introduce a new boolean property to indicate the water tank is detached.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @syssi - do you want to get this change already into this PR, or shall we merge this already for the next release?

return int(int(self.data["depth"]) / 1.25)

if "depth" in self.data and self.data["depth"] is not None:
return self.data["depth"]
return None
Expand Down Expand Up @@ -309,8 +317,12 @@ def status(self) -> AirHumidifierStatus:
# properties are divided into multiple requests
_props_per_request = 15

# The CA1 and CB1 are limited to a single property per request
if self.model in [MODEL_HUMIDIFIER_CA1, MODEL_HUMIDIFIER_CB1]:
# The CA1, CB1 and CB2 are limited to a single property per request
if self.model in [
MODEL_HUMIDIFIER_CA1,
MODEL_HUMIDIFIER_CB1,
MODEL_HUMIDIFIER_CB2,
]:
_props_per_request = 1

values = self.get_properties(properties, max_properties=_props_per_request)
Expand Down Expand Up @@ -445,3 +457,17 @@ def __init__(
super().__init__(
ip, token, start_id, debug, lazy_discover, model=MODEL_HUMIDIFIER_CB1
)


class AirHumidifierCB2(AirHumidifier):
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_HUMIDIFIER_CB2
)