mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 00:51:49 +00:00 
			
		
		
		
	Add priority to on_shutdown trigger (#3644)
This commit is contained in:
		@@ -93,7 +93,12 @@ class StartupTrigger : public Trigger<>, public Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class ShutdownTrigger : public Trigger<>, public Component {
 | 
					class ShutdownTrigger : public Trigger<>, public Component {
 | 
				
			||||||
 public:
 | 
					 public:
 | 
				
			||||||
 | 
					  explicit ShutdownTrigger(float setup_priority) : setup_priority_(setup_priority) {}
 | 
				
			||||||
  void on_shutdown() override { this->trigger(); }
 | 
					  void on_shutdown() override { this->trigger(); }
 | 
				
			||||||
 | 
					  float get_setup_priority() const override { return this->setup_priority_; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 protected:
 | 
				
			||||||
 | 
					  float setup_priority_;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class LoopTrigger : public Trigger<>, public Component {
 | 
					class LoopTrigger : public Trigger<>, public Component {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -117,6 +117,7 @@ CONFIG_SCHEMA = cv.All(
 | 
				
			|||||||
            cv.Optional(CONF_ON_SHUTDOWN): automation.validate_automation(
 | 
					            cv.Optional(CONF_ON_SHUTDOWN): automation.validate_automation(
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ShutdownTrigger),
 | 
					                    cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ShutdownTrigger),
 | 
				
			||||||
 | 
					                    cv.Optional(CONF_PRIORITY, default=600.0): cv.float_,
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            cv.Optional(CONF_ON_LOOP): automation.validate_automation(
 | 
					            cv.Optional(CONF_ON_LOOP): automation.validate_automation(
 | 
				
			||||||
@@ -291,7 +292,7 @@ async def _add_automations(config):
 | 
				
			|||||||
        await automation.build_automation(trigger, [], conf)
 | 
					        await automation.build_automation(trigger, [], conf)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for conf in config.get(CONF_ON_SHUTDOWN, []):
 | 
					    for conf in config.get(CONF_ON_SHUTDOWN, []):
 | 
				
			||||||
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
 | 
					        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf.get(CONF_PRIORITY))
 | 
				
			||||||
        await cg.register_component(trigger, conf)
 | 
					        await cg.register_component(trigger, conf)
 | 
				
			||||||
        await automation.build_automation(trigger, [], conf)
 | 
					        await automation.build_automation(trigger, [], conf)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user