mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[http_request] Add esp-idf and rp2040 support (#3256)
* Implement http_request component for esp-idf * Fix ifdefs * Lint * clang * Set else to fail with error message * Use unique_ptr * Fix * Tidy up casting, explicit HttpResponse lifetime (#3265) Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com> * Remove unique_ptr wrapper * Fix * Use reference * Add duration code into new split files * Add config for tx/rx buffer on idf * Fix * Try reserve response data with rx buffer size * Update http_request.h * Move client cleanup to be earlier * Move capture_response to bool on struct and remove global * Fix returns * Change quotes to brackets * Rework http request * Remove http request from old test yamls * Update component tests * Validate md5 length when hardcoded string * Linting * Add duration_ms to container * More lint * const * Remove default arguments and add helper functions for get and post * Add virtual destructor to HttpContainer * Undo const HEADER_KEYS * 🤦 * Update esphome/components/http_request/ota/ota_http_request.cpp Co-authored-by: Keith Burzinski <kbx81x@gmail.com> * Update esphome/components/http_request/ota/ota_http_request.cpp Co-authored-by: Keith Burzinski <kbx81x@gmail.com> * lint * Move header keys inline * Add missing WatchdogManagers * CAPS * Fix "follow redirects" string in config dump * IDF 5+ fix --------- Co-authored-by: Daniel Cousens <413395+dcousens@users.noreply.github.com> Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com> Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
		
							
								
								
									
										75
									
								
								tests/components/http_request/common.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								tests/components/http_request/common.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,75 @@ | ||||
| substitutions: | ||||
|   verify_ssl: "true" | ||||
|  | ||||
| wifi: | ||||
|   ssid: MySSID | ||||
|   password: password1 | ||||
|  | ||||
| esphome: | ||||
|   on_boot: | ||||
|     then: | ||||
|       - http_request.get: | ||||
|           url: https://esphome.io | ||||
|           headers: | ||||
|             Content-Type: application/json | ||||
|           on_response: | ||||
|             then: | ||||
|               - logger.log: | ||||
|                   format: "Response status: %d, Duration: %u ms" | ||||
|                   args: | ||||
|                     - response->status_code | ||||
|                     - response->duration_ms | ||||
|       - http_request.post: | ||||
|           url: https://esphome.io | ||||
|           headers: | ||||
|             Content-Type: application/json | ||||
|           json: | ||||
|             key: value | ||||
|       - http_request.send: | ||||
|           method: PUT | ||||
|           url: https://esphome.io | ||||
|           headers: | ||||
|             Content-Type: application/json | ||||
|           body: "Some data" | ||||
|  | ||||
| http_request: | ||||
|   useragent: esphome/tagreader | ||||
|   timeout: 10s | ||||
|   verify_ssl: ${verify_ssl} | ||||
|  | ||||
| ota: | ||||
|   - platform: http_request | ||||
|     on_begin: | ||||
|       then: | ||||
|         - logger.log: "OTA start" | ||||
|     on_progress: | ||||
|       then: | ||||
|         - logger.log: | ||||
|             format: "OTA progress %0.1f%%" | ||||
|             args: ["x"] | ||||
|     on_end: | ||||
|       then: | ||||
|         - logger.log: "OTA end" | ||||
|     on_error: | ||||
|       then: | ||||
|         - logger.log: | ||||
|             format: "OTA update error %d" | ||||
|             args: ["x"] | ||||
|     on_state_change: | ||||
|       then: | ||||
|         lambda: 'ESP_LOGD("ota", "State %d", state);' | ||||
|  | ||||
| button: | ||||
|   - platform: template | ||||
|     name: Firmware update | ||||
|     on_press: | ||||
|       then: | ||||
|         - ota.http_request.flash: | ||||
|             md5_url: http://my.ha.net:8123/local/esphome/firmware.md5 | ||||
|             url: http://my.ha.net:8123/local/esphome/firmware.bin | ||||
|  | ||||
|         - ota.http_request.flash: | ||||
|             md5: 0123456789abcdef0123456789abcdef | ||||
|             url: http://my.ha.net:8123/local/esphome/firmware.bin | ||||
|  | ||||
|         - logger.log: "This message should be not displayed (reboot)" | ||||
| @@ -1,33 +0,0 @@ | ||||
| esphome: | ||||
|   on_boot: | ||||
|     then: | ||||
|       - http_request.get: | ||||
|           url: https://esphome.io | ||||
|           headers: | ||||
|             Content-Type: application/json | ||||
|           verify_ssl: false | ||||
|           on_response: | ||||
|             then: | ||||
|               - logger.log: | ||||
|                   format: 'Response status: %d, Duration: %u ms' | ||||
|                   args: | ||||
|                     - status_code | ||||
|                     - duration_ms | ||||
|       - http_request.post: | ||||
|           url: https://esphome.io | ||||
|           headers: | ||||
|             Content-Type: application/json | ||||
|           json: | ||||
|             key: value | ||||
|           verify_ssl: false | ||||
|       - http_request.send: | ||||
|           method: PUT | ||||
|           url: https://esphome.io | ||||
|           headers: | ||||
|             Content-Type: application/json | ||||
|           body: "Some data" | ||||
|           verify_ssl: false | ||||
|  | ||||
| http_request: | ||||
|   useragent: esphome/tagreader | ||||
|   timeout: 10s | ||||
| @@ -1,36 +0,0 @@ | ||||
| wifi: | ||||
|   ssid: MySSID | ||||
|   password: password1 | ||||
|  | ||||
| ota: | ||||
|   - platform: http_request | ||||
|     verify_ssl: ${verify_ssl} | ||||
|     on_begin: | ||||
|       then: | ||||
|         - logger.log: "OTA start" | ||||
|     on_progress: | ||||
|       then: | ||||
|         - logger.log: | ||||
|             format: "OTA progress %0.1f%%" | ||||
|             args: ["x"] | ||||
|     on_end: | ||||
|       then: | ||||
|         - logger.log: "OTA end" | ||||
|     on_error: | ||||
|       then: | ||||
|         - logger.log: | ||||
|             format: "OTA update error %d" | ||||
|             args: ["x"] | ||||
|     on_state_change: | ||||
|       then: | ||||
|         lambda: 'ESP_LOGD("ota", "State %d", state);' | ||||
|  | ||||
| button: | ||||
|   - platform: template | ||||
|     name: Firmware update | ||||
|     on_press: | ||||
|       then: | ||||
|         - ota_http_request.flash: | ||||
|             md5_url: http://my.ha.net:8123/local/esphome/firmware.md5 | ||||
|             url: http://my.ha.net:8123/local/esphome/firmware.bin | ||||
|         - logger.log: "This message should be not displayed (reboot)" | ||||
| @@ -1,38 +1,4 @@ | ||||
| <<: !include common_http_request.yaml | ||||
| <<: !include common.yaml | ||||
|  | ||||
| wifi: | ||||
|   ssid: MySSID | ||||
|   password: password1 | ||||
|  | ||||
| ota: | ||||
|   - platform: http_request | ||||
|     esp8266_disable_ssl_support: true | ||||
|     on_begin: | ||||
|       then: | ||||
|         - logger.log: "OTA start" | ||||
|     on_progress: | ||||
|       then: | ||||
|         - logger.log: | ||||
|             format: "OTA progress %0.1f%%" | ||||
|             args: ["x"] | ||||
|     on_end: | ||||
|       then: | ||||
|         - logger.log: "OTA end" | ||||
|     on_error: | ||||
|       then: | ||||
|         - logger.log: | ||||
|             format: "OTA update error %d" | ||||
|             args: ["x"] | ||||
|     on_state_change: | ||||
|       then: | ||||
|         lambda: 'ESP_LOGD("ota", "State %d", state);' | ||||
|  | ||||
| button: | ||||
|   - platform: template | ||||
|     name: Firmware update | ||||
|     on_press: | ||||
|       then: | ||||
|         - ota_http_request.flash: | ||||
|             md5_url: http://my.ha.net:8123/local/esphome/firmware.md5 | ||||
|             url: http://my.ha.net:8123/local/esphome/firmware.bin | ||||
|         - logger.log: "This message should be not displayed (reboot)" | ||||
| http_request: | ||||
|   esp8266_disable_ssl_support: true | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| substitutions: | ||||
|   verify_ssl: "true" | ||||
|  | ||||
| <<: !include common_ota.yaml | ||||
| <<: !include common.yaml | ||||
|   | ||||
| @@ -1,5 +1,4 @@ | ||||
| substitutions: | ||||
|   verify_ssl: "false" | ||||
|  | ||||
| <<: !include common_http_request.yaml | ||||
| <<: !include common_ota.yaml | ||||
| <<: !include common.yaml | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| substitutions: | ||||
|   verify_ssl: "true" | ||||
|  | ||||
| <<: !include common_ota.yaml | ||||
| <<: !include common.yaml | ||||
|   | ||||
| @@ -1,5 +1,4 @@ | ||||
| substitutions: | ||||
|   verify_ssl: "false" | ||||
|  | ||||
| <<: !include common_http_request.yaml | ||||
| <<: !include common_ota.yaml | ||||
| <<: !include common.yaml | ||||
|   | ||||
| @@ -1,5 +1,4 @@ | ||||
| substitutions: | ||||
|   verify_ssl: "false" | ||||
|  | ||||
| <<: !include common_http_request.yaml | ||||
| <<: !include common_ota.yaml | ||||
| <<: !include common.yaml | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| substitutions: | ||||
|   verify_ssl: "false" | ||||
|  | ||||
| <<: !include common_ota.yaml | ||||
| <<: !include common.yaml | ||||
|   | ||||
| @@ -25,31 +25,6 @@ esphome: | ||||
|     then: | ||||
|       - lambda: >- | ||||
|           ESP_LOGV("main", "ON LOOP!"); | ||||
|       - http_request.get: | ||||
|           url: https://esphome.io | ||||
|           headers: | ||||
|             Content-Type: application/json | ||||
|           verify_ssl: false | ||||
|       - http_request.post: | ||||
|           url: https://esphome.io | ||||
|           verify_ssl: false | ||||
|           json: | ||||
|             key: !lambda |- | ||||
|               return id(${textname}_text).state; | ||||
|             greeting: Hello World | ||||
|       - http_request.send: | ||||
|           method: PUT | ||||
|           url: https://esphome.io | ||||
|           headers: | ||||
|             Content-Type: application/json | ||||
|           body: Some data | ||||
|           verify_ssl: false | ||||
|           on_response: | ||||
|             then: | ||||
|               - logger.log: | ||||
|                   format: "Response status: %d" | ||||
|                   args: | ||||
|                     - status_code | ||||
|   build_path: build/test1 | ||||
|  | ||||
| packages: | ||||
| @@ -84,10 +59,6 @@ network: | ||||
| mdns: | ||||
|   disabled: false | ||||
|  | ||||
| http_request: | ||||
|   useragent: esphome/device | ||||
|   timeout: 10s | ||||
|  | ||||
| mqtt: | ||||
|   broker: "192.168.178.84" | ||||
|   port: 1883 | ||||
|   | ||||
| @@ -447,26 +447,6 @@ switch: | ||||
|     switches: | ||||
|       - id: custom_switch | ||||
|         name: Custom Switch | ||||
|         on_turn_on: | ||||
|           - http_request.get: | ||||
|               url: https://esphome.io | ||||
|               headers: | ||||
|                 Content-Type: application/json | ||||
|               verify_ssl: false | ||||
|           - http_request.post: | ||||
|               url: https://esphome.io | ||||
|               verify_ssl: false | ||||
|               json: | ||||
|                 key: !lambda |- | ||||
|                   return id(custom_text_sensor).state; | ||||
|                 greeting: Hello World | ||||
|           - http_request.send: | ||||
|               method: PUT | ||||
|               url: https://esphome.io | ||||
|               headers: | ||||
|                 Content-Type: application/json | ||||
|               body: Some data | ||||
|               verify_ssl: false | ||||
|   - platform: template | ||||
|     name: open_vent | ||||
|     id: open_vent | ||||
| @@ -722,10 +702,6 @@ display: | ||||
|     lambda: |- | ||||
|       it.printdigit("hello"); | ||||
|  | ||||
| http_request: | ||||
|   useragent: esphome/device | ||||
|   timeout: 10s | ||||
|  | ||||
| button: | ||||
|   - platform: output | ||||
|     id: output_button | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| # Tests for ESP32-C3 boards which use toolchain-riscv32-esp | ||||
| --- | ||||
| wifi: | ||||
|   ssid: 'ssid' | ||||
|   ssid: "ssid" | ||||
|  | ||||
| network: | ||||
|   enable_ipv6: true | ||||
| @@ -12,31 +12,12 @@ esp32: | ||||
|     type: arduino | ||||
|  | ||||
| esphome: | ||||
|   name: 'on-response-test' | ||||
|   on_boot: | ||||
|     then: | ||||
|       - http_request.send: | ||||
|           method: PUT | ||||
|           url: https://esphome.io | ||||
|           headers: | ||||
|             Content-Type: application/json | ||||
|           body: Some data | ||||
|           verify_ssl: false | ||||
|           on_response: | ||||
|             then: | ||||
|               - logger.log: | ||||
|                   format: "Response status: %d" | ||||
|                   args: | ||||
|                     - status_code | ||||
|   name: test7 | ||||
|  | ||||
| logger: | ||||
|  | ||||
| debug: | ||||
|  | ||||
| http_request: | ||||
|   useragent: esphome/tagreader | ||||
|   timeout: 10s | ||||
|  | ||||
| sensor: | ||||
|   - platform: adc | ||||
|     id: adc_sensor_p4 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user