add battery level sensors for yeelink.curtain.ctmt2 - #2854
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for the yeelink.curtain.ctmt2 device, including its battery level specifications, customization configurations, and Jinja templates for parsing its properties. It also enhances the update_miio_props method in device.py to support custom property getters (like get_prop) and template rendering for properties. The review feedback suggests improving the Jinja template logic in templates.py by using props.get_child | int(1) instead of props.get_child | default(1) | int to ensure a robust fallback to 1 when the value is None.
| "'coolwind_gear': val[1]," | ||
| "'venting_gear': val[2]," | ||
| "} }}", | ||
| 'yeelink_curtain_ctmt2_miio_properties': "{%- set child = props.get_child | default(1) | int %}" |
There was a problem hiding this comment.
Using props.get_child | default(1) | int can result in child being evaluated as 0 if props.get_child is None (since the default filter in Jinja only replaces undefined values by default, and None | int defaults to 0). To ensure robust fallback to 1 when the value is None or cannot be parsed, use props.get_child | int(1) instead.
| 'yeelink_curtain_ctmt2_miio_properties': "{%- set child = props.get_child | default(1) | int %}" | |
| 'yeelink_curtain_ctmt2_miio_properties': "{%- set child = props.get_child | int(1) %}" |
|
Thanks for adding battery support for 1. Should go through The data source here (
A cleaner approach would be to add a 2. Reserve iids starting from 100 In 3. The local template’s fallback is unsafe for In {%- set child = props.get_child | default(1) | int %}Jinja’s Summary The battery feature itself looks valid, but I’d prefer this be reworked into a standard |
No description provided.