8PROGMEM_STRING_TABLE(EzoCommandTypeStrings,
"EZO_READ",
"EZO_LED",
"EZO_DEVICE_INFORMATION",
"EZO_SLOPE",
9 "EZO_CALIBRATION",
"EZO_SLEEP",
"EZO_I2C",
"EZO_T",
"EZO_CUSTOM");
14 LOG_SENSOR(
"",
"EZO",
this);
16 LOG_UPDATE_INTERVAL(
this);
23 this->commands_.size() > 1) {
34 auto ezo_command = make_unique<EzoCommand>();
35 ezo_command->command =
"R";
37 ezo_command->delay_ms = 900;
39 auto it = this->commands_.begin();
41 this->commands_.insert(it, std::move(ezo_command));
58 const uint8_t *data =
reinterpret_cast<const uint8_t *
>(to_run->
command.c_str());
59 ESP_LOGVV(TAG,
"Sending command \"%s\"", data);
85 ESP_LOGE(TAG,
"read error");
94 ESP_LOGE(TAG,
"device returned a syntax error");
99 ESP_LOGE(TAG,
"device returned no data");
102 ESP_LOGE(TAG,
"device returned an unknown response: %d", buf[0]);
106 ESP_LOGV(TAG,
"Received buffer \"%s\" for command type %s", &buf[1],
107 LOG_STR_ARG(EzoCommandTypeStrings::get_log_str(to_run->
command_type, EzoCommandTypeStrings::LAST_INDEX)));
110 std::string payload =
reinterpret_cast<char *
>(&buf[1]);
111 if (!payload.empty()) {
112 auto start_location = payload.find(
',');
116 if (start_location != std::string::npos) {
117 payload.erase(start_location);
120 if (!
val.has_value()) {
121 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
131 if (start_location != std::string::npos) {
136 if (start_location != std::string::npos) {
141 if (start_location != std::string::npos) {
146 if (start_location != std::string::npos) {
147 this->
t_callback_.call(payload.substr(start_location + 1));
162 auto ezo_command = make_unique<EzoCommand>();
163 ezo_command->command = command;
164 ezo_command->command_type = command_type;
165 ezo_command->delay_ms = delay_ms;
166 this->
commands_.push_back(std::move(ezo_command));
172 ESPHOME_snprintf_P(payload,
sizeof(payload), ESPHOME_PSTR(
"Cal,%s,%0.2f"),
173 LOG_STR_ARG(EzoCalibrationTypeStrings::get_log_str(
type, EzoCalibrationTypeStrings::LAST_INDEX)),
182 ESPHOME_snprintf_P(payload,
sizeof(payload), ESPHOME_PSTR(
"I2C,%u"),
address);
186 ESP_LOGE(TAG,
"Invalid I2C address");
203 ESPHOME_snprintf_P(payload,
sizeof(payload), ESPHOME_PSTR(
"T,%0.2f"),
value);
226 ESPHOME_snprintf_P(payload,
sizeof(payload), ESPHOME_PSTR(
"Cal,%0.2f"),
value);
void set_led_state(bool on)
void set_address(uint8_t address)
CallbackManager< void(std::string)> calibration_callback_
void set_calibration_point_mid(float value)
void set_calibration_point_high(float value)
void set_calibration_point_low(float value)
CallbackManager< void(bool)> led_callback_
void set_calibration_generic(float value)
void set_tempcomp_value(float temp)
void get_device_information()
CallbackManager< void(std::string)> device_infomation_callback_
CallbackManager< void(std::string)> t_callback_
void set_calibration_point_(EzoCalibrationType type, float value)
CallbackManager< void(std::string)> slope_callback_
std::deque< std::unique_ptr< EzoCommand > > commands_
void send_custom(const std::string &to_send)
CallbackManager< void(std::string)> custom_callback_
void add_command_(const char *command, EzoCommandType command_type, uint16_t delay_ms=300)
void dump_config() override
EzoCommandType command_type
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
optional< std::array< uint8_t, N > > read_bytes_raw()
uint8_t address_
store the address of the device on the bus
void publish_state(float state)
Publish a new state to the front-end.
PROGMEM_STRING_TABLE(EzoCommandTypeStrings, "EZO_READ", "EZO_LED", "EZO_DEVICE_INFORMATION", "EZO_SLOPE", "EZO_CALIBRATION", "EZO_SLEEP", "EZO_I2C", "EZO_T", "EZO_CUSTOM")
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
uint32_t IRAM_ATTR HOT millis()