Drop deprecated entity property base methods (#4539)

This commit is contained in:
Oxan van Leeuwen 2023-03-09 01:08:45 +01:00 committed by GitHub
parent afc1c83af4
commit ba1416cc0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 7 additions and 68 deletions

View file

@ -41,16 +41,13 @@ void BinarySensor::send_state_internal(bool state, bool is_initial) {
this->state_callback_.call(state); this->state_callback_.call(state);
} }
} }
std::string BinarySensor::device_class() { return ""; }
BinarySensor::BinarySensor() : state(false) {} BinarySensor::BinarySensor() : state(false) {}
void BinarySensor::set_device_class(const std::string &device_class) { this->device_class_ = device_class; } void BinarySensor::set_device_class(const std::string &device_class) { this->device_class_ = device_class; }
std::string BinarySensor::get_device_class() { std::string BinarySensor::get_device_class() {
if (this->device_class_.has_value()) if (this->device_class_.has_value())
return *this->device_class_; return *this->device_class_;
#pragma GCC diagnostic push return "";
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->device_class();
#pragma GCC diagnostic pop
} }
void BinarySensor::add_filter(Filter *filter) { void BinarySensor::add_filter(Filter *filter) {
filter->parent_ = this; filter->parent_ = this;

View file

@ -80,14 +80,6 @@ class BinarySensor : public EntityBase {
virtual bool is_status_binary_sensor() const; virtual bool is_status_binary_sensor() const;
// ========== OVERRIDE METHODS ==========
// (You'll only need this when creating your own custom binary sensor)
/** Override this to set the default device class.
*
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
*/
virtual std::string device_class();
protected: protected:
CallbackManager<void(bool)> state_callback_{}; CallbackManager<void(bool)> state_callback_{};
optional<std::string> device_class_{}; ///< Stores the override of the device class optional<std::string> device_class_{}; ///< Stores the override of the device class

View file

@ -208,14 +208,10 @@ Cover::Cover() : Cover("") {}
std::string Cover::get_device_class() { std::string Cover::get_device_class() {
if (this->device_class_override_.has_value()) if (this->device_class_override_.has_value())
return *this->device_class_override_; return *this->device_class_override_;
#pragma GCC diagnostic push return "";
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->device_class();
#pragma GCC diagnostic pop
} }
bool Cover::is_fully_open() const { return this->position == COVER_OPEN; } bool Cover::is_fully_open() const { return this->position == COVER_OPEN; }
bool Cover::is_fully_closed() const { return this->position == COVER_CLOSED; } bool Cover::is_fully_closed() const { return this->position == COVER_CLOSED; }
std::string Cover::device_class() { return ""; }
CoverCall CoverRestoreState::to_call(Cover *cover) { CoverCall CoverRestoreState::to_call(Cover *cover) {
auto call = cover->make_call(); auto call = cover->make_call();

View file

@ -170,12 +170,6 @@ class Cover : public EntityBase {
virtual void control(const CoverCall &call) = 0; virtual void control(const CoverCall &call) = 0;
/** Override this to set the default device class.
*
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
*/
virtual std::string device_class();
optional<CoverRestoreState> restore_state_(); optional<CoverRestoreState> restore_state_();
CallbackManager<void()> state_callback_{}; CallbackManager<void()> state_callback_{};

View file

@ -26,48 +26,32 @@ Sensor::Sensor() : Sensor("") {}
std::string Sensor::get_unit_of_measurement() { std::string Sensor::get_unit_of_measurement() {
if (this->unit_of_measurement_.has_value()) if (this->unit_of_measurement_.has_value())
return *this->unit_of_measurement_; return *this->unit_of_measurement_;
#pragma GCC diagnostic push return "";
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->unit_of_measurement();
#pragma GCC diagnostic pop
} }
void Sensor::set_unit_of_measurement(const std::string &unit_of_measurement) { void Sensor::set_unit_of_measurement(const std::string &unit_of_measurement) {
this->unit_of_measurement_ = unit_of_measurement; this->unit_of_measurement_ = unit_of_measurement;
} }
std::string Sensor::unit_of_measurement() { return ""; }
int8_t Sensor::get_accuracy_decimals() { int8_t Sensor::get_accuracy_decimals() {
if (this->accuracy_decimals_.has_value()) if (this->accuracy_decimals_.has_value())
return *this->accuracy_decimals_; return *this->accuracy_decimals_;
#pragma GCC diagnostic push return 0;
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->accuracy_decimals();
#pragma GCC diagnostic pop
} }
void Sensor::set_accuracy_decimals(int8_t accuracy_decimals) { this->accuracy_decimals_ = accuracy_decimals; } void Sensor::set_accuracy_decimals(int8_t accuracy_decimals) { this->accuracy_decimals_ = accuracy_decimals; }
int8_t Sensor::accuracy_decimals() { return 0; }
std::string Sensor::get_device_class() { std::string Sensor::get_device_class() {
if (this->device_class_.has_value()) if (this->device_class_.has_value())
return *this->device_class_; return *this->device_class_;
#pragma GCC diagnostic push return "";
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->device_class();
#pragma GCC diagnostic pop
} }
void Sensor::set_device_class(const std::string &device_class) { this->device_class_ = device_class; } void Sensor::set_device_class(const std::string &device_class) { this->device_class_ = device_class; }
std::string Sensor::device_class() { return ""; }
void Sensor::set_state_class(StateClass state_class) { this->state_class_ = state_class; } void Sensor::set_state_class(StateClass state_class) { this->state_class_ = state_class; }
StateClass Sensor::get_state_class() { StateClass Sensor::get_state_class() {
if (this->state_class_.has_value()) if (this->state_class_.has_value())
return *this->state_class_; return *this->state_class_;
#pragma GCC diagnostic push return StateClass::STATE_CLASS_NONE;
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->state_class();
#pragma GCC diagnostic pop
} }
StateClass Sensor::state_class() { return StateClass::STATE_CLASS_NONE; }
void Sensor::publish_state(float state) { void Sensor::publish_state(float state) {
this->raw_state = state; this->raw_state = state;

View file

@ -159,30 +159,6 @@ class Sensor : public EntityBase {
void internal_send_state_to_frontend(float state); void internal_send_state_to_frontend(float state);
protected: protected:
/** Override this to set the default unit of measurement.
*
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
*/
virtual std::string unit_of_measurement(); // NOLINT
/** Override this to set the default accuracy in decimals.
*
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
*/
virtual int8_t accuracy_decimals(); // NOLINT
/** Override this to set the default device class.
*
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
*/
virtual std::string device_class(); // NOLINT
/** Override this to set the default state class.
*
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
*/
virtual StateClass state_class(); // NOLINT
CallbackManager<void(float)> raw_callback_; ///< Storage for raw state callbacks. CallbackManager<void(float)> raw_callback_; ///< Storage for raw state callbacks.
CallbackManager<void(float)> callback_; ///< Storage for filtered state callbacks. CallbackManager<void(float)> callback_; ///< Storage for filtered state callbacks.