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

Fix bug for zhimi.fan.za5 resulting in user ack timeout #1348

Merged
merged 2 commits into from
Mar 7, 2022

Conversation

saxel
Copy link
Contributor

@saxel saxel commented Mar 7, 2022

This should fix #1344, at least for my simple tests of getting the status, turning the fan on and off.

Before

Status ❌

miiocli --debug fanza5 --ip 192.168.x.xxx --token <TOKEN>

DEBUG:miio.device:Detected model zhimi.fan.za5
DEBUG:miio.miioprotocol:192.168.x.xxx:54321 >>: {'id': 2, 'method': 'get_properties', 'params': [{'did': 'zhimi.fan.za5', 'power': {'siid': 2, 'piid': 1}, 'fan_level': {'siid': 2, 'piid': 2}, 'swing_mode': {'siid': 2, 'piid': 3}, 'swing_mode_angle': {'siid': 2, 'piid': 5}, 'mode': {'siid': 2, 'piid': 7}, 'power_off_time': {'siid': 2, 'piid': 10}, 'anion': {'siid': 2, 'piid': 11}, 'child_lock': {'siid': 3, 'piid': 1}, 'light': {'siid': 4, 'piid': 3}, 'buzzer': {'siid': 5, 'piid': 1}, 'buttons_pressed': {'siid': 6, 'piid': 1}, 'battery_supported': {'siid': 6, 'piid': 2}, 'set_move': {'siid': 6, 'piid': 3}, 'speed_rpm': {'siid': 6, 'piid': 4}, 'powersupply_attached': {'siid': 6, 'piid': 5}, 'fan_speed': {'siid': 6, 'piid': 8}, 'humidity': {'siid': 7, 'piid': 1}, 'temperature': {'siid': 7, 'piid': 7}}]}

DEBUG:miio.miioprotocol:192.168.x.xxx:54321 (ts: 1970-01-04 06:02:27, id: 2) << {'id': 2, 'error': {'code': -9999, 'message': 'user ack timeout'}, 'exe_time': 4010}
DEBUG:miio.click_common:Exception: {'code': -9999, 'message': 'user ack timeout'}
Traceback (most recent call last):
  File "/home/saxel/python-miio/miio/click_common.py", line 51, in __call__
    return self.main(*args, **kwargs)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/saxel/python-miio/miio/click_common.py", line 300, in wrap
    kwargs["result"] = func(*args, **kwargs)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/saxel/python-miio/miio/click_common.py", line 265, in command_callback
    return miio_command.call(miio_device, *args, **kwargs)
  File "/home/saxel/python-miio/miio/click_common.py", line 212, in call
    return method(*args, **kwargs)
  File "/home/saxel/python-miio/miio/click_common.py", line 179, in _wrap
    return func(self, *args, **kwargs)
  File "/home/saxel/python-miio/miio/integrations/fan/zhimi/zhimi_miot.py", line 202, in status
    for prop in self.get_properties_for_mapping()
  File "/home/saxel/python-miio/miio/miot_device.py", line 72, in get_properties_for_mapping
    return self.get_properties(
  File "/home/saxel/python-miio/miio/device.py", line 232, in get_properties
    values.extend(self.send(property_getter, _props[:max_properties]))
  File "/home/saxel/python-miio/miio/device.py", line 106, in send
    return self._protocol.send(
  File "/home/saxel/python-miio/miio/miioprotocol.py", line 214, in send
    self._handle_error(payload["error"])
  File "/home/saxel/python-miio/miio/miioprotocol.py", line 274, in _handle_error
    raise DeviceError(error)
miio.exceptions.DeviceError: {'code': -9999, 'message': 'user ack timeout'}
Error: {'code': -9999, 'message': 'user ack timeout'}

Turn on ❌

miiocli --debug fanza5 --ip 192.168.x.xxx --token <TOKEN>

INFO:miio.cli:Debug mode active
Powering on
DEBUG:miio.click_common:Unknown model, trying autodetection. None None
DEBUG:miio.miioprotocol:Got a response: Container:
    data = Container:
        data = b'' (total 0)
        value = b'' (total 0)
        offset1 = 32
        offset2 = 32
        length = 0
    header = Container:
        data = ...
        value = Container:
            length = 32
            unknown = 0
            device_id = unhexlify('<deviceid>')
            ts = 1970-01-04 06:03:36
        offset1 = 0
        offset2 = 16
        length = 16
    checksum = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' (total 16)
DEBUG:miio.device:Detected model zhimi.fan.za5
Traceback (most recent call last):
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/bin/miiocli", line 5, in <module>
    create_cli()
  File "/home/saxel/python-miio/miio/cli.py", line 63, in create_cli
    return cli(auto_envvar_prefix="MIIO")
  File "/home/saxel/python-miio/miio/click_common.py", line 51, in __call__
    return self.main(*args, **kwargs)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/saxel/python-miio/miio/click_common.py", line 300, in wrap
    kwargs["result"] = func(*args, **kwargs)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/saxel/.cache/pypoetry/virtualenvs/python-miio-RxGJ_yqw-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwabrgs)
  File "/home/saxel/python-miio/miio/click_common.py", line 265, in command_callback
    return miio_command.call(miio_device, *args, **kwargs)
  File "/home/saxel/python-miio/miio/click_common.py", line 212, in call
    return method(*args, **kwargs)
  File "/home/saxel/python-miio/miio/click_common.py", line 179, in _wrap
    return func(self, *args, **kwargs)
  File "/home/saxel/python-miio/miio/integrations/fan/zhimi/zhimi_miot.py", line 209, in on
    return self.set_property("power", True)
  File "/home/saxel/python-miio/miio/miot_device.py", line 154, in set_property
    [{"did": property_key, **mapping[property_key], "value": value}],
KeyError: 'power'

After

Status ✔

miiocli fanza5 --debug --ip 192.168.x.xxx --token <TOKEN> status

DEBUG:miio.device:Detected model zhimi.fan.za5
DEBUG:miio.miioprotocol:192.168.x.xxx:54321 >>: {'id': 2, 'method': 'get_properties', 'params': [{'did': 'power', 'siid': 2, 'piid': 1}, {'did': 'fan_level', 'siid': 2, 'piid': 2}, {'did': 'swing_mode', 'siid': 2, 'piid': 3}, {'did': 'swing_mode_angle', 'siid': 2, 'piid': 5}, {'did': 'mode', 'siid': 2, 'piid': 7}, {'did': 'power_off_time', 'siid': 2, 'piid': 10}, {'did': 'anion', 'siid': 2, 'piid': 11}, {'did': 'child_lock', 'siid': 3, 'piid': 1}, {'did': 'light', 'siid': 4, 'piid': 3}, {'did': 'buzzer', 'siid': 5, 'piid': 1}, {'did': 'buttons_pressed', 'siid': 6, 'piid': 1}, {'did': 'battery_supported', 'siid': 6, 'piid': 2}, {'did': 'set_move', 'siid': 6, 'piid': 3}, {'did': 'speed_rpm', 'siid': 6, 'piid': 4}, {'did': 'powersupply_attached', 'siid': 6, 'piid': 5}]}
DEBUG:miio.miioprotocol:192.168.x.xxx:54321 (ts: 1970-01-04 06:09:30, id: 2) << {'id': 2, 'result': [{'did': 'power', 'siid': 2, 'piid': 1, 'code': 0, 'value': False}, {'did': 'fan_level', 'siid': 2, 'piid': 2, 'code': 0, 'value': 2}, {'did': 'swing_mode', 'siid': 2, 'piid': 3, 'code': 0, 'value': True}, {'did': 'swing_mode_angle', 'siid': 2, 'piid': 5, 'code': 0, 'value': 30}, {'did': 'mode', 'siid': 2, 'piid': 7, 'code': 0, 'value': 1}, {'did': 'power_off_time', 'siid': 2, 'piid': 10, 'code': 0, 'value': 0}, {'did': 'anion', 'siid': 2, 'piid': 11, 'code': 0, 'value': True}, {'did': 'child_lock', 'siid': 3, 'piid': 1, 'code': 0, 'value': False}, {'did': 'light', 'siid': 4, 'piid': 3, 'code': 0, 'value': 0}, {'did': 'buzzer', 'siid': 5, 'piid': 1, 'code': 0, 'value': False}, {'did': 'buttons_pressed', 'siid': 6, 'piid': 1, 'code': 0, 'value': 0}, {'did': 'battery_supported', 'siid': 6, 'piid': 2, 'code': 0, 'value': False}, {'did': 'set_move', 'siid': 6, 'piid': 3, 'code': -4005}, {'did': 'speed_rpm', 'siid': 6, 'piid': 4, 'code': 0, 'value': 0}, {'did': 'powersupply_attached', 'siid': 6, 'piid': 5, 'code': 0, 'value': True}], 'exe_time': 310}
DEBUG:miio.miioprotocol:192.168.x.xxx:54321 >>: {'id': 3, 'method': 'get_properties', 'params': [{'did': 'fan_speed', 'siid': 6, 'piid': 8}, {'did': 'humidity', 'siid': 7, 'piid': 1}, {'did': 'temperature', 'siid': 7, 'piid': 7}]}
DEBUG:miio.miioprotocol:192.168.x.xxx:54321 (ts: 1970-01-04 06:09:30, id: 3) << {'id': 3, 'result': [{'did': 'fan_speed', 'siid': 6, 'piid': 8, 'code': 0, 'value': 35}, {'did': 'humidity', 'siid': 7, 'piid': 1, 'code': 0, 'value': 59}, {'did': 'temperature', 'siid': 7, 'piid': 7, 'code': 0, 'value': 31.4}], 'exe_time': 110}
Angle: 30
Battery Supported: False
Buttons Pressed: None
Buzzer: False
Child Lock: False
Delay Off Countdown: 0
Fan Level: 2
Fan Speed: 35
Humidity: 59
Ionizer: True
LED Brightness: 0
Mode: Normal
Oscillate: True
Power: off
Powersupply Attached: True
Speed RPM: 0
Temperature: 31.4

Turn ON ✔

miiocli fanza5 --debug --ip 192.168.x.xxx --token <TOKEN> on

DEBUG:miio.device:Detected model zhimi.fan.za5
DEBUG:miio.miioprotocol:192.168.x.xxx:54321 >>: {'id': 2, 'method': 'set_properties', 'params': [{'did': 'power', 'siid': 2, 'piid': 1, 'value': True}]}
DEBUG:miio.miioprotocol:192.168.x.xxx:54321 (ts: 1970-01-04 06:10:07, id: 2) << {'id': 2, 'result': [{'did': 'power', 'siid': 2, 'piid': 1, 'code': 0}], 'exe_time': 210}
[{'did': 'power', 'siid': 2, 'piid': 1, 'code': 0}]

Co-authored-by: Teemu R. <tpr@iki.fi>
Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the PR! Can you confirm that it's working with that _mappings change? I'll add some unit-tests and convert the remaining miot device implementations to avoid mapping, and will then prepare a patch release tonight.

@saxel
Copy link
Contributor Author

saxel commented Mar 7, 2022

Yes, I tested on/off/status with miiocli after your suggested change and it works the same 👍

@rytilahti rytilahti merged commit e901e2c into rytilahti:master Mar 7, 2022
@rytilahti rytilahti added the bug label Mar 7, 2022
rytilahti added a commit that referenced this pull request Mar 7, 2022
This release fixes zhimi.fan.za5 support and makes all integrations introspectable for their supported models.
For developers, there is now a network trace parser (in devtools/parse_pcap.py) that prints the decrypted the traffic for given tokens.

The following previously deprecated classes in favor of model-based discovery, if you were using these classes directly you need to adjust your code:
* AirFreshVA4 - use AirFresh
* AirHumidifierCA1, AirHumidifierCB1, AirHumidifierCB2 - use AirHumidifier
* AirDogX5, AirDogX7SM - use AirDogX3
* AirPurifierMB4 - use AirPurifierMiot
* Plug, PlugV1, PlugV3 - use ChuangmiPlug
* FanP9, FanP10, FanP11 - use FanMiot
* DreameVacuumMiot - use DreameVacuum
* Vacuum - use RoborockVacuum

[Full Changelog](0.5.10...0.5.11)

**Breaking changes:**

- Remove deprecated integration classes [\#1343](#1343) (@rytilahti)

**Implemented enhancements:**

- Add PCAP file parser for protocol analysis [\#1331](#1331) (@rytilahti)

**Fixed bugs:**

- Fix bug for zhimi.fan.za5 resulting in user ack timeout [\#1348](#1348) (@saxel)

**Deprecated:**

- Deprecate wifi\_led in favor of led [\#1342](#1342) (@rytilahti)

**Merged pull requests:**

- Make sure miotdevice implementations define supported models [\#1345](#1345) (@rytilahti)
- Add Viomi V2 \(viomi.vacuum.v6\) as supported [\#1340](#1340) (@rytilahti)
- Mark Roborock S7 MaxV \(roborock.vacuum.a27\) as supported [\#1337](#1337) (@rytilahti)
- Add pyupgrade to CI runs [\#1329](#1329) (@rytilahti)
@rytilahti rytilahti mentioned this pull request Mar 7, 2022
rytilahti added a commit that referenced this pull request Mar 7, 2022
This release fixes zhimi.fan.za5 support and makes all integrations introspectable for their supported models.
For developers, there is now a network trace parser (in devtools/parse_pcap.py) that prints the decrypted the traffic for given tokens.

The following previously deprecated classes in favor of model-based discovery, if you were using these classes directly you need to adjust your code:
* AirFreshVA4 - use AirFresh
* AirHumidifierCA1, AirHumidifierCB1, AirHumidifierCB2 - use AirHumidifier
* AirDogX5, AirDogX7SM - use AirDogX3
* AirPurifierMB4 - use AirPurifierMiot
* Plug, PlugV1, PlugV3 - use ChuangmiPlug
* FanP9, FanP10, FanP11 - use FanMiot
* DreameVacuumMiot - use DreameVacuum
* Vacuum - use RoborockVacuum

[Full Changelog](0.5.10...0.5.11)

**Breaking changes:**

- Remove deprecated integration classes [\#1343](#1343) (@rytilahti)

**Implemented enhancements:**

- Add PCAP file parser for protocol analysis [\#1331](#1331) (@rytilahti)

**Fixed bugs:**

- Fix bug for zhimi.fan.za5 resulting in user ack timeout [\#1348](#1348) (@saxel)

**Deprecated:**

- Deprecate wifi\_led in favor of led [\#1342](#1342) (@rytilahti)

**Merged pull requests:**

- Make sure miotdevice implementations define supported models [\#1345](#1345) (@rytilahti)
- Add Viomi V2 \(viomi.vacuum.v6\) as supported [\#1340](#1340) (@rytilahti)
- Mark Roborock S7 MaxV \(roborock.vacuum.a27\) as supported [\#1337](#1337) (@rytilahti)
- Add pyupgrade to CI runs [\#1329](#1329) (@rytilahti)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Found an unsupported model 'zhimi.fan.za5' for class 'FanZA5'
2 participants