Skip to content

Add support for Xiaomi Smart Air Purifier 4 Compact (xiaomi.airp.cpa4) - #2100

Open
boris-timofeenko wants to merge 1 commit into
rytilahti:masterfrom
boris-timofeenko:add-xiaomi-airp-cpa4
Open

boris-timofeenko wants to merge 1 commit into
rytilahti:masterfrom
boris-timofeenko:add-xiaomi-airp-cpa4

Conversation

@boris-timofeenko

Copy link
Copy Markdown

Adds the Xiaomi Smart Air Purifier 4 Compact (EU, product page) to the AirPurifierMiot integration.

Model string

miIO.info on this device reports the model as xiaomi.airp.cpa4 (firmware 2.2.10_0021, hardware esp32; the same string was reported in #1869). The Xiaomi cloud and the public spec list the device as zhimi.airp.cpa4, so the mapping is keyed on the string the library actually sees. Spec: https://home.miot-spec.com/spec/zhimi.airp.cpa4 (same instance as https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-cpa4:1).

Changes

  • _MAPPING_CPA4 with only the properties verified on the device, registered under xiaomi.airp.cpa4.
  • The screen brightness is 0 off / 1 dim / 2 brightest, like the other siid 13 screens, so the model is added to REVERSED_LED_BRIGHTNESS.
  • status() asks for at most three properties per request for this model. The purifier beeps, flashes its Wi-Fi icon and drops off the network when asked for four or more at once (Xiaomi Purifier 4 Compact #1550); three is the highest value reported to work there, and it works on firmware 2.2.10_0021.
  • A unit test with the values read from the device, and the README list of supported devices.

Properties, as read from the device today (firmware 2.2.10_0021)

name siid / piid spec value
power 2 / 1 on True
fault 2 / 2 fault (0 none, 2 motor stuck, 3 sensor lost) 0
mode 2 / 4 mode (0 auto, 1 sleep, 2 favorite) 2
aqi 3 / 4 pm2.5-density, 0–600 µg/m³ 13
filter_life_remaining 4 / 1 filter-life-level, % 100
filter_hours_used 4 / 3 filter-used-time, h 3
filter_left_time 4 / 4 filter-left-time, days 291
buzzer 6 / 1 alarm True
child_lock 8 / 1 physical-controls-locked False
motor_speed 9 / 1 moto-speed-rpm 2064 (favorite level 14; 416 rpm in auto mode earlier the same day)
favorite_level 9 / 11 favorite-level, 0–14 14
led_brightness 13 / 2 brightness (0 close, 1 bright, 2 brightest) 2 → LedBrightness.Bright

Not mapped on purpose: the spec has no temperature, humidity, fan level, LED switch, favorite rpm or purify volume for this device. country-code (9/10), aqi-updata-heartbeat (11/4), the write-only filter-used-time-dbg (9/12) and the three actions (toggle, reset-filter-life, toggle-mode) exist in the spec but nothing in AirPurifierMiotStatus uses them.

Testing

On the device:

$ miiocli device --ip <ip> --token <token> info
Model: xiaomi.airp.cpa4
Hardware version: esp32
Firmware version: 2.2.10_0021
Supported using: AirPurifierMiot
Supported by genericmiot: True

$ miiocli airpurifiermiot --ip <ip> --token <token> status
rw- Power (AirPurifierMiotStatus.power): on
r-- Air Quality Index (AirPurifierMiotStatus.aqi): 13 μg/m³
rw- Buzzer (AirPurifierMiotStatus.buzzer): True
rw- Child Lock (AirPurifierMiotStatus.child_lock): False
r-- Filter Life Remaining (AirPurifierMiotStatus.filter_life_remaining): 100 %
r-- Filter Hours Used (AirPurifierMiotStatus.filter_hours_used): 3 h
r-- Motor Speed (AirPurifierMiotStatus.motor_speed): 2064 rpm
rw- LED Brightness (AirPurifierMiotStatus.led_brightness): LedBrightness.Bright
rw- Favorite Level (AirPurifierMiotStatus.favorite_level): 14
r-- Filter Left Time (AirPurifierMiotStatus.filter_left_time): 291 days

Before this change the same status call fell back to the zhimi.airpurifier.ma4 mapping and made the device drop off the network.

Locally: uv run pytest miio (1515 passed, 7 skipped, 1 xfailed) and uv run pre-commit run --all-files pass.

Related work

Thanks to fredpoint76 for the initial work on this device in #2057. This PR differs in that the mapping is keyed on xiaomi.airp.cpa4, the string miIO.info reports (the cloud listing uses zhimi.airp.cpa4); only properties verified on firmware 2.2.10_0021 are mapped (the spec has no fan_level 2/5 or favorite_rpm 9/3 for this device); a unit test is included; and there are no changes outside the air purifier integration.

🤖 Generated with Claude Code

The device reports itself as xiaomi.airp.cpa4 over miIO, while the Xiaomi
cloud and the public spec list it as zhimi.airp.cpa4, so the mapping is
keyed on the string the library actually sees. Only the properties
verified on firmware 2.2.10_0021 are mapped. The purifier beeps and drops
off the network when asked for more than three properties at once (rytilahti#1550),
so status() requests at most three per call for this model.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.39%. Comparing base (9a00e08) to head (2689b31).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2100      +/-   ##
==========================================
+ Coverage   84.31%   84.39%   +0.07%     
==========================================
  Files         201      201              
  Lines       20656    20735      +79     
  Branches     1121     1122       +1     
==========================================
+ Hits        17417    17500      +83     
+ Misses       3047     3042       -5     
- Partials      192      193       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant