Skip to content

Commit

Permalink
Prometheus fix for esp-idf and fix newlines (esphome#5536)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored Oct 16, 2023
1 parent 357ba1a commit 06eff72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
22 changes: 9 additions & 13 deletions esphome/components/prometheus/prometheus_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#ifdef USE_ARDUINO

#include "prometheus_handler.h"
#include "esphome/core/application.h"

Expand Down Expand Up @@ -89,7 +87,7 @@ void PrometheusHandler::sensor_row_(AsyncResponseStream *stream, sensor::Sensor
stream->print(obj->get_unit_of_measurement().c_str());
stream->print(F("\"} "));
stream->print(value_accuracy_to_string(obj->state, obj->get_accuracy_decimals()).c_str());
stream->print('\n');
stream->print(F("\n"));
} else {
// Invalid state
stream->print(F("esphome_sensor_failed{id=\""));
Expand Down Expand Up @@ -124,7 +122,7 @@ void PrometheusHandler::binary_sensor_row_(AsyncResponseStream *stream, binary_s
stream->print(relabel_name_(obj).c_str());
stream->print(F("\"} "));
stream->print(obj->state);
stream->print('\n');
stream->print(F("\n"));
} else {
// Invalid state
stream->print(F("esphome_binary_sensor_failed{id=\""));
Expand Down Expand Up @@ -158,7 +156,7 @@ void PrometheusHandler::fan_row_(AsyncResponseStream *stream, fan::Fan *obj) {
stream->print(relabel_name_(obj).c_str());
stream->print(F("\"} "));
stream->print(obj->state);
stream->print('\n');
stream->print(F("\n"));
// Speed if available
if (obj->get_traits().supports_speed()) {
stream->print(F("esphome_fan_speed{id=\""));
Expand All @@ -167,7 +165,7 @@ void PrometheusHandler::fan_row_(AsyncResponseStream *stream, fan::Fan *obj) {
stream->print(relabel_name_(obj).c_str());
stream->print(F("\"} "));
stream->print(obj->speed);
stream->print('\n');
stream->print(F("\n"));
}
// Oscillation if available
if (obj->get_traits().supports_oscillation()) {
Expand All @@ -177,7 +175,7 @@ void PrometheusHandler::fan_row_(AsyncResponseStream *stream, fan::Fan *obj) {
stream->print(relabel_name_(obj).c_str());
stream->print(F("\"} "));
stream->print(obj->oscillating);
stream->print('\n');
stream->print(F("\n"));
}
}
#endif
Expand Down Expand Up @@ -281,15 +279,15 @@ void PrometheusHandler::cover_row_(AsyncResponseStream *stream, cover::Cover *ob
stream->print(relabel_name_(obj).c_str());
stream->print(F("\"} "));
stream->print(obj->position);
stream->print('\n');
stream->print(F("\n"));
if (obj->get_traits().get_supports_tilt()) {
stream->print(F("esphome_cover_tilt{id=\""));
stream->print(relabel_id_(obj).c_str());
stream->print(F("\",name=\""));
stream->print(relabel_name_(obj).c_str());
stream->print(F("\"} "));
stream->print(obj->tilt);
stream->print('\n');
stream->print(F("\n"));
}
} else {
// Invalid state
Expand Down Expand Up @@ -322,7 +320,7 @@ void PrometheusHandler::switch_row_(AsyncResponseStream *stream, switch_::Switch
stream->print(relabel_name_(obj).c_str());
stream->print(F("\"} "));
stream->print(obj->state);
stream->print('\n');
stream->print(F("\n"));
}
#endif

Expand All @@ -346,11 +344,9 @@ void PrometheusHandler::lock_row_(AsyncResponseStream *stream, lock::Lock *obj)
stream->print(relabel_name_(obj).c_str());
stream->print(F("\"} "));
stream->print(obj->state);
stream->print('\n');
stream->print(F("\n"));
}
#endif

} // namespace prometheus
} // namespace esphome

#endif // USE_ARDUINO
8 changes: 2 additions & 6 deletions esphome/components/prometheus/prometheus_handler.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#pragma once

#ifdef USE_ARDUINO

#include <map>
#include <utility>

#include "esphome/core/entity_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/controller.h"
#include "esphome/core/entity_base.h"

namespace esphome {
namespace prometheus {
Expand Down Expand Up @@ -119,5 +117,3 @@ class PrometheusHandler : public AsyncWebHandler, public Component {

} // namespace prometheus
} // namespace esphome

#endif // USE_ARDUINO

0 comments on commit 06eff72

Please sign in to comment.