Skip to content

Commit d5481fd

Browse files
excitonclaude
andcommitted
time_based valve: move into valve/ subpackage, fix include paths and control_ dispatch
- git mv valve.py → valve/__init__.py, time_based_valve.{h,cpp} → valve/ - __init__.py: from .. import (parent package), add AUTO_LOAD = ["time_based"] - time_based_valve.h: fix include path to ../time_based_actuator.h, remove redundant setup() override (now handled by TimeBasedActuatorBase::setup()), fix control() dispatch to call control_() not control() - time_based_valve.cpp: remove TimeBasedValve::setup() — setup is owned by base - Add TestTimeBasedValveInheritance class (3 tests) to test_time_based_actuator.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4cf91fd commit d5481fd

4 files changed

Lines changed: 42 additions & 14 deletions

File tree

esphome/components/time_based/valve.py renamed to esphome/components/time_based/valve/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
from esphome.components import valve
33
import esphome.config_validation as cv
44

5-
from . import (
5+
from .. import (
66
TIME_BASED_ACTUATOR_SCHEMA,
77
TimeBasedActuatorBase,
88
apply_time_based_actuator_config,
99
time_based_ns,
1010
)
1111

12+
AUTO_LOAD = ["time_based"]
13+
1214
TimeBasedValve = time_based_ns.class_(
1315
"TimeBasedValve", TimeBasedActuatorBase, valve.Valve
1416
)

esphome/components/time_based/time_based_valve.cpp renamed to esphome/components/time_based/valve/time_based_valve.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ void TimeBasedValve::dump_config() {
1515
this->open_duration_ / 1e3f, this->close_duration_ / 1e3f);
1616
}
1717

18-
void TimeBasedValve::setup() {
19-
auto restore = this->restore_state_();
20-
if (restore.has_value()) {
21-
restore->apply(this);
22-
} else {
23-
this->position = 0.5f;
24-
this->publish_state();
25-
}
26-
}
27-
2818
ValveTraits TimeBasedValve::get_traits() {
2919
auto traits = ValveTraits();
3020
traits.set_supports_stop(true);
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "time_based_actuator.h"
3+
#include "../time_based_actuator.h"
44
#include "esphome/components/valve/valve.h"
55

66
namespace esphome::time_based {
@@ -10,12 +10,11 @@ namespace esphome::time_based {
1010
class TimeBasedValve : public TimeBasedActuatorBase, public valve::Valve {
1111
public:
1212
TimeBasedValve() { this->set_actuator(this); }
13-
void setup() override;
1413
valve::ValveTraits get_traits() override;
1514
void dump_config() override;
1615

1716
protected:
18-
void control(const valve::ValveCall &call) override { TimeBasedActuatorBase::control(call); }
17+
void control(const valve::ValveCall &call) override { TimeBasedActuatorBase::control_(call); }
1918
};
2019

2120
} // namespace esphome::time_based

tests/unit_tests/test_time_based_actuator.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,40 @@ def test_time_based_cover_component_reachable_transitively(self):
6565
assert TimeBasedCover.inherits_from(cg.Component), (
6666
"TimeBasedCover must have Component reachable via TimeBasedActuatorBase"
6767
)
68+
69+
70+
class TestTimeBasedValveInheritance:
71+
"""TimeBasedValve inherits TimeBasedActuatorBase and Valve."""
72+
73+
def test_time_based_valve_inherits_actuator_base(self):
74+
"""Verify TimeBasedValve inherits TimeBasedActuatorBase."""
75+
from esphome.components.time_based import TimeBasedActuatorBase
76+
from esphome.components.time_based.valve import TimeBasedValve
77+
78+
assert TimeBasedValve.inherits_from(TimeBasedActuatorBase), (
79+
f"TimeBasedValve does not inherit from TimeBasedActuatorBase. "
80+
f"TimeBasedValve parents: {getattr(TimeBasedValve, '_parents', 'N/A')}"
81+
)
82+
83+
def test_time_based_valve_inherits_valve(self):
84+
"""The TimeBasedValve must inherit from Valve."""
85+
from esphome.components.time_based.valve import TimeBasedValve
86+
from esphome.components.valve import Valve
87+
88+
assert TimeBasedValve.inherits_from(Valve), (
89+
f"TimeBasedValve does not inherit from Valve. "
90+
f"TimeBasedValve parents: {getattr(TimeBasedValve, '_parents', 'N/A')}"
91+
)
92+
93+
def test_time_based_valve_component_reachable_transitively(self):
94+
"""Component is reachable via TimeBasedActuatorBase, not as a direct parent of TimeBasedValve.
95+
96+
TimeBasedValve's direct parents are TimeBasedActuatorBase and Valve.
97+
Component lifecycle flows through TimeBasedActuatorBase.
98+
"""
99+
import esphome.codegen as cg
100+
from esphome.components.time_based.valve import TimeBasedValve
101+
102+
assert TimeBasedValve.inherits_from(cg.Component), (
103+
"TimeBasedValve must have Component reachable via TimeBasedActuatorBase"
104+
)

0 commit comments

Comments
 (0)