ESPHome
2026.11.0-dev
Loading...
Searching...
No Matches
esphome
components
mt6701_spi
text_sensor
mt6701_spi_field_status.cpp
Go to the documentation of this file.
1
#include "
mt6701_spi_field_status.h
"
2
#include "
esphome/core/log.h
"
3
#include "
esphome/core/progmem.h
"
4
5
namespace
esphome::mt6701_spi
{
6
7
ESPHOME_LOG_TAG
(TAG,
"mt6701_spi.text_sensor"
);
8
9
// Indexed by Mg[1:0]; 0b11 is reserved in the datasheet
10
PROGMEM_STRING_TABLE
(FieldStatusStrings,
"OK"
,
"TOO_STRONG"
,
"TOO_WEAK"
,
"UNKNOWN"
);
11
12
void
MT6701SPIFieldStatus::update
() {
13
if
(!this->
parent_
->read_encoder())
14
return
;
15
char
text[FieldStatusStrings::MAX_LENGTH + 1];
16
ESPHOME_strncpy_P(text,
17
reinterpret_cast<
ESPHOME_PGM_P
>
(FieldStatusStrings::get_progmem_str(
18
this->
parent_
->get_status() & 0x03, FieldStatusStrings::LAST_INDEX)),
19
sizeof
(text));
20
this->
publish_state
(text);
21
}
22
23
void
MT6701SPIFieldStatus::dump_config
() {
24
LOG_TEXT_SENSOR(
""
,
"MT6701 field status"
,
this
);
25
LOG_UPDATE_INTERVAL(
this
);
26
}
27
28
}
// namespace esphome::mt6701_spi
esphome::Parented< MT6701SPIComponent >::parent_
MT6701SPIComponent * parent_
Definition
helpers.h:2084
esphome::mt6701_spi::MT6701SPIFieldStatus::update
void update() override
Definition
mt6701_spi_field_status.cpp:12
esphome::mt6701_spi::MT6701SPIFieldStatus::dump_config
void dump_config() override
Definition
mt6701_spi_field_status.cpp:23
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition
text_sensor.h:42
log.h
mt6701_spi_field_status.h
esphome::mt6701_spi
Definition
mt6701_spi_binary_sensors.cpp:5
esphome::mt6701_spi::ESPHOME_LOG_TAG
ESPHOME_LOG_TAG(TAG, "mt6701_spi.binary_sensor")
esphome::mt6701_spi::PROGMEM_STRING_TABLE
PROGMEM_STRING_TABLE(FieldStatusStrings, "OK", "TOO_STRONG", "TOO_WEAK", "UNKNOWN")
progmem.h
Generated by
1.12.0