mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 08:55:36 +00:00
Merge branch 'inline-continuation-actions' into integration
This commit is contained in:
@@ -75,6 +75,13 @@ SENSOR_SCHEMA = cv.Schema({}).extend(zephyr_sensor)
|
||||
SWITCH_SCHEMA = cv.Schema({}).extend(zephyr_switch)
|
||||
NUMBER_SCHEMA = cv.Schema({}).extend(zephyr_number)
|
||||
|
||||
|
||||
def _validate_router_sleepy(config: ConfigType) -> ConfigType:
|
||||
if config.get(CONF_ROUTER) and config.get(CONF_SLEEPY):
|
||||
raise cv.Invalid("router and sleepy are mutually exclusive")
|
||||
return config
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
{
|
||||
@@ -82,10 +89,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Optional(CONF_MODEL, default=CORE.name): cv.All(
|
||||
cv.string, cv.Length(max=31)
|
||||
),
|
||||
cv.OnlyWith(CONF_ROUTER, "esp32", default=False): cv.All(
|
||||
cv.requires_component("esp32"),
|
||||
cv.boolean,
|
||||
),
|
||||
cv.Optional(CONF_ROUTER, default=False): cv.boolean,
|
||||
cv.Optional(CONF_ON_JOIN): cv.All(
|
||||
cv.requires_component("nrf52"),
|
||||
automation.validate_automation(single=True),
|
||||
@@ -113,6 +117,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA),
|
||||
_validate_router_sleepy,
|
||||
zigbee_require_vfs_select,
|
||||
zigbee_set_core_data,
|
||||
cv.Any(
|
||||
|
||||
@@ -190,7 +190,9 @@ void ZigbeeComponent::setup() {
|
||||
ESP_LOGE(TAG, "Cannot load settings, err: %d", err);
|
||||
return;
|
||||
}
|
||||
#ifdef CONFIG_ZIGBEE_ROLE_END_DEVICE
|
||||
zigbee_configure_sleepy_behavior(this->sleepy_);
|
||||
#endif
|
||||
zigbee_enable();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ from esphome.types import ConfigType
|
||||
from .const import (
|
||||
CONF_ON_JOIN,
|
||||
CONF_POWER_SOURCE,
|
||||
CONF_ROUTER,
|
||||
CONF_WIPE_ON_BOOT,
|
||||
KEY_ZIGBEE,
|
||||
POWER_SOURCE,
|
||||
@@ -160,7 +161,10 @@ zephyr_number = cv.Schema(
|
||||
async def zephyr_to_code(config: ConfigType) -> None:
|
||||
zephyr_add_prj_conf("ZIGBEE", True)
|
||||
zephyr_add_prj_conf("ZIGBEE_APP_UTILS", True)
|
||||
zephyr_add_prj_conf("ZIGBEE_ROLE_END_DEVICE", True)
|
||||
if config[CONF_ROUTER]:
|
||||
zephyr_add_prj_conf("ZIGBEE_ROLE_ROUTER", True)
|
||||
else:
|
||||
zephyr_add_prj_conf("ZIGBEE_ROLE_END_DEVICE", True)
|
||||
|
||||
zephyr_add_prj_conf("ZIGBEE_CHANNEL_SELECTION_MODE_MULTI", True)
|
||||
|
||||
|
||||
@@ -273,18 +273,28 @@ template<typename... Ts> class WhileLoopContinuation : public Action<Ts...> {
|
||||
WhileAction<Ts...> *parent_;
|
||||
};
|
||||
|
||||
// Wraps a ContinuationAction when Enabled, empty otherwise.
|
||||
// Lets IfAction elide the else continuation when HasElse is false.
|
||||
template<bool Enabled, typename... Ts> struct OptionalContinuation {
|
||||
ContinuationAction<Ts...> action;
|
||||
explicit OptionalContinuation(Action<Ts...> *parent) : action(parent) {}
|
||||
};
|
||||
template<typename... Ts> struct OptionalContinuation<false, Ts...> {
|
||||
explicit OptionalContinuation(Action<Ts...> * /*parent*/) {}
|
||||
};
|
||||
|
||||
template<bool HasElse, typename... Ts> class IfAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit IfAction(Condition<Ts...> *condition) : condition_(condition) {}
|
||||
|
||||
void add_then(const std::initializer_list<Action<Ts...> *> &actions) {
|
||||
this->then_.add_actions(actions);
|
||||
this->then_.add_action(new ContinuationAction<Ts...>(this));
|
||||
this->then_.add_action(&this->then_continuation_);
|
||||
}
|
||||
|
||||
void add_else(const std::initializer_list<Action<Ts...> *> &actions) requires(HasElse) {
|
||||
this->else_.add_actions(actions);
|
||||
this->else_.add_action(new ContinuationAction<Ts...>(this));
|
||||
this->else_.add_action(&this->else_continuation_.action);
|
||||
}
|
||||
|
||||
void play_complex(const Ts &...x) override {
|
||||
@@ -316,8 +326,10 @@ template<bool HasElse, typename... Ts> class IfAction : public Action<Ts...> {
|
||||
protected:
|
||||
Condition<Ts...> *condition_;
|
||||
ActionList<Ts...> then_;
|
||||
ContinuationAction<Ts...> then_continuation_{this};
|
||||
struct NoElse {};
|
||||
[[no_unique_address]] std::conditional_t<HasElse, ActionList<Ts...>, NoElse> else_;
|
||||
[[no_unique_address]] OptionalContinuation<HasElse, Ts...> else_continuation_{this};
|
||||
};
|
||||
|
||||
template<typename... Ts> class WhileAction : public Action<Ts...> {
|
||||
@@ -326,7 +338,7 @@ template<typename... Ts> class WhileAction : public Action<Ts...> {
|
||||
|
||||
void add_then(const std::initializer_list<Action<Ts...> *> &actions) {
|
||||
this->then_.add_actions(actions);
|
||||
this->then_.add_action(new WhileLoopContinuation<Ts...>(this));
|
||||
this->then_.add_action(&this->loop_continuation_);
|
||||
}
|
||||
|
||||
friend class WhileLoopContinuation<Ts...>;
|
||||
@@ -354,6 +366,7 @@ template<typename... Ts> class WhileAction : public Action<Ts...> {
|
||||
protected:
|
||||
Condition<Ts...> *condition_;
|
||||
ActionList<Ts...> then_;
|
||||
WhileLoopContinuation<Ts...> loop_continuation_{this};
|
||||
};
|
||||
|
||||
// Implementation of WhileLoopContinuation::play
|
||||
@@ -388,7 +401,7 @@ template<typename... Ts> class RepeatAction : public Action<Ts...> {
|
||||
|
||||
void add_then(const std::initializer_list<Action<uint32_t, Ts...> *> &actions) {
|
||||
this->then_.add_actions(actions);
|
||||
this->then_.add_action(new RepeatLoopContinuation<Ts...>(this));
|
||||
this->then_.add_action(&this->loop_continuation_);
|
||||
}
|
||||
|
||||
friend class RepeatLoopContinuation<Ts...>;
|
||||
@@ -409,6 +422,7 @@ template<typename... Ts> class RepeatAction : public Action<Ts...> {
|
||||
|
||||
protected:
|
||||
ActionList<uint32_t, Ts...> then_;
|
||||
RepeatLoopContinuation<Ts...> loop_continuation_{this};
|
||||
};
|
||||
|
||||
// Implementation of RepeatLoopContinuation::play
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
<<: !include common_nrf52.yaml
|
||||
|
||||
zigbee:
|
||||
router: true
|
||||
|
||||
Reference in New Issue
Block a user