mirror of
https://github.com/esphome/esphome.git
synced 2024-11-12 18:27:46 +01:00
Bring state_to_string_()
in as a class member.
Under certain circumstances (eg: debug logging not enabled), `ESP_LOGD` will be defined to be null. Consequently, the `state_to_string` function will be defined but not used, causing unused-function warnings. Making it a class member removes these warnings; this is also a more appropriate place for a class-specific conversion function.
This commit is contained in:
parent
8e5d7337c8
commit
c910009b5b
2 changed files with 10 additions and 10 deletions
|
@ -364,28 +364,27 @@ void Rtttl::finish_() {
|
||||||
ESP_LOGD(TAG, "Playback finished");
|
ESP_LOGD(TAG, "Playback finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
static const LogString *state_to_string(State state) {
|
const char *Rtttl::state_to_string_(State state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case STATE_STOPPED:
|
case STATE_STOPPED:
|
||||||
return LOG_STR("STATE_STOPPED");
|
return "STATE_STOPPED";
|
||||||
case STATE_STARTING:
|
case STATE_STARTING:
|
||||||
return LOG_STR("STATE_STARTING");
|
return "STATE_STARTING";
|
||||||
case STATE_RUNNING:
|
case STATE_RUNNING:
|
||||||
return LOG_STR("STATE_RUNNING");
|
return "STATE_RUNNING";
|
||||||
case STATE_STOPPING:
|
case STATE_STOPPING:
|
||||||
return LOG_STR("STATE_STOPPING");
|
return "STATE_STOPPING";
|
||||||
case STATE_INIT:
|
case STATE_INIT:
|
||||||
return LOG_STR("STATE_INIT");
|
return "STATE_INIT";
|
||||||
default:
|
default:
|
||||||
return LOG_STR("UNKNOWN");
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void Rtttl::set_state_(State state) {
|
void Rtttl::set_state_(State state) {
|
||||||
State old_state = this->state_;
|
State old_state = this->state_;
|
||||||
this->state_ = state;
|
this->state_ = state;
|
||||||
ESP_LOGD(TAG, "State changed from %s to %s", LOG_STR_ARG(state_to_string(old_state)),
|
ESP_LOGD(TAG, "State changed from %s to %s", this->state_to_string_(old_state), this->state_to_string_(state));
|
||||||
LOG_STR_ARG(state_to_string(state)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace rtttl
|
} // namespace rtttl
|
||||||
|
|
|
@ -67,6 +67,7 @@ class Rtttl : public Component {
|
||||||
}
|
}
|
||||||
void finish_();
|
void finish_();
|
||||||
void set_state_(State state);
|
void set_state_(State state);
|
||||||
|
const char *state_to_string_(State state);
|
||||||
|
|
||||||
std::string rtttl_{""};
|
std::string rtttl_{""};
|
||||||
size_t position_{0};
|
size_t position_{0};
|
||||||
|
|
Loading…
Reference in a new issue