ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
husb238.cpp
Go to the documentation of this file.
1#include "husb238.h"
2#include "esphome/core/log.h"
3
4namespace esphome::husb238 {
5
6ESPHOME_LOG_TAG(TAG, "husb238");
7
9 uint8_t status;
10 if (!this->read_byte(REG_PD_STATUS1, &status)) {
11 this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
12 }
13}
14
16 uint8_t status;
17 if (!this->status_comm_result(this->read_byte(REG_PD_STATUS1, &status)))
18 return;
19
20#ifdef USE_BINARY_SENSOR
21 PUBLISH_STATE(this->attached_binary_sensor_, (status & PD_STATUS1_ATTACHED) != 0);
22 if (this->cc_direction_binary_sensor_ != nullptr) {
23 // The CC line only means something while a source is attached
24 if (status & PD_STATUS1_ATTACHED) {
25 this->cc_direction_binary_sensor_->publish_state((status & PD_STATUS1_CC_DIR) != 0);
26 } else {
27 this->cc_direction_binary_sensor_->invalidate_state();
28 }
29 }
30#endif
31}
32
34 ESP_LOGCONFIG(TAG, "HUSB238:");
35 LOG_I2C_DEVICE(this);
36 LOG_UPDATE_INTERVAL(this);
37#ifdef USE_BINARY_SENSOR
38 LOG_BINARY_SENSOR(" ", "PD Attached", this->attached_binary_sensor_);
39 LOG_BINARY_SENSOR(" ", "CC Direction", this->cc_direction_binary_sensor_);
40#endif
41}
42
43} // namespace esphome::husb238
uint8_t status
Definition bl0942.h:8
void mark_failed()
Mark this component as failed.
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
bool read_byte(uint8_t a_register, uint8_t *data)
Definition i2c.h:272
ESPHOME_LOG_TAG(TAG, "husb238")