Skip to content

Commit

Permalink
added support for zhimi.humidifier.cb2 (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
harusame3144 authored Mar 8, 2021
1 parent b340f7b commit fa4a2f9
Showing 1 changed file with 28 additions and 2 deletions.
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:
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
)

0 comments on commit fa4a2f9

Please sign in to comment.