Skip to content

Xiaomi MiIO Fan: Xiaomi Air Humidifier integration#12627

Merged
rytilahti merged 39 commits intohome-assistant:devfrom
syssi:feature/xiaomi-miio-airhumidifier
Mar 24, 2018
Merged

Xiaomi MiIO Fan: Xiaomi Air Humidifier integration#12627
rytilahti merged 39 commits intohome-assistant:devfrom
syssi:feature/xiaomi-miio-airhumidifier

Conversation

@syssi
Copy link
Copy Markdown
Member

@syssi syssi commented Feb 23, 2018

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):

fan:
  - platform: xiaomi_miio
    name: Xiaomi Air Humidifier
    host: 192.168.130.72
    token: 2b00042f7481c7b056c4b410d28f33cf
    model: zhimi.humidifier.v1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (88 > 79 characters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (105 > 79 characters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (104 > 79 characters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (104 > 79 characters)

@syssi syssi force-pushed the feature/xiaomi-miio-airhumidifier branch from 0be7d02 to be70837 Compare February 24, 2018 08:00
@syssi syssi changed the title Xiaomi MiIO Fan: Device support for the Xiaomi Air Humidifier Xiaomi MiIO Fan: Xiaomi Air Humidifier integration Feb 26, 2018
Copy link
Copy Markdown
Member

@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.

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unnecessary whitespace.

example: 'fan.xiaomi_miio_device'

xiaomi_miio_set_extra_features:
description: Set the extra features.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Auto detect and brightness are relevant?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.


SERVICE_SCHEMA_EXTRA_FEATURES = AIRPURIFIER_SERVICE_SCHEMA.extend({
vol.Required(ATTR_FEATURES):
vol.All(vol.Coerce(int), vol.Range(min=0))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does range work when only the min value is given?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. Clamp wouldn't work.

else:
_LOGGER.error(
'Unsupported device found! Please create an issue at '
'https://github.com/rytilahti/python.miio/issues '
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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,
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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,
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Cool! I will care about.

return

yield from self._try_command(
"Turning the learn mode of the miio device off failed.",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Auto detect versus learn mode.

Attribute "volume" added.
ATTR_BUZZER: 'buzzer',
ATTR_LED_BRIGHTNESS: 'led_brightness',
ATTR_SLEEP_MODE: 'sleep_mode',
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

too many blank lines (2)

ATTR_PURIFY_VOLUME: None,
ATTR_MODEL: self._model,
}
self._device_features = DEVICE_FEATURE_FLAGS_GENERIC
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'DEVICE_FEATURE_FLAGS_GENERIC'

@syssi syssi changed the title Xiaomi MiIO Fan: Xiaomi Air Humidifier integration [WIP] Xiaomi MiIO Fan: Xiaomi Air Humidifier integration Mar 18, 2018
@syssi syssi changed the title [WIP] Xiaomi MiIO Fan: Xiaomi Air Humidifier integration Xiaomi MiIO Fan: Xiaomi Air Humidifier integration Mar 19, 2018
Copy link
Copy Markdown
Member

@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.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this also valid for non-CA humidifiers? If yes, the comment should be updated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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()})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch!


if result:
self._state = True
self._skip_update = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Worth adding a comment wrt _skip_update here also?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The skip_update behavior is commented at the async_update already. I don't want to introduce a second comment here.

@rytilahti
Copy link
Copy Markdown
Member

As there has been no further requests for changes, let's get this merged for the next release 👍

@rytilahti rytilahti merged commit e36f27d into home-assistant:dev Mar 24, 2018
@balloob balloob mentioned this pull request Apr 13, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants