ESPHome
2023.11.6
|
This class simplifies creating components that periodically check a state. More...
#include <component.h>
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 () |
![]() | |
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_ |
![]() | |
uint32_t | component_state_ {0x0000} |
State of this component. More... | |
float | setup_priority_override_ {NAN} |
const char * | component_source_ {nullptr} |
Additional Inherited Members | |
![]() | |
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... | |
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 282 of file component.h.
|
inline |
Definition at line 284 of file component.h.
|
explicit |
Initialize this polling component with the given update interval in ms.
update_interval | The update interval in ms. |
Definition at line 185 of file component.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 187 of file component.cpp.
|
virtual |
Get the update interval in ms of this sensor.
Definition at line 205 of file component.cpp.
|
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.
update_interval | The update interval in ms. |
Definition at line 206 of file component.cpp.
void esphome::PollingComponent::start_poller | ( | ) |
Definition at line 195 of file component.cpp.
void esphome::PollingComponent::stop_poller | ( | ) |
Definition at line 200 of file component.cpp.
|
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::as7341::AS7341Component, esphome::max31856::MAX31856Sensor, esphome::ade7953_base::ADE7953, esphome::bme280::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::ads1115::ADS1115Sensor, esphome::xpt2046::XPT2046Component, 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::ili9xxx::ILI9XXXDisplay, esphome::max9611::MAX9611Component, esphome::bl0942::BL0942, esphome::max7219digit::MAX7219Component, esphome::alpha3::Alpha3, esphome::ezo::EZOSensor, esphome::max31865::MAX31865Sensor, 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::mcp3008::MCP3008Sensor, esphome::sgp30::SGP30Component, esphome::sigma_delta_output::SigmaDeltaOutput, esphome::wireguard::Wireguard, esphome::cse7761::CSE7761Component, esphome::ssd1306_base::SSD1306, esphome::pn532::PN532, esphome::ufire_ec::UFireECComponent, esphome::teleinfo::TeleInfo, esphome::airthings_wave_base::AirthingsWaveBase, esphome::ezo_pmp::EzoPMP, esphome::hbridge::HBridgeLightOutput, esphome::wifi_info::DNSAddressWifiInfo, esphome::st7920::ST7920, esphome::t6615::T6615Component, esphome::tm1638::TM1638Component, esphome::waveshare_epaper::WaveshareEPaper, esphome::duty_cycle::DutyCycleSensor, esphome::hm3301::HM3301Component, esphome::hx711::HX711Sensor, esphome::sntp::SNTPComponent, esphome::sps30::SPS30Component, 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::honeywellabp2_i2c::HONEYWELLABP2Sensor, esphome::max44009::MAX44009Sensor, 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::cse7766::CSE7766Component, 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::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::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::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::aht10::AHT10Component, 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.
|
protected |
Definition at line 318 of file component.h.