11 if (
const uint8_t *packet = this->
reader_.
feed(c)) {
25 uint8_t received_checksum = packet[
PACKET_SIZE - 1];
26 if (calculated_checksum != received_checksum) {
27 ESP_LOGW(TAG,
"WTS01 Checksum doesn't match: 0x%02X != 0x%02X", received_checksum, calculated_checksum);
32 const uint8_t
raw = packet[6];
35 const bool negative = (
raw & 0x80) != 0;
36 const uint8_t magnitude =
raw & 0x7F;
38 const float decimal =
static_cast<float>(packet[7]) / 100.0f;
40 float temperature =
static_cast<float>(magnitude) + decimal;
46 ESP_LOGV(TAG,
"Received new temperature: %.2f°C",
temperature);
const uint8_t * feed(uint8_t c)
Feed one byte; returns the completed frame, header included, valid until the next call,...
void publish_state(float state)
Publish a new state to the front-end.
bool read_available(F &&on_byte)
Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
void process_packet_(const uint8_t *packet)
FrameReader< PACKET_SIZE, 0x55, 0x01, 0x01, 0x04 > reader_
void dump_config() override
ESPHOME_LOG_TAG(TAG, "wts01")
constexpr uint8_t PACKET_SIZE
constexpr uint8_t sum_bytes(const uint8_t *data, size_t len, uint8_t sum=0)
Add up the bytes of data with size len, truncated to 8 bits: the checksum many serial and IR protocol...