Add deprecated attribute to some deprecated types/methods (#2185)

This commit is contained in:
Oxan van Leeuwen 2021-08-23 20:48:12 +02:00 committed by GitHub
parent 71237e2f76
commit 1c1ad32610
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 10 deletions

View file

@ -289,6 +289,7 @@ void APIConnection::fan_command(const FanCommandRequest &msg) {
// Prefer level
call.set_speed(msg.speed_level);
} else if (msg.has_speed) {
// NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations)
call.set_speed(fan::speed_enum_to_level(static_cast<fan::FanSpeed>(msg.speed), traits.supported_speed_count()));
}
if (msg.has_direction)

View file

@ -125,16 +125,19 @@ class Cover : public Nameable {
*
* This is a legacy method and may be removed later, please use `.make_call()` instead.
*/
ESPDEPRECATED("open() is deprecated, use make_call().set_command_open() instead.", "2021.9")
void open();
/** Close the cover.
*
* This is a legacy method and may be removed later, please use `.make_call()` instead.
*/
ESPDEPRECATED("close() is deprecated, use make_call().set_command_close() instead.", "2021.9")
void close();
/** Stop the cover.
*
* This is a legacy method and may be removed later, please use `.make_call()` instead.
*/
ESPDEPRECATED("stop() is deprecated, use make_call().set_command_stop() instead.", "2021.9")
void stop();
void add_on_state_callback(std::function<void()> &&f);

View file

@ -4,12 +4,14 @@
namespace esphome {
namespace fan {
// NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations)
FanSpeed speed_level_to_enum(int speed_level, int supported_speed_levels) {
const auto speed_ratio = static_cast<float>(speed_level) / (supported_speed_levels + 1);
const auto legacy_level = clamp<int>(static_cast<int>(ceilf(speed_ratio * 3)), 1, 3);
return static_cast<FanSpeed>(legacy_level - 1);
return static_cast<FanSpeed>(legacy_level - 1); // NOLINT(clang-diagnostic-deprecated-declarations)
}
// NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations)
int speed_enum_to_level(FanSpeed speed, int supported_speed_levels) {
const auto enum_level = static_cast<int>(speed) + 1;
const auto speed_level = roundf(enum_level / 3.0f * supported_speed_levels);

View file

@ -10,7 +10,7 @@ namespace esphome {
namespace fan {
/// Simple enum to represent the speed of a fan. - DEPRECATED - Will be deleted soon
enum FanSpeed {
enum ESPDEPRECATED("FanSpeed is deprecated.", "2021.9") FanSpeed {
FAN_SPEED_LOW = 0, ///< The fan is running on low speed.
FAN_SPEED_MEDIUM = 1, ///< The fan is running on medium speed.
FAN_SPEED_HIGH = 2 ///< The fan is running on high/full speed.
@ -45,6 +45,7 @@ class FanStateCall {
this->speed_ = speed;
return *this;
}
ESPDEPRECATED("set_speed() with string argument is deprecated, use integer argument instead.", "2021.9")
FanStateCall &set_speed(const char *legacy_speed);
FanStateCall &set_direction(FanDirection direction) {
this->direction_ = direction;

View file

@ -65,7 +65,9 @@ void MQTTFanComponent::setup() {
if (this->state_->get_traits().supports_speed()) {
this->subscribe(this->get_speed_command_topic(), [this](const std::string &topic, const std::string &payload) {
this->state_->make_call().set_speed(payload.c_str()).perform();
this->state_->make_call()
.set_speed(payload.c_str()) // NOLINT(clang-diagnostic-deprecated-declarations)
.perform();
});
}
@ -99,16 +101,16 @@ bool MQTTFanComponent::publish_state() {
if (traits.supports_speed()) {
const char *payload;
switch (fan::speed_level_to_enum(this->state_->speed, traits.supported_speed_count())) {
case FAN_SPEED_LOW: {
case FAN_SPEED_LOW: { // NOLINT(clang-diagnostic-deprecated-declarations)
payload = "low";
break;
}
case FAN_SPEED_MEDIUM: {
case FAN_SPEED_MEDIUM: { // NOLINT(clang-diagnostic-deprecated-declarations)
payload = "medium";
break;
}
default:
case FAN_SPEED_HIGH: {
case FAN_SPEED_HIGH: { // NOLINT(clang-diagnostic-deprecated-declarations)
payload = "high";
break;
}

View file

@ -398,13 +398,13 @@ std::string WebServer::fan_json(fan::FanState *obj) {
if (traits.supports_speed()) {
root["speed_level"] = obj->speed;
switch (fan::speed_level_to_enum(obj->speed, traits.supported_speed_count())) {
case fan::FAN_SPEED_LOW:
case fan::FAN_SPEED_LOW: // NOLINT(clang-diagnostic-deprecated-declarations)
root["speed"] = "low";
break;
case fan::FAN_SPEED_MEDIUM:
case fan::FAN_SPEED_MEDIUM: // NOLINT(clang-diagnostic-deprecated-declarations)
root["speed"] = "medium";
break;
case fan::FAN_SPEED_HIGH:
case fan::FAN_SPEED_HIGH: // NOLINT(clang-diagnostic-deprecated-declarations)
root["speed"] = "high";
break;
}
@ -430,7 +430,7 @@ void WebServer::handle_fan_request(AsyncWebServerRequest *request, const UrlMatc
auto call = obj->turn_on();
if (request->hasParam("speed")) {
String speed = request->getParam("speed")->value();
call.set_speed(speed.c_str());
call.set_speed(speed.c_str()); // NOLINT(clang-diagnostic-deprecated-declarations)
}
if (request->hasParam("speed_level")) {
String speed_level = request->getParam("speed_level")->value();