ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
bq25186_text_sensor.cpp
Go to the documentation of this file.
2#ifdef USE_TEXT_SENSOR
3
5
6namespace esphome::bq25186 {
7
8// STAT0[6:5] charge status, then STAT1[4:3] TS status
9PROGMEM_STRING_TABLE(StatusStrings, "Not Charging", "Constant Current", "Constant Voltage", "Charge Done/Disabled",
10 "Normal", "Hot/Cold (Charging Suspended)", "Cool (Current Reduced)", "Warm (Voltage Reduced)");
11
13 const uint8_t value = (status[this->reg_] >> this->shift_) & 0x03;
14 if (value == this->last_)
15 return;
16 this->last_ = value;
17 const ProgmemStr name = StatusStrings::get_progmem_str(this->first_ + value, StatusStrings::LAST_INDEX);
18 char text[32];
19 ESPHOME_strncpy_P(text, reinterpret_cast<ESPHOME_PGM_P>(name), sizeof(text));
20 text[sizeof(text) - 1] = '\0';
21 this->publish_state(text);
22}
23
24} // namespace esphome::bq25186
25
26#endif // USE_TEXT_SENSOR
uint8_t status
Definition bl0942.h:8
void on_status(const BQ25186StatusRegisters &status)
void publish_state(const std::string &state)
Definition text_sensor.h:41
PROGMEM_STRING_TABLE(StatusStrings, "Not Charging", "Constant Current", "Constant Voltage", "Charge Done/Disabled", "Normal", "Hot/Cold (Charging Suspended)", "Cool (Current Reduced)", "Warm (Voltage Reduced)")
std::array< uint8_t, BQ25186_STATUS_REGISTER_COUNT > BQ25186StatusRegisters
Definition bq25186.h:39
const __FlashStringHelper * ProgmemStr
Definition progmem.h:31