mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Prometheus fix for esp-idf and fix newlines (#5536)
This commit is contained in:
		| @@ -1,5 +1,3 @@ | |||||||
| #ifdef USE_ARDUINO |  | ||||||
|  |  | ||||||
| #include "prometheus_handler.h" | #include "prometheus_handler.h" | ||||||
| #include "esphome/core/application.h" | #include "esphome/core/application.h" | ||||||
|  |  | ||||||
| @@ -89,7 +87,7 @@ void PrometheusHandler::sensor_row_(AsyncResponseStream *stream, sensor::Sensor | |||||||
|     stream->print(obj->get_unit_of_measurement().c_str()); |     stream->print(obj->get_unit_of_measurement().c_str()); | ||||||
|     stream->print(F("\"} ")); |     stream->print(F("\"} ")); | ||||||
|     stream->print(value_accuracy_to_string(obj->state, obj->get_accuracy_decimals()).c_str()); |     stream->print(value_accuracy_to_string(obj->state, obj->get_accuracy_decimals()).c_str()); | ||||||
|     stream->print('\n'); |     stream->print(F("\n")); | ||||||
|   } else { |   } else { | ||||||
|     // Invalid state |     // Invalid state | ||||||
|     stream->print(F("esphome_sensor_failed{id=\"")); |     stream->print(F("esphome_sensor_failed{id=\"")); | ||||||
| @@ -124,7 +122,7 @@ void PrometheusHandler::binary_sensor_row_(AsyncResponseStream *stream, binary_s | |||||||
|     stream->print(relabel_name_(obj).c_str()); |     stream->print(relabel_name_(obj).c_str()); | ||||||
|     stream->print(F("\"} ")); |     stream->print(F("\"} ")); | ||||||
|     stream->print(obj->state); |     stream->print(obj->state); | ||||||
|     stream->print('\n'); |     stream->print(F("\n")); | ||||||
|   } else { |   } else { | ||||||
|     // Invalid state |     // Invalid state | ||||||
|     stream->print(F("esphome_binary_sensor_failed{id=\"")); |     stream->print(F("esphome_binary_sensor_failed{id=\"")); | ||||||
| @@ -158,7 +156,7 @@ void PrometheusHandler::fan_row_(AsyncResponseStream *stream, fan::Fan *obj) { | |||||||
|   stream->print(relabel_name_(obj).c_str()); |   stream->print(relabel_name_(obj).c_str()); | ||||||
|   stream->print(F("\"} ")); |   stream->print(F("\"} ")); | ||||||
|   stream->print(obj->state); |   stream->print(obj->state); | ||||||
|   stream->print('\n'); |   stream->print(F("\n")); | ||||||
|   // Speed if available |   // Speed if available | ||||||
|   if (obj->get_traits().supports_speed()) { |   if (obj->get_traits().supports_speed()) { | ||||||
|     stream->print(F("esphome_fan_speed{id=\"")); |     stream->print(F("esphome_fan_speed{id=\"")); | ||||||
| @@ -167,7 +165,7 @@ void PrometheusHandler::fan_row_(AsyncResponseStream *stream, fan::Fan *obj) { | |||||||
|     stream->print(relabel_name_(obj).c_str()); |     stream->print(relabel_name_(obj).c_str()); | ||||||
|     stream->print(F("\"} ")); |     stream->print(F("\"} ")); | ||||||
|     stream->print(obj->speed); |     stream->print(obj->speed); | ||||||
|     stream->print('\n'); |     stream->print(F("\n")); | ||||||
|   } |   } | ||||||
|   // Oscillation if available |   // Oscillation if available | ||||||
|   if (obj->get_traits().supports_oscillation()) { |   if (obj->get_traits().supports_oscillation()) { | ||||||
| @@ -177,7 +175,7 @@ void PrometheusHandler::fan_row_(AsyncResponseStream *stream, fan::Fan *obj) { | |||||||
|     stream->print(relabel_name_(obj).c_str()); |     stream->print(relabel_name_(obj).c_str()); | ||||||
|     stream->print(F("\"} ")); |     stream->print(F("\"} ")); | ||||||
|     stream->print(obj->oscillating); |     stream->print(obj->oscillating); | ||||||
|     stream->print('\n'); |     stream->print(F("\n")); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
| @@ -281,7 +279,7 @@ void PrometheusHandler::cover_row_(AsyncResponseStream *stream, cover::Cover *ob | |||||||
|     stream->print(relabel_name_(obj).c_str()); |     stream->print(relabel_name_(obj).c_str()); | ||||||
|     stream->print(F("\"} ")); |     stream->print(F("\"} ")); | ||||||
|     stream->print(obj->position); |     stream->print(obj->position); | ||||||
|     stream->print('\n'); |     stream->print(F("\n")); | ||||||
|     if (obj->get_traits().get_supports_tilt()) { |     if (obj->get_traits().get_supports_tilt()) { | ||||||
|       stream->print(F("esphome_cover_tilt{id=\"")); |       stream->print(F("esphome_cover_tilt{id=\"")); | ||||||
|       stream->print(relabel_id_(obj).c_str()); |       stream->print(relabel_id_(obj).c_str()); | ||||||
| @@ -289,7 +287,7 @@ void PrometheusHandler::cover_row_(AsyncResponseStream *stream, cover::Cover *ob | |||||||
|       stream->print(relabel_name_(obj).c_str()); |       stream->print(relabel_name_(obj).c_str()); | ||||||
|       stream->print(F("\"} ")); |       stream->print(F("\"} ")); | ||||||
|       stream->print(obj->tilt); |       stream->print(obj->tilt); | ||||||
|       stream->print('\n'); |       stream->print(F("\n")); | ||||||
|     } |     } | ||||||
|   } else { |   } else { | ||||||
|     // Invalid state |     // Invalid state | ||||||
| @@ -322,7 +320,7 @@ void PrometheusHandler::switch_row_(AsyncResponseStream *stream, switch_::Switch | |||||||
|   stream->print(relabel_name_(obj).c_str()); |   stream->print(relabel_name_(obj).c_str()); | ||||||
|   stream->print(F("\"} ")); |   stream->print(F("\"} ")); | ||||||
|   stream->print(obj->state); |   stream->print(obj->state); | ||||||
|   stream->print('\n'); |   stream->print(F("\n")); | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| @@ -346,11 +344,9 @@ void PrometheusHandler::lock_row_(AsyncResponseStream *stream, lock::Lock *obj) | |||||||
|   stream->print(relabel_name_(obj).c_str()); |   stream->print(relabel_name_(obj).c_str()); | ||||||
|   stream->print(F("\"} ")); |   stream->print(F("\"} ")); | ||||||
|   stream->print(obj->state); |   stream->print(obj->state); | ||||||
|   stream->print('\n'); |   stream->print(F("\n")); | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| }  // namespace prometheus | }  // namespace prometheus | ||||||
| }  // namespace esphome | }  // namespace esphome | ||||||
|  |  | ||||||
| #endif  // USE_ARDUINO |  | ||||||
|   | |||||||
| @@ -1,14 +1,12 @@ | |||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #ifdef USE_ARDUINO |  | ||||||
|  |  | ||||||
| #include <map> | #include <map> | ||||||
| #include <utility> | #include <utility> | ||||||
|  |  | ||||||
| #include "esphome/core/entity_base.h" |  | ||||||
| #include "esphome/components/web_server_base/web_server_base.h" | #include "esphome/components/web_server_base/web_server_base.h" | ||||||
| #include "esphome/core/controller.h" |  | ||||||
| #include "esphome/core/component.h" | #include "esphome/core/component.h" | ||||||
|  | #include "esphome/core/controller.h" | ||||||
|  | #include "esphome/core/entity_base.h" | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace prometheus { | namespace prometheus { | ||||||
| @@ -119,5 +117,3 @@ class PrometheusHandler : public AsyncWebHandler, public Component { | |||||||
|  |  | ||||||
| }  // namespace prometheus | }  // namespace prometheus | ||||||
| }  // namespace esphome | }  // namespace esphome | ||||||
|  |  | ||||||
| #endif  // USE_ARDUINO |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user