aholstenson / miio

Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more
MIT License
1.86k stars 354 forks source link

Support for Humidifier new model: zhimi.humidifier.cb1 #231

Open antylama opened 5 years ago

antylama commented 5 years ago

Hi,

I posted this on wrong place. It's about python-miio, but in node miio cb1 isn't supported too.

I got Smartmi Evaporative Humidifier, with new return model version:

WARNING:miio.discovery:Found unsupported device zhimi-humidifier-cb1_mibt13281121._miio._udp.local. at 192.168.1.10, please report to developers
Model: zhimi.humidifier.cb1
Hardware version: MTK7697
Firmware version: 1.6.5
Network: {'localIp': '192.168.1.10', 'mask': '255.255.255.0', 'gw': '192.168.1.1', 'gw_mac': 'mac'}
AP: {'rssi': -53, 'ssid': 'ssid', 'bssid': 'bssid'}

It's not really working on Mija Home App, so I grab the token, and run miiocli as "CA1". Everything working, except fetching status (temp_dec don't exists).

Fast path for python-miio:

index 54b56f3..18a5a31 100644
--- a/miio/airhumidifier.py
+++ b/miio/airhumidifier.py
@@ -12,11 +12,11 @@ _LOGGER = logging.getLogger(__name__)

 MODEL_HUMIDIFIER_V1 = 'zhimi.humidifier.v1'
 MODEL_HUMIDIFIER_CA1 = 'zhimi.humidifier.ca1'
+MODEL_HUMIDIFIER_CB1 = 'zhimi.humidifier.cb1'

 AVAILABLE_PROPERTIES_COMMON = [
     'power',
     'mode',
-    'temp_dec',
     'humidity',
     'buzzer',
     'led_b',
@@ -27,8 +27,9 @@ AVAILABLE_PROPERTIES_COMMON = [
 ]

 AVAILABLE_PROPERTIES = {
-    MODEL_HUMIDIFIER_V1: AVAILABLE_PROPERTIES_COMMON + ['trans_level', 'button_pressed'],
-    MODEL_HUMIDIFIER_CA1: AVAILABLE_PROPERTIES_COMMON + ['speed', 'depth', 'dry'],
+    MODEL_HUMIDIFIER_V1: AVAILABLE_PROPERTIES_COMMON + ['temp_dec', 'trans_level', 'button_pressed'],
+    MODEL_HUMIDIFIER_CA1: AVAILABLE_PROPERTIES_COMMON + ['temp_dec', 'speed', 'depth', 'dry'],
+    MODEL_HUMIDIFIER_CB1: AVAILABLE_PROPERTIES_COMMON + ['temperature', 'speed', 'depth', 'dry']
 }

@@ -85,6 +86,8 @@ class AirHumidifierStatus:
     @property
     def temperature(self) -> Optional[float]:
         """Current temperature, if available."""
+        if self.data["temperature"] is not None:
+            return self.data["temperature"]
         if self.data["temp_dec"] is not None:
             return self.data["temp_dec"] / 10.0
         return None
@@ -285,8 +288,8 @@ class AirHumidifier(Device):
         # properties are divided into multiple requests
         _props_per_request = 15

-        # The  CA1 is limited to a single property per request
-        if self.model == MODEL_HUMIDIFIER_CA1:
+        # The CA1/CB1 are limited to a single property per request
+        if self.model != MODEL_HUMIDIFIER_V1:
             _props_per_request = 1

         _props = properties.copy()
@@ -335,10 +338,10 @@ class AirHumidifier(Device):
     )
     def set_led_brightness(self, brightness: LedBrightness):
         """Set led brightness."""
-        if self.model == MODEL_HUMIDIFIER_CA1:
-            return self.send("set_led_b", [str(brightness.value)])
+        if self.model == MODEL_HUMIDIFIER_V1:
+            return self.send("set_led_b", [brightness.value])

-        return self.send("set_led_b", [brightness.value])
+        return self.send("set_led_b", [str(brightness.value)])

     @command(
         click.argument("led", type=bool),
@@ -414,3 +417,9 @@ class AirHumidifierCA1(AirHumidifier):
                  debug: int = 0, lazy_discover: bool = True) -> None:
         super().__init__(ip, token, start_id, debug, lazy_discover,
                          model=MODEL_HUMIDIFIER_CA1)
+
+class AirHumidifierCB1(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_CB1)
wbidus commented 5 years ago

Were you able to connect it to your local WiFi network, and communicate with it afterwards? I also have CB1, and I am not able to pair it with Mi Home app. I wanted to at least access to readings using my local network, but after "configure_wifi" command I am not able to speak with humidifier anymore (token rolled?)

cHunter789 commented 5 years ago

At the moment if you want to get the token you have to use modified Mi Home app https://uploadfiles.io/5dnfi (be carefully it's not my mod, i have used it with backup phone and fake account). After that just change temp_dec to temperature !

rezmus commented 5 years ago

it's my mod, kinda pitty they sell devices without support ;) btw: it's US model so there's also fahrenheit temperature supported by firmware.

public static final String MODEL = "zhimi.humidifier.cb1"; public static final String PROP_FAH = "fahrenheit";

in case you want to add support for ca2 model the only difference to ca1 is... yeah temperature prop. 3 models, 3 different prop names ;)

public static final String MODEL = "zhimi.humidifier.ca2"; public static final String PROP_TEMPERATURE = "temp";

antylama commented 5 years ago

My ca1 model almost works in Mi Home app on iPad (3 gen), works means: 1. detected and configure in manual mode (region: china), 2. only on/off device works, nothing else (error: 7, falling init device).

In the same time, on the same account android version of Mi Home (standard version, and beta on Android Pie), don't even display ca1 on list ;-).

Probably iPad version of app, just don't test version model, and this is why something is "working". I got token from iPad. Token from device not connected to wifi (accessed by device AP), isn't the same, but working in AP-mode.

rezmus commented 5 years ago

ca1 is chinese version and should be fully supported by both ipad and android mi home, however cb1 (us version) is still missing on any region.

koznov commented 5 years ago

Still no adding of CB1 version to miio? I'm trying to add it via 'zhimi.humidifier.cb1' model in Home Assistance - no luck.

AZheleznov commented 4 years ago

Cb1 works on US region

gyulkiller commented 4 years ago

Please support zhimi.humidifier.cb2, too