ESPHome  2021.9.1
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::addressable_light::AddressableLightDisplay esphome::ade7953::ADE7953 esphome::ads1115::ADS1115Sensor esphome::aht10::AHT10Component esphome::airthings_wave_plus::AirthingsWavePlus esphome::am2320::AM2320Component esphome::am43::Am43 esphome::anova::Anova esphome::apds9960::APDS9960 esphome::atm90e32::ATM90E32Component esphome::bh1750::BH1750Sensor esphome::ble_client::BLESensor 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::demo::DemoBinarySensor esphome::demo::DemoSensor esphome::demo::DemoTextSensor esphome::dht12::DHT12Component esphome::dht::DHT esphome::duty_cycle::DutyCycleSensor esphome::esp32_hall::ESP32HallSensor esphome::ezo::EZOSensor esphome::fingerprint_grow::FingerprintGrowComponent esphome::gps::GPS esphome::havells_solar::HavellsSolar esphome::hbridge::HBridgeLightOutput esphome::hdc1080::HDC1080Component esphome::hlw8012::HLW8012Component esphome::hm3301::HM3301Component esphome::hmc5883l::HMC5883LComponent esphome::htu21d::HTU21DComponent esphome::hx711::HX711Sensor esphome::ili9341::ILI9341Display esphome::ina219::INA219Component esphome::ina226::INA226Component esphome::ina3221::INA3221Component esphome::inkplate6::Inkplate6 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::mcp9808::MCP9808Sensor esphome::mhz19::MHZ19Component esphome::mpu6050::MPU6050Component esphome::ms5611::MS5611Component esphome::nextion::Nextion esphome::nextion::NextionBinarySensor esphome::nextion::NextionSensor esphome::nextion::NextionSwitch esphome::nextion::NextionTextSensor esphome::pcd8544::PCD8544 esphome::pid::PIDSimulator esphome::pipsolar::Pipsolar esphome::pm1006::PM1006Component esphome::pmsa003i::PMSA003IComponent esphome::pn532::PN532 esphome::pulse_counter::PulseCounterSensor esphome::pulse_width::PulseWidthSensor esphome::pzem004t::PZEM004T esphome::pzemac::PZEMAC esphome::pzemdc::PZEMDC esphome::qmc5883l::QMC5883LComponent esphome::rc522::RC522 esphome::scd30::SCD30Component esphome::sdm_meter::SDMMeter esphome::sdp3x::SDP3XComponent esphome::selec_meter::SelecMeter esphome::senseair::SenseAirComponent esphome::sgp30::SGP30Component esphome::sgp40::SGP40Component esphome::sht3xd::SHT3XDComponent esphome::sht4x::SHT4XComponent esphome::shtcx::SHTCXComponent esphome::sim800l::Sim800LComponent esphome::sm300d2::SM300D2Sensor esphome::sps30::SPS30Component esphome::ssd1306_base::SSD1306 esphome::ssd1322_base::SSD1322 esphome::ssd1325_base::SSD1325 esphome::ssd1327_base::SSD1327 esphome::ssd1331_base::SSD1331 esphome::ssd1351_base::SSD1351 esphome::st7735::ST7735 esphome::st7789v::ST7789V esphome::st7920::ST7920 esphome::sts3x::STS3XComponent esphome::sun::SunSensor esphome::sun::SunTextSensor esphome::sun::SunTrigger esphome::t6615::T6615Component esphome::tcs34725::TCS34725Component esphome::teleinfo::TeleInfo esphome::template_::TemplateNumber esphome::template_::TemplateSelect esphome::template_::TemplateSensor esphome::template_::TemplateTextSensor esphome::time::RealTimeClock esphome::tm1637::TM1637Display esphome::tmp102::TMP102Component esphome::tmp117::TMP117Component esphome::tof10120::TOF10120Sensor esphome::tsl2561::TSL2561Sensor esphome::tsl2591::TSL2591Component esphome::ultrasonic::UltrasonicSensorComponent esphome::uptime::UptimeSensor esphome::vl53l0x::VL53L0XSensor esphome::waveshare_epaper::WaveshareEPaper esphome::wifi_signal::WiFiSignalSensor esphome::xpt2046::XPT2046Component 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
 
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 ()
 
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 230 of file component.h.

Constructor & Destructor Documentation

◆ PollingComponent() [1/2]

esphome::PollingComponent::PollingComponent ( )
inline

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

Member Function Documentation

◆ call_setup()

void esphome::PollingComponent::call_setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 168 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 176 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 177 of file component.cpp.

◆ update()

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

Implemented in esphome::nextion::Nextion, esphome::tsl2591::TSL2591Component, esphome::st7789v::ST7789V, esphome::bme680::BME680Component, esphome::fingerprint_grow::FingerprintGrowComponent, esphome::bme280::BME280Component, esphome::sun::SunTrigger, esphome::max31856::MAX31856Sensor, esphome::xpt2046::XPT2046Component, esphome::havells_solar::HavellsSolar, esphome::inkplate6::Inkplate6, esphome::zyaura::ZyAuraSensor, esphome::bmp280::BMP280Component, esphome::tsl2561::TSL2561Sensor, esphome::pid::PIDSimulator, esphome::pulse_counter::PulseCounterSensor, esphome::ads1115::ADS1115Sensor, esphome::sdm_meter::SDMMeter, esphome::sgp40::SGP40Component, esphome::addressable_light::AddressableLightDisplay, esphome::dht::DHT, esphome::pcd8544::PCD8544, esphome::st7735::ST7735, esphome::hmc5883l::HMC5883LComponent, esphome::ade7953::ADE7953, esphome::sim800l::Sim800LComponent, esphome::tcs34725::TCS34725Component, esphome::gps::GPS, esphome::max31865::MAX31865Sensor, esphome::bh1750::BH1750Sensor, esphome::pulse_width::PulseWidthSensor, esphome::ili9341::ILI9341Display, esphome::pmsa003i::PMSA003IComponent, esphome::qmc5883l::QMC5883LComponent, esphome::mcp3008::MCP3008Sensor, esphome::max7219digit::MAX7219Component, esphome::sgp30::SGP30Component, esphome::tm1637::TM1637Display, esphome::vl53l0x::VL53L0XSensor, esphome::hbridge::HBridgeLightOutput, esphome::max7219::MAX7219Component, esphome::airthings_wave_plus::AirthingsWavePlus, esphome::st7920::ST7920, esphome::t6615::T6615Component, esphome::duty_cycle::DutyCycleSensor, esphome::hm3301::HM3301Component, esphome::pn532::PN532, esphome::sntp::SNTPComponent, esphome::sps30::SPS30Component, esphome::ssd1306_base::SSD1306, esphome::teleinfo::TeleInfo, esphome::waveshare_epaper::WaveshareEPaper, esphome::anova::Anova, esphome::hx711::HX711Sensor, esphome::adc::ADCSensor, esphome::ccs811::CCS811Component, esphome::hlw8012::HLW8012Component, esphome::lcd_base::LCDDisplay, esphome::scd30::SCD30Component, esphome::ssd1325_base::SSD1325, esphome::ultrasonic::UltrasonicSensorComponent, esphome::dallas::DallasComponent, esphome::sm300d2::SM300D2Sensor, esphome::am43::Am43, esphome::ble_client::BLESensor, esphome::max31855::MAX31855Sensor, esphome::sht4x::SHT4XComponent, esphome::shtcx::SHTCXComponent, esphome::ssd1351_base::SSD1351, esphome::ssd1322_base::SSD1322, esphome::ssd1327_base::SSD1327, 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::mhz19::MHZ19Component, esphome::nextion::NextionBinarySensor, esphome::pm1006::PM1006Component, esphome::pzemdc::PZEMDC, esphome::rc522::RC522, esphome::atm90e32::ATM90E32Component, esphome::nextion::NextionSensor, esphome::sun::SunTextSensor, esphome::apds9960::APDS9960, esphome::bmp085::BMP085Component, esphome::mcp9808::MCP9808Sensor, esphome::senseair::SenseAirComponent, esphome::ssd1331_base::SSD1331, esphome::sts3x::STS3XComponent, esphome::template_::TemplateNumber, esphome::template_::TemplateSelect, esphome::tmp102::TMP102Component, esphome::tof10120::TOF10120Sensor, esphome::am2320::AM2320Component, esphome::dht12::DHT12Component, esphome::esp32_hall::ESP32HallSensor, esphome::ezo::EZOSensor, esphome::ina219::INA219Component, esphome::ina226::INA226Component, esphome::mpu6050::MPU6050Component, esphome::ms5611::MS5611Component, esphome::nextion::NextionSwitch, esphome::tmp117::TMP117Component, esphome::ct_clamp::CTClampSensor, esphome::ina3221::INA3221Component, esphome::nextion::NextionTextSensor, esphome::template_::TemplateTextSensor, esphome::aht10::AHT10Component, esphome::ds1307::DS1307Component, esphome::homeassistant::HomeassistantTime, esphome::sdp3x::SDP3XComponent, esphome::template_::TemplateSensor, esphome::wifi_signal::WiFiSignalSensor, esphome::demo::DemoBinarySensor, esphome::demo::DemoSensor, esphome::demo::DemoTextSensor, esphome::gps::GPSTime, esphome::interval::IntervalTrigger, and esphome::uptime::UptimeSensor.

Field Documentation

◆ update_interval_

uint32_t esphome::PollingComponent::update_interval_
protected

Definition at line 260 of file component.h.


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