ESPHome 2026.11.0-dev
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->read_byte(REG_PD_STATUS1, &status)) {
18 this->status_set_warning();
19 return;
20 }
22
23#ifdef USE_BINARY_SENSOR
24 if (this->attached_binary_sensor_ != nullptr) {
25 this->attached_binary_sensor_->publish_state((status & PD_STATUS1_ATTACHED) != 0);
26 }
27 if (this->cc_direction_binary_sensor_ != nullptr) {
28 // The CC line only means something while a source is attached
29 if (status & PD_STATUS1_ATTACHED) {
30 this->cc_direction_binary_sensor_->publish_state((status & PD_STATUS1_CC_DIR) != 0);
31 } else {
32 this->cc_direction_binary_sensor_->invalidate_state();
33 }
34 }
35#endif
36}
37
39 ESP_LOGCONFIG(TAG, "HUSB238:");
40 LOG_I2C_DEVICE(this);
41 LOG_UPDATE_INTERVAL(this);
42#ifdef USE_BINARY_SENSOR
43 LOG_BINARY_SENSOR(" ", "PD Attached", this->attached_binary_sensor_);
44 LOG_BINARY_SENSOR(" ", "CC Direction", this->cc_direction_binary_sensor_);
45#endif
46}
47
48} // namespace esphome::husb238
uint8_t status
Definition bl0942.h:8
void mark_failed()
Mark this component as failed.
void status_clear_warning()
Definition component.h:291
bool read_byte(uint8_t a_register, uint8_t *data)
Definition i2c.h:240
ESPHOME_LOG_TAG(TAG, "husb238")