mirror of
https://github.com/esphome/esphome.git
synced 2026-02-19 07:55:35 -07:00
Use mutable globals in water heater test fixture
Use globals for away/is_on lambdas and sync them in set_action so optimistic state changes persist across loop iterations.
This commit is contained in:
@@ -4,6 +4,14 @@ host:
|
||||
api:
|
||||
logger:
|
||||
|
||||
globals:
|
||||
- id: global_away
|
||||
type: bool
|
||||
initial_value: "false"
|
||||
- id: global_is_on
|
||||
type: bool
|
||||
initial_value: "true"
|
||||
|
||||
water_heater:
|
||||
- platform: template
|
||||
id: test_boiler
|
||||
@@ -11,8 +19,8 @@ water_heater:
|
||||
optimistic: true
|
||||
current_temperature: !lambda "return 45.0f;"
|
||||
target_temperature: !lambda "return 60.0f;"
|
||||
away: !lambda "return false;"
|
||||
is_on: !lambda "return true;"
|
||||
away: !lambda "return id(global_away);"
|
||||
is_on: !lambda "return id(global_is_on);"
|
||||
# Note: No mode lambda - we want optimistic mode changes to stick
|
||||
# A mode lambda would override mode changes in loop()
|
||||
supported_modes:
|
||||
@@ -24,3 +32,8 @@ water_heater:
|
||||
min_temperature: 30.0
|
||||
max_temperature: 85.0
|
||||
target_temperature_step: 0.5
|
||||
set_action:
|
||||
- lambda: |-
|
||||
// Sync optimistic state back to globals so lambdas reflect the change
|
||||
id(global_away) = id(test_boiler).is_away();
|
||||
id(global_is_on) = id(test_boiler).is_on();
|
||||
|
||||
Reference in New Issue
Block a user