mirror of
https://github.com/esphome/esphome.git
synced 2025-10-02 01:52:21 +01:00
Add new Lock core component (#2958)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -45,6 +45,12 @@ void PrometheusHandler::handleRequest(AsyncWebServerRequest *req) {
|
||||
this->switch_row_(stream, obj);
|
||||
#endif
|
||||
|
||||
#ifdef USE_LOCK
|
||||
this->lock_type_(stream);
|
||||
for (auto *obj : App.get_locks())
|
||||
this->lock_row_(stream, obj);
|
||||
#endif
|
||||
|
||||
req->send(stream);
|
||||
}
|
||||
|
||||
@@ -310,6 +316,30 @@ void PrometheusHandler::switch_row_(AsyncResponseStream *stream, switch_::Switch
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_LOCK
|
||||
void PrometheusHandler::lock_type_(AsyncResponseStream *stream) {
|
||||
stream->print(F("#TYPE esphome_lock_value GAUGE\n"));
|
||||
stream->print(F("#TYPE esphome_lock_failed GAUGE\n"));
|
||||
}
|
||||
void PrometheusHandler::lock_row_(AsyncResponseStream *stream, lock::Lock *obj) {
|
||||
if (obj->is_internal())
|
||||
return;
|
||||
stream->print(F("esphome_lock_failed{id=\""));
|
||||
stream->print(obj->get_object_id().c_str());
|
||||
stream->print(F("\",name=\""));
|
||||
stream->print(obj->get_name().c_str());
|
||||
stream->print(F("\"} 0\n"));
|
||||
// Data itself
|
||||
stream->print(F("esphome_lock_value{id=\""));
|
||||
stream->print(obj->get_object_id().c_str());
|
||||
stream->print(F("\",name=\""));
|
||||
stream->print(obj->get_name().c_str());
|
||||
stream->print(F("\"} "));
|
||||
stream->print(obj->state);
|
||||
stream->print('\n');
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace prometheus
|
||||
} // namespace esphome
|
||||
|
||||
|
@@ -76,6 +76,13 @@ class PrometheusHandler : public AsyncWebHandler, public Component {
|
||||
void switch_row_(AsyncResponseStream *stream, switch_::Switch *obj);
|
||||
#endif
|
||||
|
||||
#ifdef USE_LOCK
|
||||
/// Return the type for prometheus
|
||||
void lock_type_(AsyncResponseStream *stream);
|
||||
/// Return the lock Values state as prometheus data point
|
||||
void lock_row_(AsyncResponseStream *stream, lock::Lock *obj);
|
||||
#endif
|
||||
|
||||
web_server_base::WebServerBase *base_;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user