mirror of
https://github.com/esphome/esphome.git
synced 2026-03-24 15:06:08 +08:00
[sensor] Narrow pragma scope to only functions accessing deprecated raw_state
Scope the deprecation warning suppression to just the constructor and publish_state() instead of the entire file, so unrelated deprecation warnings aren't accidentally hidden.
This commit is contained in:
@@ -4,10 +4,6 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
|
||||
// Suppress deprecation warnings for internal access to .state and .raw_state
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
namespace esphome::sensor {
|
||||
|
||||
static const char *const TAG = "sensor";
|
||||
@@ -44,7 +40,10 @@ const LogString *state_class_to_string(StateClass state_class) {
|
||||
return StateClassStrings::get_log_str(static_cast<uint8_t>(state_class), 0);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
Sensor::Sensor() : state(NAN), raw_state(NAN) {}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
int8_t Sensor::get_accuracy_decimals() {
|
||||
if (this->sensor_flags_.has_accuracy_override)
|
||||
@@ -66,6 +65,8 @@ StateClass Sensor::get_state_class() {
|
||||
return StateClass::STATE_CLASS_NONE;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
void Sensor::publish_state(float state) {
|
||||
this->raw_state = state;
|
||||
#ifdef USE_SENSOR_FILTER
|
||||
@@ -84,6 +85,7 @@ void Sensor::publish_state(float state) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#ifdef USE_SENSOR_FILTER
|
||||
void Sensor::add_filter(Filter *filter) {
|
||||
@@ -128,6 +130,4 @@ void Sensor::internal_send_state_to_frontend(float state) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
} // namespace esphome::sensor
|
||||
|
||||
Reference in New Issue
Block a user