-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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 support for Xiaomi Zero Fog Free Humidifier #33736
Conversation
This pull request needs to be manually signed off by @home-assistant/core before it can get merged. |
Hey there @rytilahti, @syssi, mind taking a look at this pull request as its been labeled with a integration ( |
Also, there is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This integration and platform needs to be refactored first to follow our design guidelines regarding fan modes, state attributes and entity access, before any more additions are made.
} | ||
|
||
AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER = { | ||
**AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER_COMMON, | ||
ATTR_TARGET_HUMIDITY: "target_humidity", | ||
ATTR_HARDWARE_VERSION: "hardware_version", | ||
ATTR_USE_TIME: "use_time", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a relative time? Relative times are not allowed in the state machine. We only allow absolute utc timestamps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this platform isn't following our design guidelines so we can not trust that the existing code is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You recently accepted PR #31729 with the same code.
I could revert this change to the state before my commit if you want. But I don't think that copy-paste is better than trivial refactoring of the code working for more than 2 years.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We won't accept this PR until the integration and platform have been refactored. That should be done in a separate PR first.
This integration and platform needs to be refactored first to follow our design guidelines regarding fan modes, state attributes and entity access, before any more additions are made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rytilahti, @syssi As code owners of the integration do you understand how it should be refactored to address this request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syssi is more knowledgeable on this specific case, but some things I feel should be refactored:
-
Moving supported features, available attributes towards the backend library.
- This involves, e.g., moving the list of available fan speeds to the backend, like was done recently for the vacuum platform.
- Homeassistant has only 3 different fan speeds (+ off), so rest of those need to be exposed over separate services (if wanted).
-
Moving supported models also towards the backend. This will simplify future developments when the backend lib is the only source of truth.
-
I think reading somewhere that sensors are preferred over custom state attributes, but cannot find the reference from the docs at the moment. So, these attributes are the ones that should be exposed through the main device: https://developers.home-assistant.io/docs/entity_fan/#properties
- This would mean creating new entities for those custom attributes, that are linked to the main device.
- We can adapt the backend to report what type of attribute something is, that can then be used inside homeassistant to create sensors, binary_sensors, switches, etc. depending on the type.
- I'm not sure what Martin means with entity access, maybe that's related?
-
Firmware information etc. should only be exposed to the device registry (https://developers.home-assistant.io/docs/device_registry_index/)
-
Lot of common code could be shared with all the platforms, e.g., the initialization is almost always the same, but is still c&p in different platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, found it (thanks @MartinHjelmare on that other PR: https://developers.home-assistant.io/docs/entity_sensor/#available-device-classes .
So in this case, to my understanding, we should have the following new entities (depending on the supported features of the device):
-
sensors:
- temperature
- humidity
-
binary_sensors:
- child lock
- led
- no water
- lid open
- buzzer
-
unknown:
- mode
- led brightness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more point, this architecture issue is relevant to this, too: home-assistant/architecture#310
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rytilahti I think that's a great plan and summary. It's not a small task though, so it will take some time and need to be taken step wise. 👍
With entity access I meant accessing the entity directly from outside the entity instead of via core or dispatcher. Direct entity access from outside is fragile since it only works after the entity has been added to home assistant. Now we also have a service helper that platforms can use to easily register services that need to call into an entity method.
core/homeassistant/components/xiaomi_miio/fan.py
Lines 573 to 574 in 0793b5a
await getattr(device, method["method"])(**params) | |
update_tasks.append(device.async_update_ha_state(True)) |
Here's the docs for the service helper:
https://developers.home-assistant.io/docs/dev_101_services#entity-services
And here's a real example how to use the service helper:
core/homeassistant/components/wled/light.py
Lines 56 to 71 in 34ecc80
platform = entity_platform.current_platform.get() | |
platform.async_register_entity_service( | |
SERVICE_EFFECT, | |
{ | |
vol.Optional(ATTR_EFFECT): vol.Any(cv.positive_int, cv.string), | |
vol.Optional(ATTR_INTENSITY): vol.All( | |
vol.Coerce(int), vol.Range(min=0, max=255) | |
), | |
vol.Optional(ATTR_REVERSE): cv.boolean, | |
vol.Optional(ATTR_SPEED): vol.All( | |
vol.Coerce(int), vol.Range(min=0, max=255) | |
), | |
}, | |
"async_effect", | |
) |
ATTR_TRANS_LEVEL: "trans_level", | ||
ATTR_BUTTON_PRESSED: "button_pressed", | ||
} | ||
|
||
AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER_CA_AND_CB = { | ||
**AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER_COMMON, | ||
ATTR_TARGET_HUMIDITY: "target_humidity", | ||
ATTR_HARDWARE_VERSION: "hardware_version", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static info is not meant for state attributes unless it's essential for automations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 attributes were moved from AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER_COMMON
to more specific implementations because they are not common for all humidifiers and not supported by shuii.humidifier.jsq001
.
**AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER_COMMON, | ||
ATTR_LED: "led", | ||
ATTR_NO_WATER: "no_water", | ||
ATTR_LID_OPENED: "lid_opened", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lid_opened
seems like it should be a binary sensor. We want to minimize state attributes and instead break out to as many individual sensors as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it could be a binary sensor. Could you guide me with some example of how I could replace with sate with a binary sensor?
self._led_brightness_enum = AirhumidifierJsqLedBrightness | ||
self._led_brightness_default = 0 | ||
self._operation_mode_enum = AirhumidifierJsqOperationMode | ||
self._speed_list = [mode.name for mode in AirhumidifierJsqOperationMode] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only allow the modes in the fan base entity integration:
core/homeassistant/components/fan/__init__.py
Lines 35 to 38 in cedf7e3
SPEED_OFF = "off" | |
SPEED_LOW = "low" | |
SPEED_MEDIUM = "medium" | |
SPEED_HIGH = "high" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The device does not fall into such a specification
Same issue as in #31729 (review)
Maybe relevant for this PR too: I am busy with supporting Config Flow for the Xiaomi Miio platform, see PR: #32091 |
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Breaking change
Proposed change
Add support for: Xiaomi Zero Fog Free Humidifier support (shuii.humidifier.jsq001)
Type of change
Example entry for
configuration.yaml
:Additional information
My PR to
python-miio
is already accepted and released in0.5.0.0
(see rytilahti/python-miio#642) This PR adds itegration for the device type.Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale: