ESPHome  2024.2.2
Public Member Functions | Protected Attributes
esphome::PollingComponent Class Referenceabstract

This class simplifies creating components that periodically check a state. More...

#include <component.h>

Inheritance diagram for esphome::PollingComponent:
esphome::Component esphome::adc128s102::ADC128S102Sensor esphome::adc::ADCSensor esphome::ade7953_base::ADE7953 esphome::ads1115::ADS1115Sensor esphome::aht10::AHT10Component esphome::airthings_wave_base::AirthingsWaveBase esphome::alpha3::Alpha3 esphome::am2320::AM2320Component esphome::am43::Am43 esphome::anova::Anova esphome::apds9960::APDS9960 esphome::as5600::AS5600Sensor esphome::as7341::AS7341Component esphome::atm90e26::ATM90E26Component esphome::atm90e32::ATM90E32Component esphome::bedjet::BedJetClimate esphome::bedjet::BedJetFan esphome::bedjet::BedJetHub esphome::bh1750::BH1750Sensor esphome::bl0939::BL0939 esphome::bl0940::BL0940 esphome::bl0942::BL0942 esphome::ble_client::BLEClientRSSISensor esphome::ble_client::BLESensor esphome::ble_client::BLETextSensor esphome::bme280_base::BME280Component esphome::bme680::BME680Component esphome::bmi160::BMI160Component esphome::bmp085::BMP085Component esphome::bmp280::BMP280Component esphome::bmp3xx::BMP3XXComponent esphome::bmp581::BMP581Component esphome::ccs811::CCS811Component esphome::cd74hc4067::CD74HC4067Sensor esphome::cse7761::CSE7761Component esphome::ct_clamp::CTClampSensor esphome::dallas::DallasComponent esphome::daly_bms::DalyBmsComponent esphome::debug::DebugComponent esphome::demo::DemoBinarySensor esphome::demo::DemoSensor esphome::demo::DemoTextSensor esphome::dht12::DHT12Component esphome::dht::DHT esphome::display::Display esphome::dps310::DPS310Component esphome::duty_cycle::DutyCycleSensor esphome::duty_time_sensor::DutyTimeSensor esphome::ee895::EE895Component esphome::emc2101::EMC2101Sensor esphome::ens160::ENS160Component esphome::ens210::ENS210Component esphome::esp32_hall::ESP32HallSensor esphome::ethernet_info::IPAddressEthernetInfo esphome::ezo::EZOSensor esphome::ezo_pmp::EzoPMP esphome::fingerprint_grow::FingerprintGrowComponent esphome::fs3000::FS3000Component esphome::gps::GPS esphome::growatt_solar::GrowattSolar esphome::havells_solar::HavellsSolar esphome::hbridge::HBridgeLightOutput esphome::hdc1080::HDC1080Component esphome::hlw8012::HLW8012Component esphome::hm3301::HM3301Component esphome::hmc5883l::HMC5883LComponent esphome::honeywell_hih_i2c::HoneywellHIComponent esphome::honeywellabp2_i2c::HONEYWELLABP2Sensor esphome::honeywellabp::HONEYWELLABPSensor esphome::hte501::HTE501Component esphome::htu21d::HTU21DComponent esphome::hx711::HX711Sensor esphome::hydreon_rgxx::HydreonRGxxComponent esphome::hyt271::HYT271Component esphome::iaqcore::IAQCore esphome::ina219::INA219Component esphome::ina226::INA226Component esphome::ina260::INA260Component esphome::ina3221::INA3221Component esphome::internal_temperature::InternalTemperatureSensor esphome::interval::IntervalTrigger esphome::kmeteriso::KMeterISOComponent esphome::kuntze::Kuntze esphome::lcd_base::LCDDisplay esphome::lightwaverf::LightWaveRF esphome::ltr390::LTR390Component esphome::max31855::MAX31855Sensor esphome::max31856::MAX31856Sensor esphome::max31865::MAX31865Sensor esphome::max44009::MAX44009Sensor esphome::max6675::MAX6675Sensor esphome::max7219::MAX7219Component esphome::max9611::MAX9611Component esphome::mcp3008::MCP3008Sensor esphome::mcp3204::MCP3204Sensor esphome::mcp9600::MCP9600Component esphome::mcp9808::MCP9808Sensor esphome::mhz19::MHZ19Component esphome::micronova::MicroNova esphome::mics_4514::MICS4514Component esphome::mlx90393::MLX90393Cls esphome::mlx90614::MLX90614Component esphome::mmc5603::MMC5603Component esphome::mmc5983::MMC5983Component esphome::modbus_controller::ModbusController esphome::mpl3115a2::MPL3115A2Component esphome::mpu6050::MPU6050Component esphome::mpu6886::MPU6886Component esphome::ms5611::MS5611Component esphome::nextion::Nextion esphome::nextion::NextionBinarySensor esphome::nextion::NextionSensor esphome::nextion::NextionSwitch esphome::nextion::NextionTextSensor esphome::pid::PIDSimulator esphome::pipsolar::Pipsolar esphome::pm1006::PM1006Component esphome::pmsa003i::PMSA003IComponent esphome::pmwcs3::PMWCS3Component esphome::pn532::PN532 esphome::pulse_counter::PulseCounterSensor esphome::pulse_width::PulseWidthSensor esphome::pvvx_mithermometer::PVVXDisplay esphome::pylontech::PylontechComponent esphome::pzem004t::PZEM004T esphome::pzemac::PZEMAC esphome::pzemdc::PZEMDC esphome::qmc5883l::QMC5883LComponent esphome::qmp6988::QMP6988Component esphome::radon_eye_rd200::RadonEyeRD200 esphome::rc522::RC522 esphome::scd4x::SCD4XComponent esphome::sdm_meter::SDMMeter esphome::sdp3x::SDP3XComponent esphome::selec_meter::SelecMeter esphome::sen0321_sensor::Sen0321Sensor esphome::sen21231_sensor::Sen21231Sensor esphome::sen5x::SEN5XComponent esphome::senseair::SenseAirComponent esphome::sfa30::SFA30Component esphome::sgp30::SGP30Component esphome::sgp4x::SGP4xComponent esphome::shelly_dimmer::ShellyDimmer esphome::sht3xd::SHT3XDComponent esphome::sht4x::SHT4XComponent esphome::shtcx::SHTCXComponent esphome::sigma_delta_output::SigmaDeltaOutput esphome::sim800l::Sim800LComponent esphome::sm300d2::SM300D2Sensor esphome::smt100::SMT100Component esphome::sps30::SPS30Component esphome::sts3x::STS3XComponent esphome::sun::SunSensor esphome::sun::SunTextSensor esphome::sun::SunTrigger esphome::t6615::T6615Component esphome::tcs34725::TCS34725Component esphome::tee501::TEE501Component esphome::teleinfo::TeleInfo esphome::template_::TemplateNumber esphome::template_::TemplateSelect esphome::template_::TemplateSensor esphome::template_::TemplateText esphome::template_::TemplateTextSensor esphome::time::RealTimeClock esphome::tm1621::TM1621Display esphome::tm1637::TM1637Display esphome::tm1638::TM1638Component esphome::tmp102::TMP102Component esphome::tmp1075::TMP1075Sensor esphome::tmp117::TMP117Component esphome::tof10120::TOF10120Sensor esphome::touchscreen::Touchscreen esphome::tsl2561::TSL2561Sensor esphome::tsl2591::TSL2591Component esphome::ufire_ec::UFireECComponent esphome::ufire_ise::UFireISEComponent esphome::ultrasonic::UltrasonicSensorComponent esphome::uptime::UptimeSensor esphome::veml3235::VEML3235Sensor esphome::vl53l0x::VL53L0XSensor esphome::wifi_info::BSSIDWiFiInfo esphome::wifi_info::DNSAddressWifiInfo esphome::wifi_info::IPAddressWiFiInfo esphome::wifi_info::ScanResultsWiFiInfo esphome::wifi_info::SSIDWiFiInfo esphome::wifi_signal::WiFiSignalSensor esphome::wireguard::Wireguard esphome::xgzp68xx::XGZP68XXComponent esphome::zio_ultrasonic::ZioUltrasonicComponent esphome::zyaura::ZyAuraSensor

Public Member Functions

 PollingComponent ()
 
 PollingComponent (uint32_t update_interval)
 Initialize this polling component with the given update interval in ms. More...
 
virtual void set_update_interval (uint32_t update_interval)
 Manually set the update interval in ms for this polling object. More...
 
virtual void update ()=0
 
void call_setup () override
 
virtual uint32_t get_update_interval () const
 Get the update interval in ms of this sensor. More...
 
void start_poller ()
 
void stop_poller ()
 
- Public Member Functions inherited from esphome::Component
virtual void setup ()
 Where the component's initialization should happen. More...
 
virtual void loop ()
 This method will be called repeatedly. More...
 
virtual void dump_config ()
 
virtual float get_setup_priority () const
 priority of setup(). More...
 
float get_actual_setup_priority () const
 
void set_setup_priority (float priority)
 
virtual float get_loop_priority () const
 priority of loop(). More...
 
void call ()
 
virtual void on_shutdown ()
 
virtual void on_safe_shutdown ()
 
uint32_t get_component_state () const
 
virtual void mark_failed ()
 Mark this component as failed. More...
 
bool is_failed ()
 
bool is_ready ()
 
virtual bool can_proceed ()
 
bool status_has_warning ()
 
bool status_has_error ()
 
void status_set_warning ()
 
void status_set_error ()
 
void status_clear_warning ()
 
void status_clear_error ()
 
void status_momentary_warning (const std::string &name, uint32_t length=5000)
 
void status_momentary_error (const std::string &name, uint32_t length=5000)
 
bool has_overridden_loop () const
 
void set_component_source (const char *source)
 Set where this component was loaded from for some debug messages. More...
 
const char * get_component_source () const
 Get the integration where this component was declared as a string. More...
 

Protected Attributes

uint32_t update_interval_
 
- Protected Attributes inherited from esphome::Component
uint32_t component_state_ {0x0000}
 State of this component. More...
 
float setup_priority_override_ {NAN}
 
const char * component_source_ {nullptr}
 

Additional Inherited Members

- Protected Member Functions inherited from esphome::Component
virtual void call_loop ()
 
virtual void call_dump_config ()
 
void set_interval (const std::string &name, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a unique name. More...
 
void set_interval (uint32_t interval, std::function< void()> &&f)
 
bool cancel_interval (const std::string &name)
 Cancel an interval function. More...
 
void set_retry (const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 Set an retry function with a unique name. More...
 
void set_retry (uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 
bool cancel_retry (const std::string &name)
 Cancel a retry function. More...
 
void set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a unique name. More...
 
void set_timeout (uint32_t timeout, std::function< void()> &&f)
 
bool cancel_timeout (const std::string &name)
 Cancel a timeout function. More...
 
void defer (const std::string &name, std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
void defer (std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
bool cancel_defer (const std::string &name)
 Cancel a defer callback using the specified name, name must not be empty. More...
 

Detailed Description

This class simplifies creating components that periodically check a state.

You basically just need to implement the update() function, it will be called every update_interval ms after startup. Note that this class cannot guarantee a correct timing, as it's not using timers, just a software polling feature with set_interval() from Component.

Definition at line 283 of file component.h.

Constructor & Destructor Documentation

◆ PollingComponent() [1/2]

esphome::PollingComponent::PollingComponent ( )
inline

Definition at line 285 of file component.h.

◆ PollingComponent() [2/2]

esphome::PollingComponent::PollingComponent ( uint32_t  update_interval)
explicit

Initialize this polling component with the given update interval in ms.

Parameters
update_intervalThe update interval in ms.

Definition at line 185 of file component.cpp.

Member Function Documentation

◆ call_setup()

void esphome::PollingComponent::call_setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 187 of file component.cpp.

◆ get_update_interval()

uint32_t esphome::PollingComponent::get_update_interval ( ) const
virtual

Get the update interval in ms of this sensor.

Definition at line 205 of file component.cpp.

◆ set_update_interval()

void esphome::PollingComponent::set_update_interval ( uint32_t  update_interval)
virtual

Manually set the update interval in ms for this polling object.

Override this if you want to do some validation for the update interval.

Parameters
update_intervalThe update interval in ms.

Definition at line 206 of file component.cpp.

◆ start_poller()

void esphome::PollingComponent::start_poller ( )

Definition at line 195 of file component.cpp.

◆ stop_poller()

void esphome::PollingComponent::stop_poller ( )

Definition at line 200 of file component.cpp.

◆ update()

virtual void esphome::PollingComponent::update ( )
pure virtual

Implemented in esphome::nextion::Nextion, esphome::modbus_controller::ModbusController, esphome::tsl2591::TSL2591Component, esphome::st7789v::ST7789V, esphome::micronova::MicroNova, esphome::bedjet::BedJetHub, esphome::inkplate6::Inkplate6, esphome::bme680::BME680Component, esphome::wifi_info::BSSIDWiFiInfo, esphome::mpl3115a2::MPL3115A2Component, esphome::fingerprint_grow::FingerprintGrowComponent, esphome::qmp6988::QMP6988Component, esphome::sun::SunTrigger, esphome::wifi_info::SSIDWiFiInfo, esphome::touchscreen::Touchscreen, esphome::as7341::AS7341Component, esphome::max31856::MAX31856Sensor, esphome::ade7953_base::ADE7953, esphome::ili9xxx::ILI9XXXDisplay, esphome::bme280_base::BME280Component, esphome::havells_solar::HavellsSolar, esphome::bmp3xx::BMP3XXComponent, esphome::pulse_counter::PulseCounterSensor, esphome::sgp4x::SGP4xComponent, esphome::bl0939::BL0939, esphome::bl0940::BL0940, esphome::zyaura::ZyAuraSensor, esphome::daly_bms::DalyBmsComponent, esphome::bmp280::BMP280Component, esphome::bmp581::BMP581Component, esphome::sen21231_sensor::Sen21231Sensor, esphome::tsl2561::TSL2561Sensor, esphome::pid::PIDSimulator, esphome::template_::TemplateText, esphome::veml3235::VEML3235Sensor, esphome::ads1115::ADS1115Sensor, esphome::tmp1075::TMP1075Sensor, esphome::ltr390::LTR390Component, esphome::sdm_meter::SDMMeter, esphome::tcs34725::TCS34725Component, esphome::wifi_info::ScanResultsWiFiInfo, esphome::sen5x::SEN5XComponent, esphome::sim800l::Sim800LComponent, esphome::addressable_light::AddressableLightDisplay, esphome::dht::DHT, esphome::cd74hc4067::CD74HC4067Sensor, esphome::st7735::ST7735, esphome::pcd8544::PCD8544, esphome::dps310::DPS310Component, esphome::gps::GPS, esphome::pvvx_mithermometer::PVVXDisplay, esphome::hmc5883l::HMC5883LComponent, esphome::hydreon_rgxx::HydreonRGxxComponent, esphome::max9611::MAX9611Component, esphome::bl0942::BL0942, esphome::st7567_base::ST7567, esphome::alpha3::Alpha3, esphome::ezo::EZOSensor, esphome::max7219digit::MAX7219Component, esphome::max31865::MAX31865Sensor, esphome::pn532::PN532, esphome::tm1637::TM1637Display, esphome::pulse_width::PulseWidthSensor, esphome::ufire_ise::UFireISEComponent, esphome::hlw8012::HLW8012Component, esphome::tm1621::TM1621Display, esphome::adc::ADCSensor, esphome::pmsa003i::PMSA003IComponent, esphome::qmc5883l::QMC5883LComponent, esphome::vl53l0x::VL53L0XSensor, esphome::wireguard::Wireguard, esphome::sgp30::SGP30Component, esphome::sigma_delta_output::SigmaDeltaOutput, esphome::ssd1306_base::SSD1306, esphome::cse7761::CSE7761Component, esphome::ufire_ec::UFireECComponent, esphome::pylontech::PylontechComponent, esphome::teleinfo::TeleInfo, esphome::airthings_wave_base::AirthingsWaveBase, esphome::ezo_pmp::EzoPMP, esphome::hbridge::HBridgeLightOutput, esphome::wifi_info::DNSAddressWifiInfo, esphome::t6615::T6615Component, esphome::tm1638::TM1638Component, esphome::waveshare_epaper::WaveshareEPaperBase, esphome::duty_cycle::DutyCycleSensor, esphome::hm3301::HM3301Component, esphome::hx711::HX711Sensor, esphome::sntp::SNTPComponent, esphome::sps30::SPS30Component, esphome::st7920::ST7920, esphome::radon_eye_rd200::RadonEyeRD200, esphome::sen0321_sensor::Sen0321Sensor, esphome::ultrasonic::UltrasonicSensorComponent, esphome::anova::Anova, esphome::lcd_base::LCDDisplay, esphome::lightwaverf::LightWaveRF, esphome::max7219::MAX7219Component, esphome::mcp9600::MCP9600Component, esphome::scd4x::SCD4XComponent, esphome::ccs811::CCS811Component, esphome::pzemac::PZEMAC, esphome::shelly_dimmer::ShellyDimmer, esphome::ssd1325_base::SSD1325, esphome::bh1750::BH1750Sensor, esphome::ble_client::BLESensor, esphome::dallas::DallasComponent, esphome::growatt_solar::GrowattSolar, esphome::max31855::MAX31855Sensor, esphome::sht4x::SHT4XComponent, esphome::sm300d2::SM300D2Sensor, esphome::am43::Am43, esphome::debug::DebugComponent, esphome::htu21d::HTU21DComponent, esphome::kmeteriso::KMeterISOComponent, esphome::kuntze::Kuntze, esphome::mmc5603::MMC5603Component, esphome::pzem004t::PZEM004T, esphome::rc522::RC522, esphome::sht3xd::SHT3XDComponent, esphome::shtcx::SHTCXComponent, esphome::ssd1351_base::SSD1351, esphome::adc128s102::ADC128S102Sensor, esphome::bedjet::BedJetClimate, esphome::ee895::EE895Component, esphome::ens160::ENS160Component, esphome::honeywellabp2_i2c::HONEYWELLABP2Sensor, esphome::max44009::MAX44009Sensor, esphome::mcp3008::MCP3008Sensor, esphome::mcp3204::MCP3204Sensor, esphome::pzemdc::PZEMDC, esphome::ssd1322_base::SSD1322, esphome::ssd1327_base::SSD1327, esphome::sun::SunSensor, esphome::ble_client::BLEClientRSSISensor, esphome::ble_client::BLETextSensor, esphome::duty_time_sensor::DutyTimeSensor, esphome::hdc1080::HDC1080Component, esphome::honeywellabp::HONEYWELLABPSensor, esphome::hte501::HTE501Component, esphome::max6675::MAX6675Sensor, esphome::sun::SunTextSensor, esphome::bedjet::BedJetFan, esphome::fs3000::FS3000Component, esphome::mhz19::MHZ19Component, esphome::mlx90393::MLX90393Cls, esphome::nextion::NextionBinarySensor, esphome::pm1006::PM1006Component, esphome::smt100::SMT100Component, esphome::sts3x::STS3XComponent, esphome::zio_ultrasonic::ZioUltrasonicComponent, esphome::aht10::AHT10Component, esphome::atm90e26::ATM90E26Component, esphome::atm90e32::ATM90E32Component, esphome::emc2101::EMC2101Sensor, esphome::hyt271::HYT271Component, esphome::ina219::INA219Component, esphome::nextion::NextionSensor, esphome::sfa30::SFA30Component, esphome::bmp085::BMP085Component, esphome::ens210::ENS210Component, esphome::honeywell_hih_i2c::HoneywellHIComponent, esphome::iaqcore::IAQCore, esphome::mcp9808::MCP9808Sensor, esphome::pmwcs3::PMWCS3Component, esphome::senseair::SenseAirComponent, esphome::ssd1331_base::SSD1331, esphome::tee501::TEE501Component, esphome::template_::TemplateNumber, esphome::template_::TemplateSelect, esphome::tmp102::TMP102Component, esphome::tof10120::TOF10120Sensor, esphome::xgzp68xx::XGZP68XXComponent, esphome::am2320::AM2320Component, esphome::as5600::AS5600Sensor, esphome::bmi160::BMI160Component, esphome::dht12::DHT12Component, esphome::esp32_hall::ESP32HallSensor, esphome::ina226::INA226Component, esphome::mpu6050::MPU6050Component, esphome::mpu6886::MPU6886Component, esphome::ms5611::MS5611Component, esphome::nextion::NextionSwitch, esphome::sdp3x::SDP3XComponent, esphome::tmp117::TMP117Component, esphome::ethernet_info::IPAddressEthernetInfo, esphome::gps::GPSTime, esphome::ina260::INA260Component, esphome::ina3221::INA3221Component, esphome::mlx90614::MLX90614Component, esphome::nextion::NextionTextSensor, esphome::template_::TemplateTextSensor, esphome::ct_clamp::CTClampSensor, esphome::ds1307::DS1307Component, esphome::homeassistant::HomeassistantTime, esphome::internal_temperature::InternalTemperatureSensor, esphome::pcf85063::PCF85063Component, esphome::pcf8563::PCF8563Component, esphome::template_::TemplateSensor, esphome::wifi_signal::WiFiSignalSensor, esphome::demo::DemoBinarySensor, esphome::demo::DemoSensor, esphome::demo::DemoTextSensor, esphome::mmc5983::MMC5983Component, esphome::wifi_info::IPAddressWiFiInfo, esphome::interval::IntervalTrigger, and esphome::uptime::UptimeSensor.

Field Documentation

◆ update_interval_

uint32_t esphome::PollingComponent::update_interval_
protected

Definition at line 319 of file component.h.


The documentation for this class was generated from the following files: