mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Move automations to automation.h, remove network dependency
				
					
				
			This commit is contained in:
		| @@ -6,7 +6,6 @@ from esphome.const import CONF_ESPHOME, CONF_OTA, CONF_PLATFORM, CONF_TRIGGER_ID | ||||
|  | ||||
| CODEOWNERS = ["@esphome/core"] | ||||
| AUTO_LOAD = ["md5"] | ||||
| DEPENDENCIES = ["network"] | ||||
|  | ||||
| IS_PLATFORM_COMPONENT = True | ||||
|  | ||||
|   | ||||
							
								
								
									
										67
									
								
								esphome/components/ota/automation.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								esphome/components/ota/automation.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,67 @@ | ||||
| #pragma once | ||||
| #ifdef USE_OTA_STATE_CALLBACK | ||||
| #include "ota_backend.h" | ||||
|  | ||||
| #include "esphome/core/automation.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace ota { | ||||
|  | ||||
| class OTAStateChangeTrigger : public Trigger<OTAState> { | ||||
|  public: | ||||
|   explicit OTAStateChangeTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (!parent->is_failed()) { | ||||
|         return trigger(state); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class OTAStartTrigger : public Trigger<> { | ||||
|  public: | ||||
|   explicit OTAStartTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (state == OTA_STARTED && !parent->is_failed()) { | ||||
|         trigger(); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class OTAProgressTrigger : public Trigger<float> { | ||||
|  public: | ||||
|   explicit OTAProgressTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (state == OTA_IN_PROGRESS && !parent->is_failed()) { | ||||
|         trigger(progress); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class OTAEndTrigger : public Trigger<> { | ||||
|  public: | ||||
|   explicit OTAEndTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (state == OTA_COMPLETED && !parent->is_failed()) { | ||||
|         trigger(); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class OTAErrorTrigger : public Trigger<uint8_t> { | ||||
|  public: | ||||
|   explicit OTAErrorTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (state == OTA_ERROR && !parent->is_failed()) { | ||||
|         trigger(error); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| }  // namespace ota | ||||
| }  // namespace esphome | ||||
| #endif | ||||
| @@ -65,67 +65,5 @@ class OTAComponent : public Component { | ||||
| }; | ||||
|  | ||||
| std::unique_ptr<ota::OTABackend> make_ota_backend(); | ||||
|  | ||||
| /// | ||||
| /// Automations | ||||
| /// | ||||
|  | ||||
| #ifdef USE_OTA_STATE_CALLBACK | ||||
| class OTAStateChangeTrigger : public Trigger<OTAState> { | ||||
|  public: | ||||
|   explicit OTAStateChangeTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (!parent->is_failed()) { | ||||
|         return trigger(state); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class OTAStartTrigger : public Trigger<> { | ||||
|  public: | ||||
|   explicit OTAStartTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (state == OTA_STARTED && !parent->is_failed()) { | ||||
|         trigger(); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class OTAProgressTrigger : public Trigger<float> { | ||||
|  public: | ||||
|   explicit OTAProgressTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (state == OTA_IN_PROGRESS && !parent->is_failed()) { | ||||
|         trigger(progress); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class OTAEndTrigger : public Trigger<> { | ||||
|  public: | ||||
|   explicit OTAEndTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (state == OTA_COMPLETED && !parent->is_failed()) { | ||||
|         trigger(); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| class OTAErrorTrigger : public Trigger<uint8_t> { | ||||
|  public: | ||||
|   explicit OTAErrorTrigger(OTAComponent *parent) { | ||||
|     parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) { | ||||
|       if (state == OTA_ERROR && !parent->is_failed()) { | ||||
|         trigger(error); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
| #endif | ||||
|  | ||||
| }  // namespace ota | ||||
| }  // namespace esphome | ||||
|   | ||||
		Reference in New Issue
	
	Block a user