Merge branch 'moment_api_misuse_fix' into integration

This commit is contained in:
J. Nick Koston
2025-11-30 22:02:10 -06:00
10 changed files with 45 additions and 21 deletions
@@ -25,7 +25,8 @@ void ADE7953::setup() {
this->ade_write_8(PGA_V_8, pga_v_);
this->ade_write_8(PGA_IA_8, pga_ia_);
this->ade_write_8(PGA_IB_8, pga_ib_);
this->ade_write_32(AVGAIN_32, vgain_);
this->ade_write_32(AVGAIN_32, avgain_);
this->ade_write_32(BVGAIN_32, bvgain_);
this->ade_write_32(AIGAIN_32, aigain_);
this->ade_write_32(BIGAIN_32, bigain_);
this->ade_write_32(AWGAIN_32, awgain_);
@@ -34,7 +35,8 @@ void ADE7953::setup() {
this->ade_read_8(PGA_V_8, &pga_v_);
this->ade_read_8(PGA_IA_8, &pga_ia_);
this->ade_read_8(PGA_IB_8, &pga_ib_);
this->ade_read_32(AVGAIN_32, &vgain_);
this->ade_read_32(AVGAIN_32, &avgain_);
this->ade_read_32(BVGAIN_32, &bvgain_);
this->ade_read_32(AIGAIN_32, &aigain_);
this->ade_read_32(BIGAIN_32, &bigain_);
this->ade_read_32(AWGAIN_32, &awgain_);
@@ -63,13 +65,14 @@ void ADE7953::dump_config() {
" PGA_V_8: 0x%X\n"
" PGA_IA_8: 0x%X\n"
" PGA_IB_8: 0x%X\n"
" VGAIN_32: 0x%08jX\n"
" AVGAIN_32: 0x%08jX\n"
" BVGAIN_32: 0x%08jX\n"
" AIGAIN_32: 0x%08jX\n"
" BIGAIN_32: 0x%08jX\n"
" AWGAIN_32: 0x%08jX\n"
" BWGAIN_32: 0x%08jX",
this->use_acc_energy_regs_, pga_v_, pga_ia_, pga_ib_, (uintmax_t) vgain_, (uintmax_t) aigain_,
(uintmax_t) bigain_, (uintmax_t) awgain_, (uintmax_t) bwgain_);
this->use_acc_energy_regs_, pga_v_, pga_ia_, pga_ib_, (uintmax_t) avgain_, (uintmax_t) bvgain_,
(uintmax_t) aigain_, (uintmax_t) bigain_, (uintmax_t) awgain_, (uintmax_t) bwgain_);
}
#define ADE_PUBLISH_(name, val, factor) \
@@ -46,7 +46,12 @@ class ADE7953 : public PollingComponent, public sensor::Sensor {
void set_pga_ib(uint8_t pga_ib) { pga_ib_ = pga_ib; }
// Set input gains
void set_vgain(uint32_t vgain) { vgain_ = vgain; }
void set_vgain(uint32_t vgain) {
// Datasheet says: "to avoid discrepancies in other registers,
// if AVGAIN is set then BVGAIN should be set to the same value."
avgain_ = vgain;
bvgain_ = vgain;
}
void set_aigain(uint32_t aigain) { aigain_ = aigain; }
void set_bigain(uint32_t bigain) { bigain_ = bigain; }
void set_awgain(uint32_t awgain) { awgain_ = awgain; }
@@ -100,7 +105,8 @@ class ADE7953 : public PollingComponent, public sensor::Sensor {
uint8_t pga_v_;
uint8_t pga_ia_;
uint8_t pga_ib_;
uint32_t vgain_;
uint32_t avgain_;
uint32_t bvgain_;
uint32_t aigain_;
uint32_t bigain_;
uint32_t awgain_;
@@ -33,7 +33,7 @@ class DemoAlarmControlPanel : public AlarmControlPanel, public Component {
case ACP_STATE_ARMED_AWAY:
if (this->get_requires_code_to_arm() && call.get_code().has_value()) {
if (call.get_code().value() != "1234") {
this->status_momentary_error("Invalid code", 5000);
this->status_momentary_error("invalid_code", 5000);
return;
}
}
@@ -42,7 +42,7 @@ class DemoAlarmControlPanel : public AlarmControlPanel, public Component {
case ACP_STATE_DISARMED:
if (this->get_requires_code() && call.get_code().has_value()) {
if (call.get_code().value() != "1234") {
this->status_momentary_error("Invalid code", 5000);
this->status_momentary_error("invalid_code", 5000);
return;
}
}
+2 -2
View File
@@ -225,7 +225,7 @@ bool ES8388::set_dac_output(DacOutputLine line) {
optional<DacOutputLine> ES8388::get_dac_power() {
uint8_t dac_power;
if (!this->read_byte(ES8388_DACPOWER, &dac_power)) {
this->status_momentary_warning("Failed to read ES8388_DACPOWER");
this->status_momentary_warning("dacpower_read");
return {};
}
switch (dac_power) {
@@ -268,7 +268,7 @@ bool ES8388::set_adc_input_mic(AdcInputMicLine line) {
optional<AdcInputMicLine> ES8388::get_mic_input() {
uint8_t mic_input;
if (!this->read_byte(ES8388_ADCCONTROL2, &mic_input)) {
this->status_momentary_warning("Failed to read ES8388_ADCCONTROL2");
this->status_momentary_warning("adccontrol2_read");
return {};
}
switch (mic_input) {
@@ -398,7 +398,7 @@ error:
this->backend_->abort();
}
this->status_momentary_error("onerror", 5000);
this->status_momentary_error("err", 5000);
#ifdef USE_OTA_STATE_LISTENER
this->notify_state_(ota::OTA_ERROR, 0.0f, static_cast<uint8_t>(error_code));
#endif
@@ -301,8 +301,7 @@ void MicroWakeWord::loop() {
// uses floating point operations.
if (!FrontendPopulateState(&this->frontend_config_, &this->frontend_state_,
this->microphone_source_->get_audio_stream_info().get_sample_rate())) {
this->status_momentary_error(
"Failed to allocate buffers for spectrogram feature processor, attempting again in 1 second", 1000);
this->status_momentary_error("frontend_alloc", 1000);
return;
}
@@ -311,7 +310,7 @@ void MicroWakeWord::loop() {
if (this->inference_task_handle_ == nullptr) {
FrontendFreeStateContents(&this->frontend_state_); // Deallocate frontend state
this->status_momentary_error("Task failed to start, attempting again in 1 second", 1000);
this->status_momentary_error("task_start", 1000);
}
}
break;
@@ -167,7 +167,7 @@ bool SoundLevelComponent::start_() {
this->audio_buffer_ = audio::AudioSourceTransferBuffer::create(
this->microphone_source_->get_audio_stream_info().ms_to_bytes(AUDIO_BUFFER_DURATION_MS));
if (this->audio_buffer_ == nullptr) {
this->status_momentary_error("Failed to allocate transfer buffer", 15000);
this->status_momentary_error("transfer_buffer", 15000);
return false;
}
@@ -176,7 +176,7 @@ bool SoundLevelComponent::start_() {
std::shared_ptr<RingBuffer> temp_ring_buffer =
RingBuffer::create(this->microphone_source_->get_audio_stream_info().ms_to_bytes(RING_BUFFER_DURATION_MS));
if (temp_ring_buffer.use_count() == 0) {
this->status_momentary_error("Failed to allocate ring buffer", 15000);
this->status_momentary_error("ring_buffer", 15000);
this->stop_();
return false;
} else {
@@ -1692,6 +1692,7 @@ std::string WebServer::event_state_json_generator(WebServer *web_server, void *s
auto *event = static_cast<event::Event *>(source);
return web_server->event_json(event, get_event_type(event), DETAIL_STATE);
}
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
std::string WebServer::event_all_json_generator(WebServer *web_server, void *source) {
auto *event = static_cast<event::Event *>(source);
return web_server->event_json(event, get_event_type(event), DETAIL_ALL);
@@ -1715,6 +1716,7 @@ std::string WebServer::event_json(event::Event *obj, const std::string &event_ty
return builder.serialize();
}
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
#endif
#ifdef USE_UPDATE
+2 -2
View File
@@ -369,11 +369,11 @@ void Component::status_clear_error() {
this->component_state_ &= ~STATUS_LED_ERROR;
ESP_LOGE(TAG, "%s cleared Error flag", LOG_STR_ARG(this->get_component_log_str()));
}
void Component::status_momentary_warning(const std::string &name, uint32_t length) {
void Component::status_momentary_warning(const char *name, uint32_t length) {
this->status_set_warning();
this->set_timeout(name, length, [this]() { this->status_clear_warning(); });
}
void Component::status_momentary_error(const std::string &name, uint32_t length) {
void Component::status_momentary_error(const char *name, uint32_t length) {
this->status_set_error();
this->set_timeout(name, length, [this]() { this->status_clear_error(); });
}
+16 -2
View File
@@ -241,9 +241,23 @@ class Component {
void status_clear_error();
void status_momentary_warning(const std::string &name, uint32_t length = 5000);
/** Set warning status flag and automatically clear it after a timeout.
*
* @param name Identifier for the timeout (used to cancel/replace existing timeouts with the same name).
* Must be a static string literal (stored in flash/rodata), not a temporary or dynamic string.
* This is NOT a message to display - use status_set_warning() with a message if logging is needed.
* @param length Duration in milliseconds before the warning is automatically cleared.
*/
void status_momentary_warning(const char *name, uint32_t length = 5000);
void status_momentary_error(const std::string &name, uint32_t length = 5000);
/** Set error status flag and automatically clear it after a timeout.
*
* @param name Identifier for the timeout (used to cancel/replace existing timeouts with the same name).
* Must be a static string literal (stored in flash/rodata), not a temporary or dynamic string.
* This is NOT a message to display - use status_set_error() with a message if logging is needed.
* @param length Duration in milliseconds before the error is automatically cleared.
*/
void status_momentary_error(const char *name, uint32_t length = 5000);
bool has_overridden_loop() const;