-
-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Air purifier 3/3H support (remastered) (#634)
* Add basic support for Xiaomi Mi Air Purifier 3/3H. In order to support that, also implement MiotDevice class with basic support for MIoT protocol. * Extract functionality for determining Xiaomi air filter type into a separate util class * Rename airfilter.py to airfilter_util.py to indicate it's not referring to an actual device * Tests for miot purifier # Conflicts: # miio/ceil_cli.py # miio/device.py # miio/philips_eyecare_cli.py # miio/plug_cli.py # miio/tests/dummies.py # miio/tests/test_airconditioningcompanion.py # miio/tests/test_wifirepeater.py # miio/vacuum.py # miio/vacuum_cli.py * MIoT Air Purifier: add support for fine-tuning favourite mode by "set_favorite_rpm" * MIoT Air Purifier: improve comments * airpurifier_miot: don't try to retrieve "button_pressed" as it errors out if no button was pressed since purifier started up * Version * Fix MIOT purifier tests * Added buzzer_volumw and handling missing features for miot * Fixed volume setter to be same as in non-miot purifier * Fixed incorrect comment body * Review comments fixed * Expanded documentation Co-authored-by: Petr Kotek <kotekp@google.com>
- Loading branch information
Showing
10 changed files
with
798 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import enum | ||
import re | ||
from typing import Optional | ||
|
||
|
||
class FilterType(enum.Enum): | ||
Regular = "regular" | ||
AntiBacterial = "anti-bacterial" | ||
AntiFormaldehyde = "anti-formaldehyde" | ||
Unknown = "unknown" | ||
|
||
|
||
FILTER_TYPE_RE = ( | ||
(re.compile(r"^\d+:\d+:41:30$"), FilterType.AntiBacterial), | ||
(re.compile(r"^\d+:\d+:(30|0|00):31$"), FilterType.AntiFormaldehyde), | ||
(re.compile(r".*"), FilterType.Regular), | ||
) | ||
|
||
|
||
class FilterTypeUtil: | ||
"""Utility class for determining xiaomi air filter type.""" | ||
|
||
_filter_type_cache = {} | ||
|
||
def determine_filter_type( | ||
self, rfid_tag: Optional[str], product_id: Optional[str] | ||
) -> Optional[FilterType]: | ||
""" | ||
Determine Xiaomi air filter type based on its product ID. | ||
:param rfid_tag: RFID tag value | ||
:param product_id: Product ID such as "0:0:30:33" | ||
""" | ||
if rfid_tag is None: | ||
return None | ||
if rfid_tag == "0:0:0:0:0:0:0": | ||
return FilterType.Unknown | ||
if product_id is None: | ||
return FilterType.Regular | ||
|
||
ft = self._filter_type_cache.get(product_id, None) | ||
if ft is None: | ||
for filter_re, filter_type in FILTER_TYPE_RE: | ||
if filter_re.match(product_id): | ||
ft = self._filter_type_cache[product_id] = filter_type | ||
break | ||
return ft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.