diff --git a/esphome/components/prometheus/prometheus_handler.cpp b/esphome/components/prometheus/prometheus_handler.cpp index 794df299a1..8c1e86b349 100644 --- a/esphome/components/prometheus/prometheus_handler.cpp +++ b/esphome/components/prometheus/prometheus_handler.cpp @@ -89,6 +89,12 @@ void PrometheusHandler::handleRequest(AsyncWebServerRequest *req) { this->valve_row_(stream, obj, area, node, friendly_name); #endif +#ifdef USE_CLIMATE + this->climate_type_(stream); + for (auto *obj : App.get_climates()) + this->climate_row_(stream, obj, area, node, friendly_name); +#endif + req->send(stream); } @@ -824,6 +830,40 @@ void PrometheusHandler::valve_row_(AsyncResponseStream *stream, valve::Valve *ob } #endif +#ifdef USE_CLIMATE +void PrometheusHandler::climate_type_(AsyncResponseStream *stream) { + stream->print(F("#TYPE esphome_climate_operation gauge\n")); + stream->print(F("#TYPE esphome_climate_failed gauge\n")); +} + +void PrometheusHandler::climate_row_(AsyncResponseStream *stream, climate::Climate *obj, std::string &area, + std::string &node, std::string &friendly_name) { + if (obj->is_internal() && !this->include_internal_) + return; + stream->print(F("esphome_climate_failed{id=\"")); + stream->print(relabel_id_(obj).c_str()); + add_area_label_(stream, area); + add_node_label_(stream, node); + add_friendly_name_label_(stream, friendly_name); + stream->print(F("\",name=\"")); + stream->print(relabel_name_(obj).c_str()); + stream->print(F("\"} 0\n")); + // Data itself + stream->print(F("esphome_climate_operation{id=\"")); + stream->print(relabel_id_(obj).c_str()); + add_area_label_(stream, area); + add_node_label_(stream, node); + add_friendly_name_label_(stream, friendly_name); + stream->print(F("\",name=\"")); + stream->print(relabel_name_(obj).c_str()); + stream->print(F("\",operation=\"")); + // stream->print(valve::valve_operation_to_str(obj->current_operation)); + stream->print(F("\"} ")); + stream->print(F("1.0")); + stream->print(F("\n")); +} +#endif + } // namespace prometheus } // namespace esphome #endif diff --git a/esphome/components/prometheus/prometheus_handler.h b/esphome/components/prometheus/prometheus_handler.h index b77dbc462b..a27b1050be 100644 --- a/esphome/components/prometheus/prometheus_handler.h +++ b/esphome/components/prometheus/prometheus_handler.h @@ -169,6 +169,14 @@ class PrometheusHandler : public AsyncWebHandler, public Component { std::string &friendly_name); #endif +#ifdef USE_CLIMATE + /// Return the type for prometheus + void climate_type_(AsyncResponseStream *stream); + /// Return the climate state as prometheus data point + void climate_row_(AsyncResponseStream *stream, climate::Climate *obj, std::string &area, std::string &node, + std::string &friendly_name); +#endif + web_server_base::WebServerBase *base_; bool include_internal_{false}; std::map relabel_map_id_; diff --git a/tests/components/prometheus/common.yaml b/tests/components/prometheus/common.yaml index 7c226b6782..ce6ff62b94 100644 --- a/tests/components/prometheus/common.yaml +++ b/tests/components/prometheus/common.yaml @@ -129,6 +129,14 @@ valve: optimistic: true has_position: true +remote_transmitter: + pin: ${pin} + carrier_duty_percent: 50% + +climate: + - platform: climate_ir_lg + name: LG Climate + prometheus: include_internal: true relabel: diff --git a/tests/components/prometheus/test.esp32-ard.yaml b/tests/components/prometheus/test.esp32-ard.yaml index 3045a6db13..014600d82d 100644 --- a/tests/components/prometheus/test.esp32-ard.yaml +++ b/tests/components/prometheus/test.esp32-ard.yaml @@ -1,3 +1,6 @@ +substitutions: + pin: GPIO2 + <<: !include common.yaml i2s_audio: diff --git a/tests/components/prometheus/test.esp32-c3-ard.yaml b/tests/components/prometheus/test.esp32-c3-ard.yaml index dade44d145..7b012aa64c 100644 --- a/tests/components/prometheus/test.esp32-c3-ard.yaml +++ b/tests/components/prometheus/test.esp32-c3-ard.yaml @@ -1 +1,4 @@ +substitutions: + pin: GPIO2 + <<: !include common.yaml diff --git a/tests/components/prometheus/test.esp32-c3-idf.yaml b/tests/components/prometheus/test.esp32-c3-idf.yaml index dade44d145..7b012aa64c 100644 --- a/tests/components/prometheus/test.esp32-c3-idf.yaml +++ b/tests/components/prometheus/test.esp32-c3-idf.yaml @@ -1 +1,4 @@ +substitutions: + pin: GPIO2 + <<: !include common.yaml diff --git a/tests/components/prometheus/test.esp32-idf.yaml b/tests/components/prometheus/test.esp32-idf.yaml index dade44d145..7b012aa64c 100644 --- a/tests/components/prometheus/test.esp32-idf.yaml +++ b/tests/components/prometheus/test.esp32-idf.yaml @@ -1 +1,4 @@ +substitutions: + pin: GPIO2 + <<: !include common.yaml diff --git a/tests/components/prometheus/test.esp8266-ard.yaml b/tests/components/prometheus/test.esp8266-ard.yaml index dade44d145..f5097fcf5f 100644 --- a/tests/components/prometheus/test.esp8266-ard.yaml +++ b/tests/components/prometheus/test.esp8266-ard.yaml @@ -1 +1,4 @@ +substitutions: + pin: GPIO5 + <<: !include common.yaml