[Aqara] add Aqara Bath Heater T1#2942
Conversation
|
Duplicate profile check: Passed - no duplicate profiles detected. |
|
Invitation URL: |
Test Results 73 files 512 suites 0s ⏱️ Results for commit fefff4b. ♻️ This comment has been updated with latest results. |
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against fefff4b |
| HIGH = "high", | ||
| } | ||
| local MODE_TO_FAN = { [SPEED.LOW] = FAN_LOW, [SPEED.MEDIUM] = FAN_MID, [SPEED.HIGH] = FAN_HIGH } | ||
| local FAN_TO_MODE = { [0] = SPEED.LOW, [1] = SPEED.MEDIUM, [2] = SPEED.HIGH } |
There was a problem hiding this comment.
| local FAN_TO_MODE = { [0] = SPEED.LOW, [1] = SPEED.MEDIUM, [2] = SPEED.HIGH } | |
| local FAN_TO_MODE = { [FAN_LOW] = SPEED.LOW, [FAN_MID] = SPEED.MEDIUM, [FAN_HIGH] = SPEED.HIGH } |
nit: Keep them interlocked
There was a problem hiding this comment.
I have made the requested changes.
|
|
||
| if params.setpoint ~= nil then | ||
| local sp_raw = math.floor(clamp(params.setpoint, 16, 45) * 100) & 0xFFFF | ||
| hi32 = (sp_raw << 16) | (hi32 & 0xFFFF) |
There was a problem hiding this comment.
| hi32 = (sp_raw << 16) | (hi32 & 0xFFFF) | |
| hi32 = (sp_raw << 16) | 0xFFFF |
Since hi32 is unmodified from being set to 0xFFFFFFFF and (hi32 & 0xFFFF) will always evaluate to 0xFFFF
There was a problem hiding this comment.
The unnecessary computations have been removed.
…ition since hi32 remains 0xFFFFFFFF, making (hi32 & 0xFFFF) always 0xFFFF.
cjswedes
left a comment
There was a problem hiding this comment.
I dont see a reason to not use the defaults, so I would prefer those are used.
| [OnOff.ID] = { | ||
| [OnOff.attributes.OnOff.ID] = on_off_attr_handler, | ||
| }, | ||
| [Level.ID] = { | ||
| [Level.attributes.CurrentLevel.ID] = current_level_handler, | ||
| }, | ||
| [ColorControl.ID] = { | ||
| [ColorControl.attributes.ColorTemperatureMireds.ID] = color_temp_handler, | ||
| }, |
There was a problem hiding this comment.
These handlers are also covered by the defaults
| [ColorControl.attributes.ColorTemperatureMireds.ID] = color_temp_handler, | ||
| }, | ||
| [aqara.CLUSTER_ID] = { | ||
| [aqara.ATTR_AC_CODE] = ac_code_attr_handler, |
There was a problem hiding this comment.
I dont see any reporting configuration setup for this attribute. Does Aqara just automatically do the reporting?
There was a problem hiding this comment.
Yes, the aqara.ATTR_AC_CODE attribute under the aqara.CLUSTER_ID cluster is automatically reported by the device whenever there is a change in the device status. No additional reporting configuration is required for this specific attribute.
| device:emit_event(capabilities.fanOscillationMode.fanOscillationMode(st_fan)) | ||
| end | ||
|
|
||
| local function handle_fan_mode(driver, device, cmd) |
There was a problem hiding this comment.
Other handlers emit the event after the ac_code has been sent. Why not do that here? Should the other command handlers be following this pattern to ensure we are emitting events that match the reported device state (i.e. handle_fan_oscillation_mode, handle_heating_setpoint, handler_thermostat_mode) ?
There was a problem hiding this comment.
Good catch. I've adjusted the event emission timing to execute after the ac_code is sent, ensuring consistency across all command handlers as suggested.
There was a problem hiding this comment.
What is the reason for emitting the even prior to receiving the updated state from the device? If there is a failure on the device, the platform will show the wrong state.
There was a problem hiding this comment.
That's a valid point, and I was already aware of this trade-off — I understood the risk of showing an inconsistent state if the device reports a failure.
The reason I added this optimistic emit was twofold:
- Improved UX responsiveness — emitting early gives users immediate visual feedback, reducing perceived latency.
- Consistency with thermostat mode changes — the same pattern was already being used there, so I followed the same approach for uniformity.
That said, your concern is well-founded, and I've updated the code to wait for the confirmed state from the device before emitting. One exception: I've kept the optimistic emit for thermostat mode changes, as that behavior is intentional to match the UX of the Aqara app. Please take note of that when reviewing.
- Add register_for_default_handlers and call handle_refresh to eliminate duplicated code. - Update event emission to trigger after ac_code is sent for consistency across all command handlers.
nand-nor
left a comment
There was a problem hiding this comment.
This looks good to me with all the added fixes addressing others comments
- Remove optimistic emit to prevent temporary inconsistent states. - Exception: Keep optimistic emit for thermostat mode changes to match Aqara app UX.
| supported_capabilities = { | ||
| capabilities.switch, | ||
| capabilities.switchLevel, | ||
| capabilities.colorTemperature | ||
| }, |
There was a problem hiding this comment.
These should be updated to include thermostatMode, thermostatHeatingSetpoint, fanOscilalationMode, and fanMode. Its not super critical since you are not relying on any default functionality, but it also affects the default driver switch behavior (which is a rarely used path)
Check all that apply
Type of Change
Checklist
Description of Change
Summary of Completed Tests