ESPHome  1.15.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::adc::ADCSensor esphome::ade7953::ADE7953 esphome::ads1115::ADS1115Sensor esphome::aht10::AHT10Component esphome::am2320::AM2320Component esphome::apds9960::APDS9960 esphome::atm90e32::ATM90E32Component esphome::bh1750::BH1750Sensor esphome::bme280::BME280Component esphome::bme680::BME680Component esphome::bmp085::BMP085Component esphome::bmp280::BMP280Component esphome::ccs811::CCS811Component esphome::cse7766::CSE7766Component esphome::ct_clamp::CTClampSensor esphome::dallas::DallasComponent esphome::dht12::DHT12Component esphome::dht::DHT esphome::duty_cycle::DutyCycleSensor esphome::esp32_hall::ESP32HallSensor esphome::hdc1080::HDC1080Component esphome::hlw8012::HLW8012Component esphome::hm3301::HM3301Component esphome::hmc5883l::HMC5883LComponent esphome::htu21d::HTU21DComponent esphome::hx711::HX711Sensor esphome::ina219::INA219Component esphome::ina226::INA226Component esphome::ina3221::INA3221Component esphome::interval::IntervalTrigger esphome::lcd_base::LCDDisplay esphome::max31855::MAX31855Sensor esphome::max31856::MAX31856Sensor esphome::max31865::MAX31865Sensor esphome::max6675::MAX6675Sensor esphome::max7219::MAX7219Component esphome::max7219digit::MAX7219Component esphome::mcp3008::MCP3008Sensor esphome::mhz19::MHZ19Component esphome::mpu6050::MPU6050Component esphome::ms5611::MS5611Component esphome::nextion::Nextion esphome::pcd8544::PCD8544 esphome::pid::PIDSimulator esphome::pn532::PN532 esphome::pulse_counter::PulseCounterSensor esphome::pulse_width::PulseWidthSensor esphome::pzem004t::PZEM004T esphome::pzemac::PZEMAC esphome::pzemdc::PZEMDC esphome::qmc5883l::QMC5883LComponent esphome::scd30::SCD30Component esphome::senseair::SenseAirComponent esphome::sensor::PollingSensorComponent esphome::sgp30::SGP30Component esphome::sht3xd::SHT3XDComponent esphome::shtcx::SHTCXComponent esphome::sim800l::Sim800LComponent esphome::sps30::SPS30Component esphome::ssd1306_base::SSD1306 esphome::ssd1325_base::SSD1325 esphome::ssd1351_base::SSD1351 esphome::st7789v::ST7789V esphome::sts3x::STS3XComponent esphome::sun::SunSensor esphome::sun::SunTextSensor esphome::sun::SunTrigger esphome::tcs34725::TCS34725Component esphome::template_::TemplateSensor esphome::template_::TemplateTextSensor esphome::tm1637::TM1637Display esphome::tmp117::TMP117Component esphome::tsl2561::TSL2561Sensor esphome::ultrasonic::UltrasonicSensorComponent esphome::uptime::UptimeSensor esphome::vl53l0x::VL53L0XSensor esphome::waveshare_epaper::WaveshareEPaper esphome::wifi_signal::WiFiSignalSensor 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...
 
- 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 ()
 
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
 

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}
 

Additional Inherited Members

- Protected Member Functions inherited from esphome::Component
virtual void call_loop ()
 
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_timeout (uint32_t timeout, std::function< void()> &&f)
 
void set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a unique name. More...
 
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 210 of file component.h.

Constructor & Destructor Documentation

◆ PollingComponent() [1/2]

esphome::PollingComponent::PollingComponent ( )
inline

Definition at line 212 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 156 of file component.cpp.

Member Function Documentation

◆ call_setup()

void esphome::PollingComponent::call_setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 158 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 166 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 167 of file component.cpp.

◆ update()

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

Implemented in esphome::nextion::Nextion, esphome::st7789v::ST7789V, esphome::bme680::BME680Component, esphome::sun::SunTrigger, esphome::bme280::BME280Component, esphome::max31856::MAX31856Sensor, esphome::zyaura::ZyAuraSensor, esphome::bmp280::BMP280Component, esphome::tsl2561::TSL2561Sensor, esphome::pid::PIDSimulator, esphome::pulse_counter::PulseCounterSensor, esphome::ads1115::ADS1115Sensor, esphome::dht::DHT, esphome::pcd8544::PCD8544, esphome::hmc5883l::HMC5883LComponent, esphome::tcs34725::TCS34725Component, esphome::max31865::MAX31865Sensor, esphome::sim800l::Sim800LComponent, esphome::bh1750::BH1750Sensor, esphome::pulse_width::PulseWidthSensor, esphome::mcp3008::MCP3008Sensor, esphome::qmc5883l::QMC5883LComponent, esphome::ade7953::ADE7953, esphome::max7219digit::MAX7219Component, esphome::tm1637::TM1637Display, esphome::max7219::MAX7219Component, esphome::duty_cycle::DutyCycleSensor, esphome::hm3301::HM3301Component, esphome::sps30::SPS30Component, esphome::ssd1306_base::SSD1306, esphome::vl53l0x::VL53L0XSensor, esphome::waveshare_epaper::WaveshareEPaper, esphome::hx711::HX711Sensor, esphome::lcd_base::LCDDisplay, esphome::ssd1325_base::SSD1325, esphome::ultrasonic::UltrasonicSensorComponent, esphome::dallas::DallasComponent, esphome::ccs811::CCS811Component, esphome::pn532::PN532, esphome::sgp30::SGP30Component, esphome::max31855::MAX31855Sensor, esphome::shtcx::SHTCXComponent, esphome::ssd1351_base::SSD1351, esphome::adc::ADCSensor, esphome::scd30::SCD30Component, esphome::sun::SunSensor, esphome::hdc1080::HDC1080Component, esphome::htu21d::HTU21DComponent, esphome::max6675::MAX6675Sensor, esphome::pzem004t::PZEM004T, esphome::pzemac::PZEMAC, esphome::sht3xd::SHT3XDComponent, esphome::cse7766::CSE7766Component, esphome::hlw8012::HLW8012Component, esphome::mhz19::MHZ19Component, esphome::pzemdc::PZEMDC, esphome::atm90e32::ATM90E32Component, esphome::sun::SunTextSensor, esphome::apds9960::APDS9960, esphome::bmp085::BMP085Component, esphome::sts3x::STS3XComponent, esphome::am2320::AM2320Component, esphome::dht12::DHT12Component, esphome::esp32_hall::ESP32HallSensor, esphome::ina219::INA219Component, esphome::ina226::INA226Component, esphome::mpu6050::MPU6050Component, esphome::ms5611::MS5611Component, esphome::senseair::SenseAirComponent, esphome::tmp117::TMP117Component, esphome::ct_clamp::CTClampSensor, esphome::ina3221::INA3221Component, esphome::template_::TemplateTextSensor, esphome::aht10::AHT10Component, esphome::template_::TemplateSensor, esphome::wifi_signal::WiFiSignalSensor, esphome::interval::IntervalTrigger, and esphome::uptime::UptimeSensor.

Field Documentation

◆ update_interval_

uint32_t esphome::PollingComponent::update_interval_
protected

Definition at line 240 of file component.h.


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