Xiaomi MiIO Fan: Xiaomi Air Humidifier integration#12627
Xiaomi MiIO Fan: Xiaomi Air Humidifier integration#12627rytilahti merged 39 commits intohome-assistant:devfrom
Conversation
There was a problem hiding this comment.
continuation line under-indented for visual indent
There was a problem hiding this comment.
continuation line under-indented for visual indent
There was a problem hiding this comment.
continuation line under-indented for visual indent
There was a problem hiding this comment.
continuation line under-indented for visual indent
There was a problem hiding this comment.
continuation line under-indented for visual indent
There was a problem hiding this comment.
continuation line under-indented for visual indent
There was a problem hiding this comment.
line too long (88 > 79 characters)
There was a problem hiding this comment.
line too long (105 > 79 characters)
There was a problem hiding this comment.
line too long (104 > 79 characters)
There was a problem hiding this comment.
line too long (104 > 79 characters)
0be7d02 to
be70837
Compare
rytilahti
left a comment
There was a problem hiding this comment.
From a quick review it looks good! I left a couple of comments how it could be improved.
| description: Name of the xiaomi miio entity. | ||
| example: 'fan.xiaomi_miio_device' | ||
| humidity: | ||
| description: Target humidity. Allowed values are 30, 40, 50, 60, 70 and 80. |
| example: 'fan.xiaomi_miio_device' | ||
|
|
||
| xiaomi_miio_set_extra_features: | ||
| description: Set the extra features. |
There was a problem hiding this comment.
This could be more elaborate, what are the extra features and what are the known values below?
| example: 1 | ||
|
|
||
| xiaomi_miio_set_auto_detect_on: | ||
| description: Turn the auto detect on. |
There was a problem hiding this comment.
Auto detect and brightness are relevant?
|
|
||
| SERVICE_SCHEMA_EXTRA_FEATURES = AIRPURIFIER_SERVICE_SCHEMA.extend({ | ||
| vol.Required(ATTR_FEATURES): | ||
| vol.All(vol.Coerce(int), vol.Range(min=0)) |
There was a problem hiding this comment.
Does range work when only the min value is given?
| else: | ||
| _LOGGER.error( | ||
| 'Unsupported device found! Please create an issue at ' | ||
| 'https://github.com/rytilahti/python.miio/issues ' |
There was a problem hiding this comment.
Typo in the URL, should this be reported to homeassistant though (considering that the backend library may already support the device)? Just a thought though, this is fine for me either way.
There was a problem hiding this comment.
It would be a feature request. That's why I don't want to mention homeassistant here. I added a link to my development repository now. So we can keep the python-miio repo clean for protocol issues.
| ATTR_TURBO_MODE_SUPPORTED: None, | ||
| ATTR_SLEEP_MODE: None, | ||
| ATTR_AUTO_DETECT: None, | ||
| }) |
There was a problem hiding this comment.
Would it make sense to have a list of these attrs and simply do _state_attrs = {attr: None for attr in available_attributes} and set the model attribute afterwards?
| ATTR_EXTRA_FEATURES: state.extra_features, | ||
| ATTR_TURBO_MODE_SUPPORTED: state.turbo_mode_supported, | ||
| ATTR_AUTO_DETECT: state.auto_detect, | ||
| }) |
There was a problem hiding this comment.
The same idea that I elaborated above could be use here too, maybe the available_attributes could be a map of (attribute_name, attribute_getter)` or similar?
| return | ||
|
|
||
| yield from self._try_command( | ||
| "Turning the learn mode of the miio device off failed.", |
There was a problem hiding this comment.
Auto detect versus learn mode.
Attribute "volume" added.
| ATTR_BUZZER: 'buzzer', | ||
| ATTR_LED_BRIGHTNESS: 'led_brightness', | ||
| ATTR_SLEEP_MODE: 'sleep_mode', | ||
| }) |
There was a problem hiding this comment.
Considering minimum python version being 3.5 now, I think the following would also work to simplify it a bit more:
AVAILABLE_ATTRIBUTES_AIRPURIFIER = {**AVAILABLE_ATTRIBUTES_AIRPURIFIER_COMMON,
ATTR_BUZZER: 'buzzer',
}
Determine support features and attributes at the constructor. Use starred expressions at dicts instead of copies.
| AVAILABLE_ATTRIBUTES_AIRPURIFIER}) | ||
|
|
||
|
|
||
| @property |
| ATTR_PURIFY_VOLUME: None, | ||
| ATTR_MODEL: self._model, | ||
| } | ||
| self._device_features = DEVICE_FEATURE_FLAGS_GENERIC |
There was a problem hiding this comment.
undefined name 'DEVICE_FEATURE_FLAGS_GENERIC'
rytilahti
left a comment
There was a problem hiding this comment.
Looks great! I added some more comments, other than that I feel this can be merged. Maybe someone else could also do a quick review on this?
Generally speaking it is visible here that the amount of boilerplate required to expose extra services will become a pain to maintain in the future...
| """Call an air purifier command handling error messages.""" | ||
| @staticmethod | ||
| def _extract_value_from_attribute(state, attribute): | ||
| from enum import Enum |
There was a problem hiding this comment.
Normal imports (not related to backend libraries) should be done on top of the file.
| return [mode.name for mode in OperationMode if mode.name != 'Auto'] | ||
|
|
||
| # Air Humidifier CA | ||
| return [mode.name for mode in OperationMode] |
There was a problem hiding this comment.
Is this also valid for non-CA humidifiers? If yes, the comment should be updated.
There was a problem hiding this comment.
I'm using the V1 as new default now. The CA is a very specific device version. My approach was to provide all known operation modes to reduce it later on for specific devices.
| self._state_attrs.update( | ||
| {key: self._extract_value_from_attribute(state, value) | ||
| for key, value in | ||
| AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER.items()}) |
There was a problem hiding this comment.
This looks like repetition from above (in __init__), I think it'd make sense to have a self._available_attrs or something initialized in there.
|
|
||
| if result: | ||
| self._state = True | ||
| self._skip_update = True |
There was a problem hiding this comment.
Worth adding a comment wrt _skip_update here also?
There was a problem hiding this comment.
The skip_update behavior is commented at the async_update already. I don't want to introduce a second comment here.
…rd version doesn't
This reverts commit 40b443e.
|
As there has been no further requests for changes, let's get this merged for the next release 👍 |
Description:
Device support for the Xiaomi Air Humidifier.
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io/pull/4829
Example entry for
configuration.yaml(if applicable):