mirror of
https://github.com/esphome/esphome.git
synced 2026-09-20 03:28:41 +00:00
Remove deprecated offsetof hack from NumberTraits
NumberTraits no longer needs get_device_class_ref() or get_unit_of_measurement_ref() — no internal callers exist. Callers should use number->get_device_class_ref() directly. Eliminates offsetof warning on non-standard-layout type.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include "number.h"
|
||||
#include <cstddef>
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/controller_registry.h"
|
||||
#include "esphome/core/log.h"
|
||||
@@ -20,18 +19,6 @@ void log_number(const char *tag, const char *prefix, const char *type, Number *o
|
||||
LOG_ENTITY_DEVICE_CLASS(tag, prefix, *obj);
|
||||
}
|
||||
|
||||
// Deprecated backward-compat: delegate to parent Number's EntityBase methods
|
||||
StringRef NumberTraits::get_device_class_ref() const {
|
||||
const auto *number =
|
||||
reinterpret_cast<const Number *>(reinterpret_cast<const uint8_t *>(this) - offsetof(Number, traits));
|
||||
return number->get_device_class_ref();
|
||||
}
|
||||
StringRef NumberTraits::get_unit_of_measurement_ref() const {
|
||||
const auto *number =
|
||||
reinterpret_cast<const Number *>(reinterpret_cast<const uint8_t *>(this) - offsetof(Number, traits));
|
||||
return number->get_unit_of_measurement_ref();
|
||||
}
|
||||
|
||||
void Number::publish_state(float state) {
|
||||
this->set_has_state(true);
|
||||
this->state = state;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/entity_base.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
|
||||
namespace esphome::number {
|
||||
|
||||
@@ -27,16 +27,6 @@ class NumberTraits {
|
||||
void set_mode(NumberMode mode) { this->mode_ = mode; }
|
||||
NumberMode get_mode() const { return this->mode_; }
|
||||
|
||||
// Deprecated: use Number::get_device_class_ref() instead.
|
||||
// Delegates to parent Number's EntityBase via offsetof.
|
||||
ESPDEPRECATED("Use number->get_device_class_ref() instead. Removed in 2027.2.0", "2026.8.0")
|
||||
StringRef get_device_class_ref() const;
|
||||
|
||||
// Deprecated: use Number::get_unit_of_measurement_ref() instead.
|
||||
// Delegates to parent Number's EntityBase via offsetof.
|
||||
ESPDEPRECATED("Use number->get_unit_of_measurement_ref() instead. Removed in 2027.2.0", "2026.8.0")
|
||||
StringRef get_unit_of_measurement_ref() const;
|
||||
|
||||
protected:
|
||||
float min_value_ = NAN;
|
||||
float max_value_ = NAN;
|
||||
|
||||
Reference in New Issue
Block a user