ESPHome  2024.12.2
prometheus_handler.cpp
Go to the documentation of this file.
1 #include "prometheus_handler.h"
2 #ifdef USE_NETWORK
4 
5 namespace esphome {
6 namespace prometheus {
7 
8 void PrometheusHandler::handleRequest(AsyncWebServerRequest *req) {
9  AsyncResponseStream *stream = req->beginResponseStream("text/plain; version=0.0.4; charset=utf-8");
10  std::string area = App.get_area();
11  std::string node = App.get_name();
12  std::string friendly_name = App.get_friendly_name();
13 
14 #ifdef USE_SENSOR
15  this->sensor_type_(stream);
16  for (auto *obj : App.get_sensors())
17  this->sensor_row_(stream, obj, area, node, friendly_name);
18 #endif
19 
20 #ifdef USE_BINARY_SENSOR
21  this->binary_sensor_type_(stream);
22  for (auto *obj : App.get_binary_sensors())
23  this->binary_sensor_row_(stream, obj, area, node, friendly_name);
24 #endif
25 
26 #ifdef USE_FAN
27  this->fan_type_(stream);
28  for (auto *obj : App.get_fans())
29  this->fan_row_(stream, obj, area, node, friendly_name);
30 #endif
31 
32 #ifdef USE_LIGHT
33  this->light_type_(stream);
34  for (auto *obj : App.get_lights())
35  this->light_row_(stream, obj, area, node, friendly_name);
36 #endif
37 
38 #ifdef USE_COVER
39  this->cover_type_(stream);
40  for (auto *obj : App.get_covers())
41  this->cover_row_(stream, obj, area, node, friendly_name);
42 #endif
43 
44 #ifdef USE_SWITCH
45  this->switch_type_(stream);
46  for (auto *obj : App.get_switches())
47  this->switch_row_(stream, obj, area, node, friendly_name);
48 #endif
49 
50 #ifdef USE_LOCK
51  this->lock_type_(stream);
52  for (auto *obj : App.get_locks())
53  this->lock_row_(stream, obj, area, node, friendly_name);
54 #endif
55 
56 #ifdef USE_TEXT_SENSOR
57  this->text_sensor_type_(stream);
58  for (auto *obj : App.get_text_sensors())
59  this->text_sensor_row_(stream, obj, area, node, friendly_name);
60 #endif
61 
62  req->send(stream);
63 }
64 
66  auto item = relabel_map_id_.find(obj);
67  return item == relabel_map_id_.end() ? obj->get_object_id() : item->second;
68 }
69 
71  auto item = relabel_map_name_.find(obj);
72  return item == relabel_map_name_.end() ? obj->get_name() : item->second;
73 }
74 
75 void PrometheusHandler::add_area_label_(AsyncResponseStream *stream, std::string &area) {
76  if (!area.empty()) {
77  stream->print(F("\",area=\""));
78  stream->print(area.c_str());
79  }
80 }
81 
82 void PrometheusHandler::add_node_label_(AsyncResponseStream *stream, std::string &node) {
83  if (!node.empty()) {
84  stream->print(F("\",node=\""));
85  stream->print(node.c_str());
86  }
87 }
88 
89 void PrometheusHandler::add_friendly_name_label_(AsyncResponseStream *stream, std::string &friendly_name) {
90  if (!friendly_name.empty()) {
91  stream->print(F("\",friendly_name=\""));
92  stream->print(friendly_name.c_str());
93  }
94 }
95 
96 // Type-specific implementation
97 #ifdef USE_SENSOR
98 void PrometheusHandler::sensor_type_(AsyncResponseStream *stream) {
99  stream->print(F("#TYPE esphome_sensor_value gauge\n"));
100  stream->print(F("#TYPE esphome_sensor_failed gauge\n"));
101 }
102 void PrometheusHandler::sensor_row_(AsyncResponseStream *stream, sensor::Sensor *obj, std::string &area,
103  std::string &node, std::string &friendly_name) {
104  if (obj->is_internal() && !this->include_internal_)
105  return;
106  if (!std::isnan(obj->state)) {
107  // We have a valid value, output this value
108  stream->print(F("esphome_sensor_failed{id=\""));
109  stream->print(relabel_id_(obj).c_str());
110  add_area_label_(stream, area);
111  add_node_label_(stream, node);
112  add_friendly_name_label_(stream, friendly_name);
113  stream->print(F("\",name=\""));
114  stream->print(relabel_name_(obj).c_str());
115  stream->print(F("\"} 0\n"));
116  // Data itself
117  stream->print(F("esphome_sensor_value{id=\""));
118  stream->print(relabel_id_(obj).c_str());
119  add_area_label_(stream, area);
120  add_node_label_(stream, node);
121  add_friendly_name_label_(stream, friendly_name);
122  stream->print(F("\",name=\""));
123  stream->print(relabel_name_(obj).c_str());
124  stream->print(F("\",unit=\""));
125  stream->print(obj->get_unit_of_measurement().c_str());
126  stream->print(F("\"} "));
127  stream->print(value_accuracy_to_string(obj->state, obj->get_accuracy_decimals()).c_str());
128  stream->print(F("\n"));
129  } else {
130  // Invalid state
131  stream->print(F("esphome_sensor_failed{id=\""));
132  stream->print(relabel_id_(obj).c_str());
133  add_area_label_(stream, area);
134  add_node_label_(stream, node);
135  add_friendly_name_label_(stream, friendly_name);
136  stream->print(F("\",name=\""));
137  stream->print(relabel_name_(obj).c_str());
138  stream->print(F("\"} 1\n"));
139  }
140 }
141 #endif
142 
143 // Type-specific implementation
144 #ifdef USE_BINARY_SENSOR
145 void PrometheusHandler::binary_sensor_type_(AsyncResponseStream *stream) {
146  stream->print(F("#TYPE esphome_binary_sensor_value gauge\n"));
147  stream->print(F("#TYPE esphome_binary_sensor_failed gauge\n"));
148 }
150  std::string &area, std::string &node, std::string &friendly_name) {
151  if (obj->is_internal() && !this->include_internal_)
152  return;
153  if (obj->has_state()) {
154  // We have a valid value, output this value
155  stream->print(F("esphome_binary_sensor_failed{id=\""));
156  stream->print(relabel_id_(obj).c_str());
157  add_area_label_(stream, area);
158  add_node_label_(stream, node);
159  add_friendly_name_label_(stream, friendly_name);
160  stream->print(F("\",name=\""));
161  stream->print(relabel_name_(obj).c_str());
162  stream->print(F("\"} 0\n"));
163  // Data itself
164  stream->print(F("esphome_binary_sensor_value{id=\""));
165  stream->print(relabel_id_(obj).c_str());
166  add_area_label_(stream, area);
167  add_node_label_(stream, node);
168  add_friendly_name_label_(stream, friendly_name);
169  stream->print(F("\",name=\""));
170  stream->print(relabel_name_(obj).c_str());
171  stream->print(F("\"} "));
172  stream->print(obj->state);
173  stream->print(F("\n"));
174  } else {
175  // Invalid state
176  stream->print(F("esphome_binary_sensor_failed{id=\""));
177  stream->print(relabel_id_(obj).c_str());
178  add_area_label_(stream, area);
179  add_node_label_(stream, node);
180  add_friendly_name_label_(stream, friendly_name);
181  stream->print(F("\",name=\""));
182  stream->print(relabel_name_(obj).c_str());
183  stream->print(F("\"} 1\n"));
184  }
185 }
186 #endif
187 
188 #ifdef USE_FAN
189 void PrometheusHandler::fan_type_(AsyncResponseStream *stream) {
190  stream->print(F("#TYPE esphome_fan_value gauge\n"));
191  stream->print(F("#TYPE esphome_fan_failed gauge\n"));
192  stream->print(F("#TYPE esphome_fan_speed gauge\n"));
193  stream->print(F("#TYPE esphome_fan_oscillation gauge\n"));
194 }
195 void PrometheusHandler::fan_row_(AsyncResponseStream *stream, fan::Fan *obj, std::string &area, std::string &node,
196  std::string &friendly_name) {
197  if (obj->is_internal() && !this->include_internal_)
198  return;
199  stream->print(F("esphome_fan_failed{id=\""));
200  stream->print(relabel_id_(obj).c_str());
201  add_area_label_(stream, area);
202  add_node_label_(stream, node);
203  add_friendly_name_label_(stream, friendly_name);
204  stream->print(F("\",name=\""));
205  stream->print(relabel_name_(obj).c_str());
206  stream->print(F("\"} 0\n"));
207  // Data itself
208  stream->print(F("esphome_fan_value{id=\""));
209  stream->print(relabel_id_(obj).c_str());
210  add_area_label_(stream, area);
211  add_node_label_(stream, node);
212  add_friendly_name_label_(stream, friendly_name);
213  stream->print(F("\",name=\""));
214  stream->print(relabel_name_(obj).c_str());
215  stream->print(F("\"} "));
216  stream->print(obj->state);
217  stream->print(F("\n"));
218  // Speed if available
219  if (obj->get_traits().supports_speed()) {
220  stream->print(F("esphome_fan_speed{id=\""));
221  stream->print(relabel_id_(obj).c_str());
222  add_area_label_(stream, area);
223  add_node_label_(stream, node);
224  add_friendly_name_label_(stream, friendly_name);
225  stream->print(F("\",name=\""));
226  stream->print(relabel_name_(obj).c_str());
227  stream->print(F("\"} "));
228  stream->print(obj->speed);
229  stream->print(F("\n"));
230  }
231  // Oscillation if available
232  if (obj->get_traits().supports_oscillation()) {
233  stream->print(F("esphome_fan_oscillation{id=\""));
234  stream->print(relabel_id_(obj).c_str());
235  add_area_label_(stream, area);
236  add_node_label_(stream, node);
237  add_friendly_name_label_(stream, friendly_name);
238  stream->print(F("\",name=\""));
239  stream->print(relabel_name_(obj).c_str());
240  stream->print(F("\"} "));
241  stream->print(obj->oscillating);
242  stream->print(F("\n"));
243  }
244 }
245 #endif
246 
247 #ifdef USE_LIGHT
248 void PrometheusHandler::light_type_(AsyncResponseStream *stream) {
249  stream->print(F("#TYPE esphome_light_state gauge\n"));
250  stream->print(F("#TYPE esphome_light_color gauge\n"));
251  stream->print(F("#TYPE esphome_light_effect_active gauge\n"));
252 }
253 void PrometheusHandler::light_row_(AsyncResponseStream *stream, light::LightState *obj, std::string &area,
254  std::string &node, std::string &friendly_name) {
255  if (obj->is_internal() && !this->include_internal_)
256  return;
257  // State
258  stream->print(F("esphome_light_state{id=\""));
259  stream->print(relabel_id_(obj).c_str());
260  add_area_label_(stream, area);
261  add_node_label_(stream, node);
262  add_friendly_name_label_(stream, friendly_name);
263  stream->print(F("\",name=\""));
264  stream->print(relabel_name_(obj).c_str());
265  stream->print(F("\"} "));
266  stream->print(obj->remote_values.is_on());
267  stream->print(F("\n"));
268  // Brightness and RGBW
270  float brightness, r, g, b, w;
271  color.as_brightness(&brightness);
272  color.as_rgbw(&r, &g, &b, &w);
273  stream->print(F("esphome_light_color{id=\""));
274  stream->print(relabel_id_(obj).c_str());
275  add_area_label_(stream, area);
276  add_node_label_(stream, node);
277  add_friendly_name_label_(stream, friendly_name);
278  stream->print(F("\",name=\""));
279  stream->print(relabel_name_(obj).c_str());
280  stream->print(F("\",channel=\"brightness\"} "));
281  stream->print(brightness);
282  stream->print(F("\n"));
283  stream->print(F("esphome_light_color{id=\""));
284  stream->print(relabel_id_(obj).c_str());
285  add_area_label_(stream, area);
286  add_node_label_(stream, node);
287  add_friendly_name_label_(stream, friendly_name);
288  stream->print(F("\",name=\""));
289  stream->print(relabel_name_(obj).c_str());
290  stream->print(F("\",channel=\"r\"} "));
291  stream->print(r);
292  stream->print(F("\n"));
293  stream->print(F("esphome_light_color{id=\""));
294  stream->print(relabel_id_(obj).c_str());
295  add_area_label_(stream, area);
296  add_node_label_(stream, node);
297  add_friendly_name_label_(stream, friendly_name);
298  stream->print(F("\",name=\""));
299  stream->print(relabel_name_(obj).c_str());
300  stream->print(F("\",channel=\"g\"} "));
301  stream->print(g);
302  stream->print(F("\n"));
303  stream->print(F("esphome_light_color{id=\""));
304  stream->print(relabel_id_(obj).c_str());
305  add_area_label_(stream, area);
306  add_node_label_(stream, node);
307  add_friendly_name_label_(stream, friendly_name);
308  stream->print(F("\",name=\""));
309  stream->print(relabel_name_(obj).c_str());
310  stream->print(F("\",channel=\"b\"} "));
311  stream->print(b);
312  stream->print(F("\n"));
313  stream->print(F("esphome_light_color{id=\""));
314  stream->print(relabel_id_(obj).c_str());
315  add_area_label_(stream, area);
316  add_node_label_(stream, node);
317  add_friendly_name_label_(stream, friendly_name);
318  stream->print(F("\",name=\""));
319  stream->print(relabel_name_(obj).c_str());
320  stream->print(F("\",channel=\"w\"} "));
321  stream->print(w);
322  stream->print(F("\n"));
323  // Effect
324  std::string effect = obj->get_effect_name();
325  if (effect == "None") {
326  stream->print(F("esphome_light_effect_active{id=\""));
327  stream->print(relabel_id_(obj).c_str());
328  add_area_label_(stream, area);
329  add_node_label_(stream, node);
330  add_friendly_name_label_(stream, friendly_name);
331  stream->print(F("\",name=\""));
332  stream->print(relabel_name_(obj).c_str());
333  stream->print(F("\",effect=\"None\"} 0\n"));
334  } else {
335  stream->print(F("esphome_light_effect_active{id=\""));
336  stream->print(relabel_id_(obj).c_str());
337  add_area_label_(stream, area);
338  add_node_label_(stream, node);
339  add_friendly_name_label_(stream, friendly_name);
340  stream->print(F("\",name=\""));
341  stream->print(relabel_name_(obj).c_str());
342  stream->print(F("\",effect=\""));
343  stream->print(effect.c_str());
344  stream->print(F("\"} 1\n"));
345  }
346 }
347 #endif
348 
349 #ifdef USE_COVER
350 void PrometheusHandler::cover_type_(AsyncResponseStream *stream) {
351  stream->print(F("#TYPE esphome_cover_value gauge\n"));
352  stream->print(F("#TYPE esphome_cover_failed gauge\n"));
353 }
354 void PrometheusHandler::cover_row_(AsyncResponseStream *stream, cover::Cover *obj, std::string &area, std::string &node,
355  std::string &friendly_name) {
356  if (obj->is_internal() && !this->include_internal_)
357  return;
358  if (!std::isnan(obj->position)) {
359  // We have a valid value, output this value
360  stream->print(F("esphome_cover_failed{id=\""));
361  stream->print(relabel_id_(obj).c_str());
362  add_area_label_(stream, area);
363  add_node_label_(stream, node);
364  add_friendly_name_label_(stream, friendly_name);
365  stream->print(F("\",name=\""));
366  stream->print(relabel_name_(obj).c_str());
367  stream->print(F("\"} 0\n"));
368  // Data itself
369  stream->print(F("esphome_cover_value{id=\""));
370  stream->print(relabel_id_(obj).c_str());
371  add_area_label_(stream, area);
372  add_node_label_(stream, node);
373  add_friendly_name_label_(stream, friendly_name);
374  stream->print(F("\",name=\""));
375  stream->print(relabel_name_(obj).c_str());
376  stream->print(F("\"} "));
377  stream->print(obj->position);
378  stream->print(F("\n"));
379  if (obj->get_traits().get_supports_tilt()) {
380  stream->print(F("esphome_cover_tilt{id=\""));
381  stream->print(relabel_id_(obj).c_str());
382  add_area_label_(stream, area);
383  add_node_label_(stream, node);
384  add_friendly_name_label_(stream, friendly_name);
385  stream->print(F("\",name=\""));
386  stream->print(relabel_name_(obj).c_str());
387  stream->print(F("\"} "));
388  stream->print(obj->tilt);
389  stream->print(F("\n"));
390  }
391  } else {
392  // Invalid state
393  stream->print(F("esphome_cover_failed{id=\""));
394  stream->print(relabel_id_(obj).c_str());
395  add_area_label_(stream, area);
396  add_node_label_(stream, node);
397  add_friendly_name_label_(stream, friendly_name);
398  stream->print(F("\",name=\""));
399  stream->print(relabel_name_(obj).c_str());
400  stream->print(F("\"} 1\n"));
401  }
402 }
403 #endif
404 
405 #ifdef USE_SWITCH
406 void PrometheusHandler::switch_type_(AsyncResponseStream *stream) {
407  stream->print(F("#TYPE esphome_switch_value gauge\n"));
408  stream->print(F("#TYPE esphome_switch_failed gauge\n"));
409 }
410 void PrometheusHandler::switch_row_(AsyncResponseStream *stream, switch_::Switch *obj, std::string &area,
411  std::string &node, std::string &friendly_name) {
412  if (obj->is_internal() && !this->include_internal_)
413  return;
414  stream->print(F("esphome_switch_failed{id=\""));
415  stream->print(relabel_id_(obj).c_str());
416  add_area_label_(stream, area);
417  add_node_label_(stream, node);
418  add_friendly_name_label_(stream, friendly_name);
419  stream->print(F("\",name=\""));
420  stream->print(relabel_name_(obj).c_str());
421  stream->print(F("\"} 0\n"));
422  // Data itself
423  stream->print(F("esphome_switch_value{id=\""));
424  stream->print(relabel_id_(obj).c_str());
425  add_area_label_(stream, area);
426  add_node_label_(stream, node);
427  add_friendly_name_label_(stream, friendly_name);
428  stream->print(F("\",name=\""));
429  stream->print(relabel_name_(obj).c_str());
430  stream->print(F("\"} "));
431  stream->print(obj->state);
432  stream->print(F("\n"));
433 }
434 #endif
435 
436 #ifdef USE_LOCK
437 void PrometheusHandler::lock_type_(AsyncResponseStream *stream) {
438  stream->print(F("#TYPE esphome_lock_value gauge\n"));
439  stream->print(F("#TYPE esphome_lock_failed gauge\n"));
440 }
441 void PrometheusHandler::lock_row_(AsyncResponseStream *stream, lock::Lock *obj, std::string &area, std::string &node,
442  std::string &friendly_name) {
443  if (obj->is_internal() && !this->include_internal_)
444  return;
445  stream->print(F("esphome_lock_failed{id=\""));
446  stream->print(relabel_id_(obj).c_str());
447  add_area_label_(stream, area);
448  add_node_label_(stream, node);
449  add_friendly_name_label_(stream, friendly_name);
450  stream->print(F("\",name=\""));
451  stream->print(relabel_name_(obj).c_str());
452  stream->print(F("\"} 0\n"));
453  // Data itself
454  stream->print(F("esphome_lock_value{id=\""));
455  stream->print(relabel_id_(obj).c_str());
456  add_area_label_(stream, area);
457  add_node_label_(stream, node);
458  add_friendly_name_label_(stream, friendly_name);
459  stream->print(F("\",name=\""));
460  stream->print(relabel_name_(obj).c_str());
461  stream->print(F("\"} "));
462  stream->print(obj->state);
463  stream->print(F("\n"));
464 }
465 #endif
466 
467 // Type-specific implementation
468 #ifdef USE_TEXT_SENSOR
469 void PrometheusHandler::text_sensor_type_(AsyncResponseStream *stream) {
470  stream->print(F("#TYPE esphome_text_sensor_value gauge\n"));
471  stream->print(F("#TYPE esphome_text_sensor_failed gauge\n"));
472 }
473 void PrometheusHandler::text_sensor_row_(AsyncResponseStream *stream, text_sensor::TextSensor *obj, std::string &area,
474  std::string &node, std::string &friendly_name) {
475  if (obj->is_internal() && !this->include_internal_)
476  return;
477  if (obj->has_state()) {
478  // We have a valid value, output this value
479  stream->print(F("esphome_text_sensor_failed{id=\""));
480  stream->print(relabel_id_(obj).c_str());
481  add_area_label_(stream, area);
482  add_node_label_(stream, node);
483  add_friendly_name_label_(stream, friendly_name);
484  stream->print(F("\",name=\""));
485  stream->print(relabel_name_(obj).c_str());
486  stream->print(F("\"} 0\n"));
487  // Data itself
488  stream->print(F("esphome_text_sensor_value{id=\""));
489  stream->print(relabel_id_(obj).c_str());
490  add_area_label_(stream, area);
491  add_node_label_(stream, node);
492  add_friendly_name_label_(stream, friendly_name);
493  stream->print(F("\",name=\""));
494  stream->print(relabel_name_(obj).c_str());
495  stream->print(F("\",value=\""));
496  stream->print(obj->state.c_str());
497  stream->print(F("\"} "));
498  stream->print(F("1.0"));
499  stream->print(F("\n"));
500  } else {
501  // Invalid state
502  stream->print(F("esphome_text_sensor_failed{id=\""));
503  stream->print(relabel_id_(obj).c_str());
504  add_area_label_(stream, area);
505  add_node_label_(stream, node);
506  add_friendly_name_label_(stream, friendly_name);
507  stream->print(F("\",name=\""));
508  stream->print(relabel_name_(obj).c_str());
509  stream->print(F("\"} 1\n"));
510  }
511 }
512 #endif
513 
514 } // namespace prometheus
515 } // namespace esphome
516 #endif
Base class for all switches.
Definition: switch.h:39
bool state
The current on/off state of the fan.
Definition: fan.h:110
void handleRequest(AsyncWebServerRequest *req) override
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:63
bool oscillating
The current oscillation state of the fan.
Definition: fan.h:112
bool is_on() const
Get the binary true/false state of these light color values.
Base class for all cover devices.
Definition: cover.h:111
std::string value_accuracy_to_string(float value, int8_t accuracy_decimals)
Create a string from a value and an accuracy in decimals.
Definition: helpers.cpp:432
LightColorValues current_values
The current values of the light as outputted to the light.
Definition: light_state.h:94
void add_node_label_(AsyncResponseStream *stream, std::string &node)
std::string get_effect_name()
Return the name of the current effect, or if no effect is active "None".
LockState state
The current reported state of the lock.
Definition: lock.h:122
virtual FanTraits get_traits()=0
std::string relabel_id_(EntityBase *obj)
const std::string & get_area() const
Get the area of this Application set by pre_setup().
Definition: application.h:208
const std::string & get_friendly_name() const
Get the friendly name of this Application set by pre_setup().
Definition: application.h:205
const std::vector< fan::Fan * > & get_fans()
Definition: application.h:297
void text_sensor_type_(AsyncResponseStream *stream)
Return the type for prometheus.
void switch_type_(AsyncResponseStream *stream)
Return the type for prometheus.
bool supports_oscillation() const
Return if this fan supports oscillation.
Definition: fan_traits.h:16
void add_area_label_(AsyncResponseStream *stream, std::string &area)
float tilt
The current tilt value of the cover from 0.0 to 1.0.
Definition: cover.h:124
std::string get_object_id() const
Definition: entity_base.cpp:43
void binary_sensor_row_(AsyncResponseStream *stream, binary_sensor::BinarySensor *obj, std::string &area, std::string &node, std::string &friendly_name)
Return the sensor state as prometheus data point.
virtual CoverTraits get_traits()=0
const std::vector< lock::Lock * > & get_locks()
Definition: application.h:397
float state
This member variable stores the last state that has passed through all filters.
Definition: sensor.h:131
This class represents the color state for a light object.
void text_sensor_row_(AsyncResponseStream *stream, text_sensor::TextSensor *obj, std::string &area, std::string &node, std::string &friendly_name)
Return the lock Values state as prometheus data point.
virtual bool has_state() const
Return whether this binary sensor has outputted a state.
void binary_sensor_type_(AsyncResponseStream *stream)
Return the type for prometheus.
const std::vector< switch_::Switch * > & get_switches()
Definition: application.h:257
void add_friendly_name_label_(AsyncResponseStream *stream, std::string &friendly_name)
int speed
The current fan speed level.
Definition: fan.h:114
void fan_row_(AsyncResponseStream *stream, fan::Fan *obj, std::string &area, std::string &node, std::string &friendly_name)
Return the sensor state as prometheus data point.
void switch_row_(AsyncResponseStream *stream, switch_::Switch *obj, std::string &area, std::string &node, std::string &friendly_name)
Return the switch Values state as prometheus data point.
bool is_internal() const
Definition: entity_base.cpp:22
std::string get_unit_of_measurement()
Get the unit of measurement, using the manual override if set.
Definition: entity_base.cpp:87
const std::vector< text_sensor::TextSensor * > & get_text_sensors()
Definition: application.h:287
std::map< EntityBase *, std::string > relabel_map_name_
bool state
The current reported state of the binary sensor.
Definition: binary_sensor.h:61
const std::vector< sensor::Sensor * > & get_sensors()
Definition: application.h:277
Application App
Global storage of Application pointer - only one Application can exist.
void light_type_(AsyncResponseStream *stream)
Return the type for prometheus.
const std::vector< binary_sensor::BinarySensor * > & get_binary_sensors()
Definition: application.h:247
const std::string & get_name() const
Get the name of this Application set by pre_setup().
Definition: application.h:202
void lock_row_(AsyncResponseStream *stream, lock::Lock *obj, std::string &area, std::string &node, std::string &friendly_name)
Return the lock Values state as prometheus data point.
const std::vector< cover::Cover * > & get_covers()
Definition: application.h:307
void lock_type_(AsyncResponseStream *stream)
Return the type for prometheus.
void sensor_row_(AsyncResponseStream *stream, sensor::Sensor *obj, std::string &area, std::string &node, std::string &friendly_name)
Return the sensor state as prometheus data point.
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
Definition: cover.h:122
void fan_type_(AsyncResponseStream *stream)
Return the type for prometheus.
void sensor_type_(AsyncResponseStream *stream)
Return the type for prometheus.
const std::vector< light::LightState * > & get_lights()
Definition: application.h:317
void cover_type_(AsyncResponseStream *stream)
Return the type for prometheus.
std::string relabel_name_(EntityBase *obj)
bool get_supports_tilt() const
Definition: cover_traits.h:14
void cover_row_(AsyncResponseStream *stream, cover::Cover *obj, std::string &area, std::string &node, std::string &friendly_name)
Return the switch Values state as prometheus data point.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
LightColorValues remote_values
The remote color values reported to the frontend.
Definition: light_state.h:106
void as_rgbw(float *red, float *green, float *blue, float *white, float gamma=0, bool color_interlock=false) const
Convert these light color values to an RGBW representation and write them to red, green...
int8_t get_accuracy_decimals()
Get the accuracy in decimals, using the manual override if set.
Definition: sensor.cpp:25
Base-class for all sensors.
Definition: sensor.h:57
void as_brightness(float *brightness, float gamma=0) const
Convert these light color values to a brightness-only representation and write them to brightness...
std::map< EntityBase *, std::string > relabel_map_id_
void light_row_(AsyncResponseStream *stream, light::LightState *obj, std::string &area, std::string &node, std::string &friendly_name)
Return the Light Values state as prometheus data point.
bool state
The current reported state of the binary sensor.
Definition: switch.h:53
const StringRef & get_name() const
Definition: entity_base.cpp:10
Base class for all locks.
Definition: lock.h:103
bool supports_speed() const
Return if this fan supports speed modes.
Definition: fan_traits.h:20