mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 18:46:02 +00:00
[cover] Address Copilot review on integration test fixture and macro comments
This commit is contained in:
@@ -51,8 +51,9 @@ namespace cover_action_detail {
|
||||
template<int Tag> struct Empty {};
|
||||
} // namespace cover_action_detail
|
||||
|
||||
// X-macro: (type, field_name, bit_index). Order/bits must match
|
||||
// cover_control_to_code's FIELDS table in __init__.py.
|
||||
// X-macro: (type, field_name, bit_index). Order/bits must match the
|
||||
// inline field-mask computation in cover_control_to_code in __init__.py:
|
||||
// stop=bit 0, position=bit 1 (also set by CONF_STATE), tilt=bit 2.
|
||||
#define COVER_CONTROL_FIELDS(X) \
|
||||
X(bool, stop, 0) \
|
||||
X(float, position, 1) \
|
||||
@@ -86,8 +87,10 @@ template<uint16_t Fields, typename... Ts> class ControlAction : public Action<Ts
|
||||
};
|
||||
#undef COVER_CONTROL_FIELDS
|
||||
|
||||
// X-macro: (type, field_name, bit_index). Order/bits must match
|
||||
// cover_template_publish_to_code's FIELDS table in template/cover/__init__.py.
|
||||
// X-macro: (type, field_name, bit_index). Order/bits must match the
|
||||
// inline bitmask built in cover_template_publish_to_code in
|
||||
// template/cover/__init__.py: position=bit 0 (also set by CONF_STATE),
|
||||
// tilt=bit 1, current_operation=bit 2.
|
||||
#define COVER_PUBLISH_FIELDS(X) \
|
||||
X(float, position, 0) \
|
||||
X(float, tilt, 1) \
|
||||
|
||||
@@ -64,16 +64,7 @@ button:
|
||||
position: 25%
|
||||
tilt: 30%
|
||||
|
||||
# Test 4: cover.control with stop only (mask 0b001 = 1)
|
||||
- platform: template
|
||||
id: btn_stop
|
||||
name: "Stop Cover"
|
||||
on_press:
|
||||
- cover.control:
|
||||
id: test_cover
|
||||
stop: true
|
||||
|
||||
# Test 5: cover.control with state alias (sets position bit via CONF_STATE)
|
||||
# Test 4: cover.control with state alias (sets position bit via CONF_STATE)
|
||||
- platform: template
|
||||
id: btn_open_state
|
||||
name: "Open State"
|
||||
@@ -82,7 +73,7 @@ button:
|
||||
id: test_cover
|
||||
state: OPEN
|
||||
|
||||
# Test 6: cover.control with lambda position (exercises lambda path)
|
||||
# Test 5: cover.control with lambda position (exercises lambda path)
|
||||
- platform: template
|
||||
id: btn_lambda_position
|
||||
name: "Lambda Position"
|
||||
@@ -91,7 +82,7 @@ button:
|
||||
id: test_cover
|
||||
position: !lambda "return id(test_position);"
|
||||
|
||||
# Test 7: cover.template.publish position only (mask 0b001)
|
||||
# Test 6: cover.template.publish position only (mask 0b001)
|
||||
- platform: template
|
||||
id: btn_publish_pos
|
||||
name: "Publish Pos"
|
||||
@@ -100,7 +91,7 @@ button:
|
||||
id: test_cover
|
||||
position: 0.6
|
||||
|
||||
# Test 8: cover.template.publish current_operation only (mask 0b100)
|
||||
# Test 7: cover.template.publish current_operation only (mask 0b100)
|
||||
- platform: template
|
||||
id: btn_publish_op
|
||||
name: "Publish Op"
|
||||
@@ -108,3 +99,13 @@ button:
|
||||
- cover.template.publish:
|
||||
id: test_cover
|
||||
current_operation: OPENING
|
||||
|
||||
# Test 8: cover.control with stop only (mask 0b001 = 1) — runs after
|
||||
# Publish Op so we can verify current_operation transitions OPENING -> IDLE
|
||||
- platform: template
|
||||
id: btn_stop
|
||||
name: "Stop Cover"
|
||||
on_press:
|
||||
- cover.control:
|
||||
id: test_cover
|
||||
stop: true
|
||||
|
||||
@@ -84,3 +84,9 @@ async def test_cover_control_action(
|
||||
state = await press_and_wait("Publish Op")
|
||||
# CoverOperation.OPENING == 1
|
||||
assert state.current_operation == 1
|
||||
|
||||
# Test 8: cover.control stop only (mask 1)
|
||||
# The template cover's stop_action publishes current_operation: IDLE
|
||||
state = await press_and_wait("Stop Cover")
|
||||
# CoverOperation.IDLE == 0
|
||||
assert state.current_operation == 0
|
||||
|
||||
Reference in New Issue
Block a user