mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 09:01:49 +00:00 
			
		
		
		
	Merge branch 'integration' into memory_api
This commit is contained in:
		@@ -15,7 +15,7 @@ from esphome.const import (
 | 
			
		||||
    CONF_TYPE_ID,
 | 
			
		||||
    CONF_UPDATE_INTERVAL,
 | 
			
		||||
)
 | 
			
		||||
from esphome.core import ID
 | 
			
		||||
from esphome.core import ID, Lambda
 | 
			
		||||
from esphome.cpp_generator import (
 | 
			
		||||
    LambdaExpression,
 | 
			
		||||
    MockObj,
 | 
			
		||||
@@ -310,6 +310,30 @@ async def for_condition_to_code(
 | 
			
		||||
    return var
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register_condition(
 | 
			
		||||
    "component.is_idle",
 | 
			
		||||
    LambdaCondition,
 | 
			
		||||
    maybe_simple_id(
 | 
			
		||||
        {
 | 
			
		||||
            cv.Required(CONF_ID): cv.use_id(cg.Component),
 | 
			
		||||
        }
 | 
			
		||||
    ),
 | 
			
		||||
)
 | 
			
		||||
async def component_is_idle_condition_to_code(
 | 
			
		||||
    config: ConfigType,
 | 
			
		||||
    condition_id: ID,
 | 
			
		||||
    template_arg: cg.TemplateArguments,
 | 
			
		||||
    args: TemplateArgsType,
 | 
			
		||||
) -> MockObj:
 | 
			
		||||
    comp = await cg.get_variable(config[CONF_ID])
 | 
			
		||||
    lambda_ = await cg.process_lambda(
 | 
			
		||||
        Lambda(f"return {comp}->is_idle();"), args, return_type=bool
 | 
			
		||||
    )
 | 
			
		||||
    return new_lambda_pvariable(
 | 
			
		||||
        condition_id, lambda_, StatelessLambdaCondition, template_arg
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register_action(
 | 
			
		||||
    "delay", DelayAction, cv.templatable(cv.positive_time_period_milliseconds)
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -137,7 +137,11 @@ async def lvgl_is_idle(config, condition_id, template_arg, args):
 | 
			
		||||
    lvgl = config[CONF_LVGL_ID]
 | 
			
		||||
    timeout = await lv_milliseconds.process(config[CONF_TIMEOUT])
 | 
			
		||||
    async with LambdaContext(LVGL_COMP_ARG, return_type=cg.bool_) as context:
 | 
			
		||||
        lv_add(ReturnStatement(lvgl_comp.is_idle(timeout)))
 | 
			
		||||
        lv_add(
 | 
			
		||||
            ReturnStatement(
 | 
			
		||||
                lv_expr.disp_get_inactive_time(lvgl_comp.get_disp()) > timeout
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
    var = cg.new_Pvariable(
 | 
			
		||||
        condition_id,
 | 
			
		||||
        TemplateArguments(LvglComponent, *template_arg),
 | 
			
		||||
 
 | 
			
		||||
@@ -175,7 +175,6 @@ class LvglComponent : public PollingComponent {
 | 
			
		||||
  static void monitor_cb(lv_disp_drv_t *disp_drv, uint32_t time, uint32_t px);
 | 
			
		||||
  static void render_start_cb(lv_disp_drv_t *disp_drv);
 | 
			
		||||
  void dump_config() override;
 | 
			
		||||
  bool is_idle(uint32_t idle_ms) { return lv_disp_get_inactive_time(this->disp_) > idle_ms; }
 | 
			
		||||
  lv_disp_t *get_disp() { return this->disp_; }
 | 
			
		||||
  lv_obj_t *get_scr_act() { return lv_disp_get_scr_act(this->disp_); }
 | 
			
		||||
  // Pause or resume the display.
 | 
			
		||||
 
 | 
			
		||||
@@ -103,7 +103,7 @@ template<typename... Ts> class ForCondition : public Condition<Ts...>, public Co
 | 
			
		||||
  bool check_internal() {
 | 
			
		||||
    bool cond = this->condition_->check();
 | 
			
		||||
    if (!cond)
 | 
			
		||||
      this->last_inactive_ = millis();
 | 
			
		||||
      this->last_inactive_ = App.get_loop_component_start_time();
 | 
			
		||||
    return cond;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -433,7 +433,7 @@ template<typename... Ts> class WaitUntilAction : public Action<Ts...>, public Co
 | 
			
		||||
    if (this->num_running_ == 0)
 | 
			
		||||
      return;
 | 
			
		||||
 | 
			
		||||
    auto now = millis();
 | 
			
		||||
    auto now = App.get_loop_component_start_time();
 | 
			
		||||
 | 
			
		||||
    this->var_queue_.remove_if([&](auto &queued) {
 | 
			
		||||
      auto start = std::get<uint32_t>(queued);
 | 
			
		||||
 
 | 
			
		||||
@@ -284,6 +284,7 @@ bool Component::is_ready() const {
 | 
			
		||||
         (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE ||
 | 
			
		||||
         (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_SETUP;
 | 
			
		||||
}
 | 
			
		||||
bool Component::is_idle() const { return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE; }
 | 
			
		||||
bool Component::can_proceed() { return true; }
 | 
			
		||||
bool Component::status_has_warning() const { return this->component_state_ & STATUS_LED_WARNING; }
 | 
			
		||||
bool Component::status_has_error() const { return this->component_state_ & STATUS_LED_ERROR; }
 | 
			
		||||
 
 | 
			
		||||
@@ -141,6 +141,14 @@ class Component {
 | 
			
		||||
   */
 | 
			
		||||
  bool is_in_loop_state() const;
 | 
			
		||||
 | 
			
		||||
  /** Check if this component is idle.
 | 
			
		||||
   * Being idle means being in LOOP_DONE state.
 | 
			
		||||
   * This means the component has completed setup, is not failed, but its loop is currently disabled.
 | 
			
		||||
   *
 | 
			
		||||
   * @return True if the component is idle
 | 
			
		||||
   */
 | 
			
		||||
  bool is_idle() const;
 | 
			
		||||
 | 
			
		||||
  /** Mark this component as failed. Any future timeouts/intervals/setup/loop will no longer be called.
 | 
			
		||||
   *
 | 
			
		||||
   * This might be useful if a component wants to indicate that a connection to its peripheral failed.
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,11 @@ esphome:
 | 
			
		||||
  on_shutdown:
 | 
			
		||||
    logger.log: on_shutdown
 | 
			
		||||
  on_loop:
 | 
			
		||||
    logger.log: on_loop
 | 
			
		||||
    if:
 | 
			
		||||
      condition:
 | 
			
		||||
        component.is_idle: binary_sensor_id
 | 
			
		||||
      then:
 | 
			
		||||
        logger.log: on_loop - sensor idle
 | 
			
		||||
  compile_process_limit: 1
 | 
			
		||||
  min_version: "2025.1"
 | 
			
		||||
  name_add_mac_suffix: true
 | 
			
		||||
@@ -34,5 +38,6 @@ esphome:
 | 
			
		||||
 | 
			
		||||
binary_sensor:
 | 
			
		||||
  - platform: template
 | 
			
		||||
    id: binary_sensor_id
 | 
			
		||||
    name: Other device sensor
 | 
			
		||||
    device_id: other_device
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user