From 1a55254258e93f479b8ccd76cae2bb1264cb50d6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 18 Jan 2026 18:28:24 -1000 Subject: [PATCH] [status] Convert to PollingComponent to reduce CPU usage (#13342) --- esphome/components/status/binary_sensor.py | 4 ++-- esphome/components/status/status_binary_sensor.cpp | 8 +++----- esphome/components/status/status_binary_sensor.h | 10 ++++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/esphome/components/status/binary_sensor.py b/esphome/components/status/binary_sensor.py index c1a4a52ce2..f0c7c87e17 100644 --- a/esphome/components/status/binary_sensor.py +++ b/esphome/components/status/binary_sensor.py @@ -7,14 +7,14 @@ DEPENDENCIES = ["network"] status_ns = cg.esphome_ns.namespace("status") StatusBinarySensor = status_ns.class_( - "StatusBinarySensor", binary_sensor.BinarySensor, cg.Component + "StatusBinarySensor", binary_sensor.BinarySensor, cg.PollingComponent ) CONFIG_SCHEMA = binary_sensor.binary_sensor_schema( StatusBinarySensor, device_class=DEVICE_CLASS_CONNECTIVITY, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, -).extend(cv.COMPONENT_SCHEMA) +).extend(cv.polling_component_schema("1s")) async def to_code(config): diff --git a/esphome/components/status/status_binary_sensor.cpp b/esphome/components/status/status_binary_sensor.cpp index 1795a9c41b..2c95be8569 100644 --- a/esphome/components/status/status_binary_sensor.cpp +++ b/esphome/components/status/status_binary_sensor.cpp @@ -10,12 +10,11 @@ #include "esphome/components/api/api_server.h" #endif -namespace esphome { -namespace status { +namespace esphome::status { static const char *const TAG = "status"; -void StatusBinarySensor::loop() { +void StatusBinarySensor::update() { bool status = network::is_connected(); #ifdef USE_MQTT if (mqtt::global_mqtt_client != nullptr) { @@ -33,5 +32,4 @@ void StatusBinarySensor::loop() { void StatusBinarySensor::setup() { this->publish_initial_state(false); } void StatusBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Status Binary Sensor", this); } -} // namespace status -} // namespace esphome +} // namespace esphome::status diff --git a/esphome/components/status/status_binary_sensor.h b/esphome/components/status/status_binary_sensor.h index feda8b6328..7e8c31d741 100644 --- a/esphome/components/status/status_binary_sensor.h +++ b/esphome/components/status/status_binary_sensor.h @@ -3,12 +3,11 @@ #include "esphome/core/component.h" #include "esphome/components/binary_sensor/binary_sensor.h" -namespace esphome { -namespace status { +namespace esphome::status { -class StatusBinarySensor : public binary_sensor::BinarySensor, public Component { +class StatusBinarySensor : public binary_sensor::BinarySensor, public PollingComponent { public: - void loop() override; + void update() override; void setup() override; void dump_config() override; @@ -16,5 +15,4 @@ class StatusBinarySensor : public binary_sensor::BinarySensor, public Component bool is_status_binary_sensor() const override { return true; } }; -} // namespace status -} // namespace esphome +} // namespace esphome::status