Skip to content

Commit

Permalink
Add deerma.humidifier.jsq1 support (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored Nov 5, 2020
1 parent 74ab3b3 commit 32dfb5a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Supported devices
- Xiaomi Mi Home Air Conditioner Companion
- Xiaomi Mi Smart Air Conditioner A (xiaomi.aircondition.mc1, mc2, mc4, mc5)
- Xiaomi Mi Air Purifier
- Xiaomi Mi Air Humidifier
- Xiaomi Aqara Camera
- Xiaomi Aqara Gateway (basic implementation, alarm, lights)
- Xiaomi Mijia 360 1080p
Expand Down
55 changes: 41 additions & 14 deletions miio/airhumidifier_mjjsq.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum
import logging
from collections import defaultdict
from typing import Any, Dict
from typing import Any, Dict, Optional

import click

Expand All @@ -12,19 +12,23 @@
_LOGGER = logging.getLogger(__name__)

MODEL_HUMIDIFIER_MJJSQ = "deerma.humidifier.mjjsq"
MODEL_HUMIDIFIER_JSQ1 = "deerma.humidifier.jsq1"

MODEL_HUMIDIFIER_JSQ_COMMON = [
"OnOff_State",
"TemperatureValue",
"Humidity_Value",
"HumiSet_Value",
"Humidifier_Gear",
"Led_State",
"TipSound_State",
"waterstatus",
"watertankstatus",
]

AVAILABLE_PROPERTIES = {
MODEL_HUMIDIFIER_MJJSQ: [
"OnOff_State",
"TemperatureValue",
"Humidity_Value",
"HumiSet_Value",
"Humidifier_Gear",
"Led_State",
"TipSound_State",
"waterstatus",
"watertankstatus",
]
MODEL_HUMIDIFIER_MJJSQ: MODEL_HUMIDIFIER_JSQ_COMMON,
MODEL_HUMIDIFIER_JSQ1: MODEL_HUMIDIFIER_JSQ_COMMON + ["wet_and_protect"],
}


Expand Down Expand Up @@ -103,6 +107,14 @@ def water_tank_detached(self) -> bool:
"""True if the water tank is detached."""
return self.data["watertankstatus"] == 0

@property
def wet_protection(self) -> Optional[bool]:
"""True if wet protection is enabled."""
if self.data["wet_and_protect"] is not None:
return self.data["wet_and_protect"] == 1

return None

def __repr__(self) -> str:
s = (
"<AirHumidiferStatus power=%s, "
Expand All @@ -113,7 +125,8 @@ def __repr__(self) -> str:
"buzzer=%s, "
"target_humidity=%s%%, "
"no_water=%s, "
"water_tank_detached=%s>"
"water_tank_detached=%s,"
"wet_protection=%s>"
% (
self.power,
self.mode,
Expand All @@ -124,6 +137,7 @@ def __repr__(self) -> str:
self.target_humidity,
self.no_water,
self.water_tank_detached,
self.wet_protection,
)
)
return s
Expand Down Expand Up @@ -157,7 +171,8 @@ def __init__(
"Buzzer: {result.buzzer}\n"
"Target humidity: {result.target_humidity} %\n"
"No water: {result.no_water}\n"
"Water tank detached: {result.water_tank_detached}\n",
"Water tank detached: {result.water_tank_detached}\n"
"Wet protection: {result.wet_protection}\n",
)
)
def status(self) -> AirHumidifierStatus:
Expand Down Expand Up @@ -216,3 +231,15 @@ def set_target_humidity(self, humidity: int):
raise AirHumidifierException("Invalid target humidity: %s" % humidity)

return self.send("Set_HumiValue", [humidity])

@command(
click.argument("protection", type=bool),
default_output=format_output(
lambda protection: "Turning on wet protection"
if protection
else "Turning off wet protection"
),
)
def set_wet_protection(self, protection: bool):
"""Turn wet protection on/off."""
return self.send("Set_wet_and_protect", [int(protection)])
3 changes: 2 additions & 1 deletion miio/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
MODEL_HUMIDIFIER_CB1,
MODEL_HUMIDIFIER_V1,
)
from .airhumidifier_mjjsq import MODEL_HUMIDIFIER_MJJSQ
from .airhumidifier_mjjsq import MODEL_HUMIDIFIER_JSQ1, MODEL_HUMIDIFIER_MJJSQ
from .airqualitymonitor import (
MODEL_AIRQUALITYMONITOR_B1,
MODEL_AIRQUALITYMONITOR_S1,
Expand Down Expand Up @@ -134,6 +134,7 @@
"deerma-humidifier-mjjsq": partial(
AirHumidifierMjjsq, model=MODEL_HUMIDIFIER_MJJSQ
),
"deerma-humidifier-jsq1": partial(AirHumidifierMjjsq, model=MODEL_HUMIDIFIER_JSQ1),
"yunmi-waterpuri-v2": WaterPurifier,
"yunmi.waterpuri.lx9": WaterPurifierYunmi,
"yunmi.waterpuri.lx11": WaterPurifierYunmi,
Expand Down
16 changes: 14 additions & 2 deletions miio/tests/test_airhumidifier_mjjsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from miio import AirHumidifierMjjsq
from miio.airhumidifier_mjjsq import (
MODEL_HUMIDIFIER_MJJSQ,
MODEL_HUMIDIFIER_JSQ1,
AirHumidifierException,
AirHumidifierStatus,
OperationMode,
Expand All @@ -15,7 +15,7 @@

class DummyAirHumidifierMjjsq(DummyDevice, AirHumidifierMjjsq):
def __init__(self, *args, **kwargs):
self.model = MODEL_HUMIDIFIER_MJJSQ
self.model = MODEL_HUMIDIFIER_JSQ1
self.state = {
"Humidifier_Gear": 1,
"Humidity_Value": 44,
Expand All @@ -26,6 +26,7 @@ def __init__(self, *args, **kwargs):
"TipSound_State": 0,
"waterstatus": 1,
"watertankstatus": 1,
"wet_and_protect": 1,
}
self.return_values = {
"get_prop": self._get_state,
Expand All @@ -34,6 +35,7 @@ def __init__(self, *args, **kwargs):
"SetLedState": lambda x: self._set_state("Led_State", x),
"SetTipSound_Status": lambda x: self._set_state("TipSound_State", x),
"Set_HumiValue": lambda x: self._set_state("HumiSet_Value", x),
"Set_wet_and_protect": lambda x: self._set_state("wet_and_protect", x),
}
super().__init__(args, kwargs)

Expand Down Expand Up @@ -139,3 +141,13 @@ def target_humidity():

with pytest.raises(AirHumidifierException):
self.device.set_target_humidity(101)

def test_set_wet_protection(self):
def wet_protection():
return self.device.status().wet_protection

self.device.set_wet_protection(True)
assert wet_protection() is True

self.device.set_wet_protection(False)
assert wet_protection() is False

0 comments on commit 32dfb5a

Please sign in to comment.