ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
bq25186_binary_sensor.h
Go to the documentation of this file.
1#pragma once
2
4#ifdef USE_BINARY_SENSOR
5
6#include "bq25186.h"
8
9namespace esphome::bq25186 {
10
13 public:
14 BQ25186BinarySensor(uint8_t reg, uint8_t shift, uint8_t mask, uint8_t match)
15 : reg_(reg), shift_(shift), mask_(mask), match_(match) {}
16
17 void on_status(const BQ25186StatusRegisters &status) {
18 const uint8_t value = (status[this->reg_] >> this->shift_) & this->mask_;
19 this->publish_state((this->match_ >> value) & 1);
20 }
21
22 protected:
23 const uint8_t reg_;
24 const uint8_t shift_;
25 const uint8_t mask_;
26 const uint8_t match_;
27};
28
29} // namespace esphome::bq25186
30
31#endif // USE_BINARY_SENSOR
uint8_t status
Definition bl0942.h:8
Base class for all binary_sensor-type classes.
void publish_state(bool new_state)
Publish a new state to the front-end.
One field of a status register; match has a bit set for each field value that reads as on.
BQ25186BinarySensor(uint8_t reg, uint8_t shift, uint8_t mask, uint8_t match)
void on_status(const BQ25186StatusRegisters &status)
std::array< uint8_t, BQ25186_STATUS_REGISTER_COUNT > BQ25186StatusRegisters
Definition bq25186.h:39