8 static const char *
const TAG =
"kmeteriso.sensor";
10 static const uint8_t KMETER_ERROR_STATUS_REG = 0x20;
11 static const uint8_t KMETER_TEMP_VAL_REG = 0x00;
12 static const uint8_t KMETER_INTERNAL_TEMP_VAL_REG = 0x10;
13 static const uint8_t KMETER_FIRMWARE_VERSION_REG = 0xFE;
16 ESP_LOGCONFIG(TAG,
"Setting up KMeterISO...");
17 this->error_code_ =
NONE;
28 ESP_LOGCONFIG(TAG,
"Could write to the address %d.", this->
address_);
30 ESP_LOGCONFIG(TAG,
"Could not write to the address %d.", this->
address_);
36 uint8_t read_buf[4] = {1};
37 if (!this->
read_bytes(KMETER_ERROR_STATUS_REG, read_buf, 1)) {
38 ESP_LOGCONFIG(TAG,
"Could not read from the device.");
43 if (read_buf[0] != 0) {
44 ESP_LOGCONFIG(TAG,
"The device is not ready.");
49 ESP_LOGCONFIG(TAG,
"The device was successfully setup.");
58 if (!this->
read_bytes(KMETER_TEMP_VAL_REG, read_buf, 4)) {
59 ESP_LOGW(TAG,
"Error reading temperature.");
61 int32_t temp =
encode_uint32(read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
62 float temp_f = temp / 100.0;
63 ESP_LOGV(TAG,
"Got temperature=%.2f °C", temp_f);
69 if (!this->
read_bytes(KMETER_INTERNAL_TEMP_VAL_REG, read_buf, 4)) {
70 ESP_LOGW(TAG,
"Error reading internal temperature.");
73 int32_t internal_temp =
encode_uint32(read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
74 float internal_temp_f = internal_temp / 100.0;
75 ESP_LOGV(TAG,
"Got internal temperature=%.2f °C", internal_temp_f);
const uint32_t COMPONENT_STATE_FAILED
const float DATA
For components that import data from directly connected sensors like DHT.
float get_setup_priority() const override
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
enum esphome::kmeteriso::KMeterISOComponent::ErrorCode NONE
uint32_t component_state_
State of this component.
virtual ErrorCode writev(uint8_t address, WriteBuffer *buffers, size_t cnt)
No error found during execution of method.
const uint32_t COMPONENT_STATE_CONSTRUCTION
void publish_state(float state)
Publish a new state to the front-end.
const uint32_t COMPONENT_STATE_MASK
uint8_t address_
store the address of the device on the bus
I2CBus * bus_
pointer to I2CBus instance
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
sensor::Sensor * internal_temperature_sensor_
sensor::Sensor * temperature_sensor_