mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 23:37:34 +00:00
Merge branch 'light-dim-relative-constexpr-template' into integration
This commit is contained in:
@@ -87,12 +87,15 @@ template<typename... Ts> class LightControlAction : public Action<Ts...> {
|
||||
LightState *parent_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class DimRelativeAction : public Action<Ts...> {
|
||||
template<bool HasTransitionLength, typename... Ts> class DimRelativeAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit DimRelativeAction(LightState *parent) : parent_(parent) {}
|
||||
|
||||
TEMPLATABLE_VALUE(float, relative_brightness)
|
||||
TEMPLATABLE_VALUE(uint32_t, transition_length)
|
||||
|
||||
template<typename V> void set_transition_length(V value) requires(HasTransitionLength) {
|
||||
this->transition_length_ = value;
|
||||
}
|
||||
|
||||
void play(const Ts &...x) override {
|
||||
auto call = this->parent_->make_call();
|
||||
@@ -106,7 +109,9 @@ template<typename... Ts> class DimRelativeAction : public Action<Ts...> {
|
||||
call.set_state(new_brightness != 0.0f);
|
||||
call.set_brightness(new_brightness);
|
||||
|
||||
call.set_transition_length(this->transition_length_.optional_value(x...));
|
||||
if constexpr (HasTransitionLength) {
|
||||
call.set_transition_length(this->transition_length_.optional_value(x...));
|
||||
}
|
||||
call.perform();
|
||||
}
|
||||
|
||||
@@ -122,6 +127,9 @@ template<typename... Ts> class DimRelativeAction : public Action<Ts...> {
|
||||
float min_brightness_{0.0};
|
||||
float max_brightness_{1.0};
|
||||
LimitMode limit_mode_{LimitMode::CLAMP};
|
||||
struct NoTransition {};
|
||||
[[no_unique_address]] std::conditional_t<HasTransitionLength, TemplatableFn<uint32_t, Ts...>, NoTransition>
|
||||
transition_length_{};
|
||||
};
|
||||
|
||||
template<typename... Ts> class LightIsOnCondition : public Condition<Ts...> {
|
||||
|
||||
@@ -263,10 +263,12 @@ LIGHT_DIM_RELATIVE_ACTION_SCHEMA = cv.Schema(
|
||||
)
|
||||
async def light_dim_relative_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
has_transition_length = CONF_TRANSITION_LENGTH in config
|
||||
dim_template_arg = cg.TemplateArguments(has_transition_length, *template_arg)
|
||||
var = cg.new_Pvariable(action_id, dim_template_arg, paren)
|
||||
templ = await cg.templatable(config[CONF_RELATIVE_BRIGHTNESS], args, cg.float_)
|
||||
cg.add(var.set_relative_brightness(templ))
|
||||
if CONF_TRANSITION_LENGTH in config:
|
||||
if has_transition_length:
|
||||
templ = await cg.templatable(config[CONF_TRANSITION_LENGTH], args, cg.uint32)
|
||||
cg.add(var.set_transition_length(templ))
|
||||
if conf := config.get(CONF_BRIGHTNESS_LIMITS):
|
||||
|
||||
Reference in New Issue
Block a user