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

Add Air Purifier 4 and Air Purifier 4 Lite #284

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion custom_components/xiaomi_miio_airpurifier/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
MODEL_AIRPURIFIER_3 = "zhimi.airpurifier.ma4"
MODEL_AIRPURIFIER_3H = "zhimi.airpurifier.mb3"
MODEL_AIRPURIFIER_ZA1 = "zhimi.airpurifier.za1"
MODEL_AIRPURIFIER_4_PRO = "zhimi.airp.vb4"
MODEL_AIRPURIFIER_4_LITE = "zhimi.airp.rmb1"
MODEL_AIRPURIFIER_AIRDOG_X3 = "airdog.airpurifier.x3"
MODEL_AIRPURIFIER_AIRDOG_X5 = "airdog.airpurifier.x5"
MODEL_AIRPURIFIER_AIRDOG_X7SM = "airdog.airpurifier.x7sm"
Expand Down Expand Up @@ -183,6 +185,8 @@
MODEL_AIRPURIFIER_3,
MODEL_AIRPURIFIER_3H,
MODEL_AIRPURIFIER_ZA1,
MODEL_AIRPURIFIER_4_PRO,
MODEL_AIRPURIFIER_4_LITE,
MODEL_AIRPURIFIER_AIRDOG_X3,
MODEL_AIRPURIFIER_AIRDOG_X5,
MODEL_AIRPURIFIER_AIRDOG_X7SM,
Expand Down Expand Up @@ -259,6 +263,11 @@
ATTR_VOLUME = "volume"
ATTR_USE_TIME = "use_time"
ATTR_BUTTON_PRESSED = "button_pressed"
ATTR_ANION = "anion"
ATTR_PM10_DENSITY = "pm10_density"
ATTR_FILTER_LEFT_TIME = "filter_left_time"
ATTR_FAVORITE_RPM = "favorite_rpm"
ATTR_DISPLAY_UNIT = "device-display-unit"

# Air Humidifier
ATTR_TARGET_HUMIDITY = "target_humidity"
Expand Down Expand Up @@ -322,7 +331,7 @@
# Fan Leshow SS4
ATTR_ERROR_DETECTED = "error_detected"

PURIFIER_MIOT = [MODEL_AIRPURIFIER_3, MODEL_AIRPURIFIER_3H, MODEL_AIRPURIFIER_ZA1]
PURIFIER_MIOT = [MODEL_AIRPURIFIER_3, MODEL_AIRPURIFIER_3H, MODEL_AIRPURIFIER_ZA1, MODEL_AIRPURIFIER_4_PRO, MODEL_AIRPURIFIER_4_LITE]
HUMIDIFIER_MIOT = [MODEL_AIRHUMIDIFIER_CA4]

# AirDogX7SM
Expand Down Expand Up @@ -465,6 +474,48 @@
ATTR_BUTTON_PRESSED: "button_pressed",
}

AVAILABLE_ATTRIBUTES_AIRPURIFIER_4_PRO = {
ATTR_POWER: "power",
ATTR_MODE: "mode",
ATTR_FAN_LEVEL: "fan_level",
ATTR_ANION: "anion",
ATTR_HUMIDITY: "humidity",
ATTR_AIR_QUALITY_INDEX: "aqi",
ATTR_TEMPERATURE: "temperature",
ATTR_PM10_DENSITY: "pm10_density",
ATTR_FILTER_LIFE: "filter_life_remaining",
ATTR_FILTER_HOURS_USED: "filter_hours_used",
ATTR_FILTER_LEFT_TIME: "filter_left_time",
ATTR_BUZZER: "buzzer",
ATTR_CHILD_LOCK: "child_lock",
ATTR_MOTOR_SPEED: "motor_speed",
ATTR_FAVORITE_RPM: "favorite_rpm",
ATTR_FAVORITE_LEVEL: "favorite_level",
ATTR_PURIFY_VOLUME: "purify_volume",
ATTR_AVERAGE_AIR_QUALITY_INDEX: "average_aqi",
ATTR_FILTER_RFID_TAG: "filter_rfid_tag",
ATTR_FILTER_RFID_PRODUCT_ID: "filter_rfid_product_id",
ATTR_LED_BRIGHTNESS: "led_brightness",
ATTR_DISPLAY_UNIT: "device-display-unit"
}

AVAILABLE_ATTRIBUTES_AIRPURIFIER_4_LITE = {
ATTR_POWER: "power",
ATTR_MODE: "mode",
ATTR_HUMIDITY: "humidity",
ATTR_AIR_QUALITY_INDEX: "aqi",
ATTR_TEMPERATURE: "temperature",
ATTR_FILTER_LIFE: "filter_life_remaining",
ATTR_FILTER_HOURS_USED: "filter_hours_used",
ATTR_FILTER_LEFT_TIME: "filter_left_time",
ATTR_BUZZER: "buzzer",
ATTR_CHILD_LOCK: "child_lock",
ATTR_MOTOR_SPEED: "motor_speed",
ATTR_FAVORITE_LEVEL: "favorite_level",
ATTR_LED_BRIGHTNESS: "led_brightness",
ATTR_DISPLAY_UNIT: "device-display-unit"
}

AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER_COMMON = {
ATTR_TEMPERATURE: "temperature",
ATTR_HUMIDITY: "humidity",
Expand Down Expand Up @@ -722,6 +773,8 @@
"High",
"Strong",
]
OPERATION_MODES_AIRPURIFIER_4_PRO = ["Auto", "Sleep", "Favorite", "Manual"]
OPERATION_MODES_AIRPURIFIER_4_LITE = ["Auto", "Sleep", "Favorite"]
OPERATION_MODES_AIRFRESH = ["Auto", "Silent", "Interval", "Low", "Middle", "Strong"]
OPERATION_MODES_AIRFRESH_T2017 = ["Auto", "Sleep", "Favorite"]

Expand Down Expand Up @@ -808,6 +861,24 @@
FEATURE_SET_BUZZER | FEATURE_SET_CHILD_LOCK | FEATURE_SET_LED
)

FEATURE_FLAGS_AIRPURIFIER_4_PRO = (
FEATURE_SET_BUZZER
| FEATURE_SET_CHILD_LOCK
| FEATURE_SET_LED
| FEATURE_SET_FAVORITE_LEVEL
| FEATURE_SET_FAN_LEVEL
| FEATURE_SET_LED_BRIGHTNESS
)

FEATURE_FLAGS_AIRPURIFIER_4_LITE = (
FEATURE_SET_BUZZER
| FEATURE_SET_CHILD_LOCK
| FEATURE_SET_LED
| FEATURE_SET_FAVORITE_LEVEL
| FEATURE_SET_FAN_LEVEL
| FEATURE_SET_LED_BRIGHTNESS
)

FEATURE_FLAGS_AIRHUMIDIFIER = (
FEATURE_SET_BUZZER
| FEATURE_SET_CHILD_LOCK
Expand Down Expand Up @@ -1424,6 +1495,14 @@ def __init__(self, name, device, model, unique_id, retries=0):
self._device_features = FEATURE_FLAGS_AIRPURIFIER_V3
self._available_attributes = AVAILABLE_ATTRIBUTES_AIRPURIFIER_V3
self._preset_modes = OPERATION_MODES_AIRPURIFIER_V3
elif self._model == MODEL_AIRPURIFIER_4_PRO:
self._device_features = FEATURE_FLAGS_AIRPURIFIER_4_PRO
self._available_attributes = AVAILABLE_ATTRIBUTES_AIRPURIFIER_4_PRO
self._preset_modes = OPERATION_MODES_AIRPURIFIER_4_PRO
elif self._model == MODEL_AIRPURIFIER_4_LITE:
self._device_features = FEATURE_FLAGS_AIRPURIFIER_4_LITE
self._available_attributes = AVAILABLE_ATTRIBUTES_AIRPURIFIER_4_LITE
self._preset_modes = OPERATION_MODES_AIRPURIFIER_4_LITE
else:
self._device_features = FEATURE_FLAGS_AIRPURIFIER
self._available_attributes = AVAILABLE_ATTRIBUTES_AIRPURIFIER
Expand Down