From 0d1028be2e3e7a6a639bd5c7029a6a49fb281b99 Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Tue, 7 Jun 2022 23:13:11 +0200 Subject: [PATCH] Cleanup deprecated EntityBase::hash_base() (#3525) Co-authored-by: Maurice Makaay --- esphome/components/binary_sensor/binary_sensor.cpp | 1 - esphome/components/binary_sensor/binary_sensor.h | 2 -- esphome/components/ble_client/sensor/ble_sensor.cpp | 2 -- esphome/components/ble_client/sensor/ble_sensor.h | 1 - esphome/components/ble_client/text_sensor/ble_text_sensor.cpp | 2 -- esphome/components/ble_client/text_sensor/ble_text_sensor.h | 1 - esphome/components/button/button.cpp | 1 - esphome/components/button/button.h | 2 -- esphome/components/climate/climate.cpp | 1 - esphome/components/climate/climate.h | 1 - esphome/components/cover/cover.cpp | 2 -- esphome/components/cover/cover.h | 1 - esphome/components/esp32_camera/esp32_camera.cpp | 1 - esphome/components/esp32_camera/esp32_camera.h | 1 - esphome/components/fan/fan.cpp | 1 - esphome/components/fan/fan.h | 1 - esphome/components/light/light_state.cpp | 1 - esphome/components/light/light_state.h | 2 -- esphome/components/lock/lock.cpp | 1 - esphome/components/lock/lock.h | 2 -- esphome/components/media_player/media_player.cpp | 1 - esphome/components/media_player/media_player.h | 1 - esphome/components/number/number.cpp | 2 -- esphome/components/number/number.h | 2 -- esphome/components/select/select.cpp | 2 -- esphome/components/select/select.h | 2 -- esphome/components/sensor/sensor.cpp | 1 - esphome/components/sensor/sensor.h | 2 -- esphome/components/switch/switch.cpp | 1 - esphome/components/switch/switch.h | 2 -- esphome/components/text_sensor/text_sensor.cpp | 1 - esphome/components/text_sensor/text_sensor.h | 2 -- esphome/core/entity_base.h | 4 +++- 33 files changed, 3 insertions(+), 47 deletions(-) diff --git a/esphome/components/binary_sensor/binary_sensor.cpp b/esphome/components/binary_sensor/binary_sensor.cpp index 02735feaae..07217eebed 100644 --- a/esphome/components/binary_sensor/binary_sensor.cpp +++ b/esphome/components/binary_sensor/binary_sensor.cpp @@ -69,7 +69,6 @@ void BinarySensor::add_filters(const std::vector &filters) { } } bool BinarySensor::has_state() const { return this->has_state_; } -uint32_t BinarySensor::hash_base() { return 1210250844UL; } bool BinarySensor::is_status_binary_sensor() const { return false; } } // namespace binary_sensor diff --git a/esphome/components/binary_sensor/binary_sensor.h b/esphome/components/binary_sensor/binary_sensor.h index b5d1244bce..87d87b8eb4 100644 --- a/esphome/components/binary_sensor/binary_sensor.h +++ b/esphome/components/binary_sensor/binary_sensor.h @@ -76,8 +76,6 @@ class BinarySensor : public EntityBase { virtual std::string device_class(); protected: - uint32_t hash_base() override; - CallbackManager state_callback_{}; optional device_class_{}; ///< Stores the override of the device class Filter *filter_list_{nullptr}; diff --git a/esphome/components/ble_client/sensor/ble_sensor.cpp b/esphome/components/ble_client/sensor/ble_sensor.cpp index f8eee43137..ee5afd3f7b 100644 --- a/esphome/components/ble_client/sensor/ble_sensor.cpp +++ b/esphome/components/ble_client/sensor/ble_sensor.cpp @@ -11,8 +11,6 @@ namespace ble_client { static const char *const TAG = "ble_sensor"; -uint32_t BLESensor::hash_base() { return 343459825UL; } - void BLESensor::loop() {} void BLESensor::dump_config() { diff --git a/esphome/components/ble_client/sensor/ble_sensor.h b/esphome/components/ble_client/sensor/ble_sensor.h index d9f310b575..d3d037572a 100644 --- a/esphome/components/ble_client/sensor/ble_sensor.h +++ b/esphome/components/ble_client/sensor/ble_sensor.h @@ -37,7 +37,6 @@ class BLESensor : public sensor::Sensor, public PollingComponent, public BLEClie uint16_t handle; protected: - uint32_t hash_base() override; float parse_data_(uint8_t *value, uint16_t value_len); optional data_to_value_func_{}; bool notify_; diff --git a/esphome/components/ble_client/text_sensor/ble_text_sensor.cpp b/esphome/components/ble_client/text_sensor/ble_text_sensor.cpp index c4d175faa4..1a71cd6cd8 100644 --- a/esphome/components/ble_client/text_sensor/ble_text_sensor.cpp +++ b/esphome/components/ble_client/text_sensor/ble_text_sensor.cpp @@ -14,8 +14,6 @@ static const char *const TAG = "ble_text_sensor"; static const std::string EMPTY = ""; -uint32_t BLETextSensor::hash_base() { return 193967603UL; } - void BLETextSensor::loop() {} void BLETextSensor::dump_config() { diff --git a/esphome/components/ble_client/text_sensor/ble_text_sensor.h b/esphome/components/ble_client/text_sensor/ble_text_sensor.h index 37537307de..cb34043b46 100644 --- a/esphome/components/ble_client/text_sensor/ble_text_sensor.h +++ b/esphome/components/ble_client/text_sensor/ble_text_sensor.h @@ -35,7 +35,6 @@ class BLETextSensor : public text_sensor::TextSensor, public PollingComponent, p uint16_t handle; protected: - uint32_t hash_base() override; bool notify_; espbt::ESPBTUUID service_uuid_; espbt::ESPBTUUID char_uuid_; diff --git a/esphome/components/button/button.cpp b/esphome/components/button/button.cpp index 0a5c6567bc..3d58780d6d 100644 --- a/esphome/components/button/button.cpp +++ b/esphome/components/button/button.cpp @@ -15,7 +15,6 @@ void Button::press() { this->press_callback_.call(); } void Button::add_on_press_callback(std::function &&callback) { this->press_callback_.add(std::move(callback)); } -uint32_t Button::hash_base() { return 1495763804UL; } void Button::set_device_class(const std::string &device_class) { this->device_class_ = device_class; } std::string Button::get_device_class() { return this->device_class_; } diff --git a/esphome/components/button/button.h b/esphome/components/button/button.h index f60c2a2bc5..398d398cd9 100644 --- a/esphome/components/button/button.h +++ b/esphome/components/button/button.h @@ -47,8 +47,6 @@ class Button : public EntityBase { */ virtual void press_action() = 0; - uint32_t hash_base() override; - CallbackManager press_callback_{}; std::string device_class_{}; }; diff --git a/esphome/components/climate/climate.cpp b/esphome/components/climate/climate.cpp index 65b5ef4eb4..776a54f59d 100644 --- a/esphome/components/climate/climate.cpp +++ b/esphome/components/climate/climate.cpp @@ -419,7 +419,6 @@ void Climate::publish_state() { // Save state this->save_state_(); } -uint32_t Climate::hash_base() { return 3104134496UL; } ClimateTraits Climate::get_traits() { auto traits = this->traits(); diff --git a/esphome/components/climate/climate.h b/esphome/components/climate/climate.h index 852b76686c..d508bb31b0 100644 --- a/esphome/components/climate/climate.h +++ b/esphome/components/climate/climate.h @@ -282,7 +282,6 @@ class Climate : public EntityBase { */ void save_state_(); - uint32_t hash_base() override; void dump_traits_(const char *tag); CallbackManager state_callback_{}; diff --git a/esphome/components/cover/cover.cpp b/esphome/components/cover/cover.cpp index 21f35f14de..3d3abffae2 100644 --- a/esphome/components/cover/cover.cpp +++ b/esphome/components/cover/cover.cpp @@ -33,8 +33,6 @@ const char *cover_operation_to_str(CoverOperation op) { Cover::Cover(const std::string &name) : EntityBase(name), position{COVER_OPEN} {} -uint32_t Cover::hash_base() { return 1727367479UL; } - CoverCall::CoverCall(Cover *parent) : parent_(parent) {} CoverCall &CoverCall::set_command(const char *command) { if (strcasecmp(command, "OPEN") == 0) { diff --git a/esphome/components/cover/cover.h b/esphome/components/cover/cover.h index 1b5d3a8fa1..27a821215a 100644 --- a/esphome/components/cover/cover.h +++ b/esphome/components/cover/cover.h @@ -177,7 +177,6 @@ class Cover : public EntityBase { virtual std::string device_class(); optional restore_state_(); - uint32_t hash_base() override; CallbackManager state_callback_{}; optional device_class_override_{}; diff --git a/esphome/components/esp32_camera/esp32_camera.cpp b/esphome/components/esp32_camera/esp32_camera.cpp index 65b316dc8d..165c00c960 100644 --- a/esphome/components/esp32_camera/esp32_camera.cpp +++ b/esphome/components/esp32_camera/esp32_camera.cpp @@ -322,7 +322,6 @@ void ESP32Camera::update_camera_parameters() { } /* ---------------- Internal methods ---------------- */ -uint32_t ESP32Camera::hash_base() { return 3010542557UL; } bool ESP32Camera::has_requested_image_() const { return this->single_requesters_ || this->stream_requesters_; } bool ESP32Camera::can_return_image_() const { return this->current_image_.use_count() == 1; } void ESP32Camera::framebuffer_task(void *pv) { diff --git a/esphome/components/esp32_camera/esp32_camera.h b/esphome/components/esp32_camera/esp32_camera.h index 8bf73a0fa6..87c5b0ba4a 100644 --- a/esphome/components/esp32_camera/esp32_camera.h +++ b/esphome/components/esp32_camera/esp32_camera.h @@ -151,7 +151,6 @@ class ESP32Camera : public Component, public EntityBase { protected: /* internal methods */ - uint32_t hash_base() override; bool has_requested_image_() const; bool can_return_image_() const; diff --git a/esphome/components/fan/fan.cpp b/esphome/components/fan/fan.cpp index f7c4ab2e11..961ed6142a 100644 --- a/esphome/components/fan/fan.cpp +++ b/esphome/components/fan/fan.cpp @@ -152,7 +152,6 @@ void Fan::dump_traits_(const char *tag, const char *prefix) { if (this->get_traits().supports_direction()) ESP_LOGCONFIG(tag, "%s Direction: YES", prefix); } -uint32_t Fan::hash_base() { return 418001110UL; } } // namespace fan } // namespace esphome diff --git a/esphome/components/fan/fan.h b/esphome/components/fan/fan.h index ef2ecd0f3f..337bb3935a 100644 --- a/esphome/components/fan/fan.h +++ b/esphome/components/fan/fan.h @@ -136,7 +136,6 @@ class Fan : public EntityBase { void save_state_(); void dump_traits_(const char *tag, const char *prefix); - uint32_t hash_base() override; CallbackManager state_callback_{}; ESPPreferenceObject rtc_; diff --git a/esphome/components/light/light_state.cpp b/esphome/components/light/light_state.cpp index dadad38235..00c03eb5f0 100644 --- a/esphome/components/light/light_state.cpp +++ b/esphome/components/light/light_state.cpp @@ -145,7 +145,6 @@ void LightState::loop() { } float LightState::get_setup_priority() const { return setup_priority::HARDWARE - 1.0f; } -uint32_t LightState::hash_base() { return 1114400283; } void LightState::publish_state() { this->remote_values_callback_.call(); } diff --git a/esphome/components/light/light_state.h b/esphome/components/light/light_state.h index 2e523eda5c..2834836c0e 100644 --- a/esphome/components/light/light_state.h +++ b/esphome/components/light/light_state.h @@ -150,8 +150,6 @@ class LightState : public EntityBase, public Component { friend LightCall; friend class AddressableLight; - uint32_t hash_base() override; - /// Internal method to start an effect with the given index void start_effect_(uint32_t effect_index); /// Internal method to get the currently active effect diff --git a/esphome/components/lock/lock.cpp b/esphome/components/lock/lock.cpp index e32ab6d0a6..dbb8a941ad 100644 --- a/esphome/components/lock/lock.cpp +++ b/esphome/components/lock/lock.cpp @@ -57,7 +57,6 @@ void Lock::publish_state(LockState state) { } void Lock::add_on_state_callback(std::function &&callback) { this->state_callback_.add(std::move(callback)); } -uint32_t Lock::hash_base() { return 856245656UL; } void LockCall::perform() { ESP_LOGD(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); diff --git a/esphome/components/lock/lock.h b/esphome/components/lock/lock.h index f11035c03e..52256691f6 100644 --- a/esphome/components/lock/lock.h +++ b/esphome/components/lock/lock.h @@ -167,8 +167,6 @@ class Lock : public EntityBase { */ virtual void control(const LockCall &call) = 0; - uint32_t hash_base() override; - CallbackManager state_callback_{}; Deduplicator publish_dedup_; ESPPreferenceObject rtc_; diff --git a/esphome/components/media_player/media_player.cpp b/esphome/components/media_player/media_player.cpp index 00ad31ab18..b05423c2bd 100644 --- a/esphome/components/media_player/media_player.cpp +++ b/esphome/components/media_player/media_player.cpp @@ -107,7 +107,6 @@ MediaPlayerCall &MediaPlayerCall::set_volume(float volume) { void MediaPlayer::add_on_state_callback(std::function &&callback) { this->state_callback_.add(std::move(callback)); } -uint32_t MediaPlayer::hash_base() { return 1938496157UL; } void MediaPlayer::publish_state() { this->state_callback_.call(); } diff --git a/esphome/components/media_player/media_player.h b/esphome/components/media_player/media_player.h index 9a86874996..12e0b5c17d 100644 --- a/esphome/components/media_player/media_player.h +++ b/esphome/components/media_player/media_player.h @@ -82,7 +82,6 @@ class MediaPlayer : public EntityBase { friend MediaPlayerCall; virtual void control(const MediaPlayerCall &call) = 0; - uint32_t hash_base() override; CallbackManager state_callback_{}; }; diff --git a/esphome/components/number/number.cpp b/esphome/components/number/number.cpp index 03a7cc6ce3..fda4f43e34 100644 --- a/esphome/components/number/number.cpp +++ b/esphome/components/number/number.cpp @@ -17,7 +17,5 @@ void Number::add_on_state_callback(std::function &&callback) { this->state_callback_.add(std::move(callback)); } -uint32_t Number::hash_base() { return 2282307003UL; } - } // namespace number } // namespace esphome diff --git a/esphome/components/number/number.h b/esphome/components/number/number.h index ad058e3a0e..7f360cad7b 100644 --- a/esphome/components/number/number.h +++ b/esphome/components/number/number.h @@ -52,8 +52,6 @@ class Number : public EntityBase { */ virtual void control(float value) = 0; - uint32_t hash_base() override; - CallbackManager state_callback_; bool has_state_{false}; }; diff --git a/esphome/components/select/select.cpp b/esphome/components/select/select.cpp index 35f1cfba46..f4583b4e2e 100644 --- a/esphome/components/select/select.cpp +++ b/esphome/components/select/select.cpp @@ -58,7 +58,5 @@ optional Select::at(size_t index) const { } } -uint32_t Select::hash_base() { return 2812997003UL; } - } // namespace select } // namespace esphome diff --git a/esphome/components/select/select.h b/esphome/components/select/select.h index b11c6404a0..23258d5785 100644 --- a/esphome/components/select/select.h +++ b/esphome/components/select/select.h @@ -65,8 +65,6 @@ class Select : public EntityBase { */ virtual void control(const std::string &value) = 0; - uint32_t hash_base() override; - CallbackManager state_callback_; bool has_state_{false}; }; diff --git a/esphome/components/sensor/sensor.cpp b/esphome/components/sensor/sensor.cpp index 73730f6482..c0869631aa 100644 --- a/esphome/components/sensor/sensor.cpp +++ b/esphome/components/sensor/sensor.cpp @@ -126,7 +126,6 @@ void Sensor::internal_send_state_to_frontend(float state) { this->callback_.call(state); } bool Sensor::has_state() const { return this->has_state_; } -uint32_t Sensor::hash_base() { return 2455723294UL; } } // namespace sensor } // namespace esphome diff --git a/esphome/components/sensor/sensor.h b/esphome/components/sensor/sensor.h index d31fe9d834..f29125ee42 100644 --- a/esphome/components/sensor/sensor.h +++ b/esphome/components/sensor/sensor.h @@ -174,8 +174,6 @@ class Sensor : public EntityBase { */ virtual StateClass state_class(); // NOLINT - uint32_t hash_base() override; - CallbackManager raw_callback_; ///< Storage for raw state callbacks. CallbackManager callback_; ///< Storage for filtered state callbacks. diff --git a/esphome/components/switch/switch.cpp b/esphome/components/switch/switch.cpp index ca36e6feb9..099bd4819b 100644 --- a/esphome/components/switch/switch.cpp +++ b/esphome/components/switch/switch.cpp @@ -43,7 +43,6 @@ void Switch::add_on_state_callback(std::function &&callback) { this->state_callback_.add(std::move(callback)); } void Switch::set_inverted(bool inverted) { this->inverted_ = inverted; } -uint32_t Switch::hash_base() { return 3129890955UL; } bool Switch::is_inverted() const { return this->inverted_; } std::string Switch::get_device_class() { diff --git a/esphome/components/switch/switch.h b/esphome/components/switch/switch.h index dda24e85fa..c521c4024b 100644 --- a/esphome/components/switch/switch.h +++ b/esphome/components/switch/switch.h @@ -107,8 +107,6 @@ class Switch : public EntityBase { */ virtual void write_state(bool state) = 0; - uint32_t hash_base() override; - CallbackManager state_callback_{}; bool inverted_{false}; Deduplicator publish_dedup_; diff --git a/esphome/components/text_sensor/text_sensor.cpp b/esphome/components/text_sensor/text_sensor.cpp index 5d47e7465a..d76ab7e27d 100644 --- a/esphome/components/text_sensor/text_sensor.cpp +++ b/esphome/components/text_sensor/text_sensor.cpp @@ -70,7 +70,6 @@ void TextSensor::internal_send_state_to_frontend(const std::string &state) { std::string TextSensor::unique_id() { return ""; } bool TextSensor::has_state() { return this->has_state_; } -uint32_t TextSensor::hash_base() { return 334300109UL; } } // namespace text_sensor } // namespace esphome diff --git a/esphome/components/text_sensor/text_sensor.h b/esphome/components/text_sensor/text_sensor.h index 4bd77131d7..340f7ff9ed 100644 --- a/esphome/components/text_sensor/text_sensor.h +++ b/esphome/components/text_sensor/text_sensor.h @@ -59,8 +59,6 @@ class TextSensor : public EntityBase { void internal_send_state_to_frontend(const std::string &state); protected: - uint32_t hash_base() override; - CallbackManager raw_callback_; ///< Storage for raw state callbacks. CallbackManager callback_; ///< Storage for filtered state callbacks. diff --git a/esphome/core/entity_base.h b/esphome/core/entity_base.h index c489d71910..a9eedfd07e 100644 --- a/esphome/core/entity_base.h +++ b/esphome/core/entity_base.h @@ -46,7 +46,9 @@ class EntityBase { void set_icon(const std::string &name); protected: - virtual uint32_t hash_base() = 0; + /// The hash_base() function has been deprecated. It is kept in this + /// class for now, to prevent external components from not compiling. + virtual uint32_t hash_base() { return 0L; } void calc_object_id_(); std::string name_;