mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Suppress excessive warnings about deprecated Fan interfaces (#2270)
This commit is contained in:
parent
3aa107142b
commit
e18dfdd656
6 changed files with 20 additions and 4 deletions
|
@ -214,6 +214,9 @@ void APIConnection::cover_command(const CoverCommandRequest &msg) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FAN
|
#ifdef USE_FAN
|
||||||
|
// Shut-up about usage of deprecated speed_level_to_enum/speed_enum_to_level functions for a bit.
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
bool APIConnection::send_fan_state(fan::FanState *fan) {
|
bool APIConnection::send_fan_state(fan::FanState *fan) {
|
||||||
if (!this->state_subscription_)
|
if (!this->state_subscription_)
|
||||||
return false;
|
return false;
|
||||||
|
@ -262,13 +265,13 @@ void APIConnection::fan_command(const FanCommandRequest &msg) {
|
||||||
// Prefer level
|
// Prefer level
|
||||||
call.set_speed(msg.speed_level);
|
call.set_speed(msg.speed_level);
|
||||||
} else if (msg.has_speed) {
|
} 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()));
|
call.set_speed(fan::speed_enum_to_level(static_cast<fan::FanSpeed>(msg.speed), traits.supported_speed_count()));
|
||||||
}
|
}
|
||||||
if (msg.has_direction)
|
if (msg.has_direction)
|
||||||
call.set_direction(static_cast<fan::FanDirection>(msg.direction));
|
call.set_direction(static_cast<fan::FanDirection>(msg.direction));
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_LIGHT
|
#ifdef USE_LIGHT
|
||||||
|
|
|
@ -4,14 +4,15 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace fan {
|
namespace fan {
|
||||||
|
|
||||||
// NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations)
|
// This whole file is deprecated, don't warn about usage of deprecated types in here.
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
||||||
FanSpeed speed_level_to_enum(int speed_level, int supported_speed_levels) {
|
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 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);
|
const auto legacy_level = clamp<int>(static_cast<int>(ceilf(speed_ratio * 3)), 1, 3);
|
||||||
return static_cast<FanSpeed>(legacy_level - 1); // NOLINT(clang-diagnostic-deprecated-declarations)
|
return static_cast<FanSpeed>(legacy_level - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations)
|
|
||||||
int speed_enum_to_level(FanSpeed speed, int supported_speed_levels) {
|
int speed_enum_to_level(FanSpeed speed, int supported_speed_levels) {
|
||||||
const auto enum_level = static_cast<int>(speed) + 1;
|
const auto enum_level = static_cast<int>(speed) + 1;
|
||||||
const auto speed_level = roundf(enum_level / 3.0f * supported_speed_levels);
|
const auto speed_level = roundf(enum_level / 3.0f * supported_speed_levels);
|
||||||
|
|
|
@ -4,8 +4,16 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace fan {
|
namespace fan {
|
||||||
|
|
||||||
|
// Shut-up about usage of deprecated FanSpeed for a bit.
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
||||||
|
ESPDEPRECATED("FanSpeed and speed_level_to_enum() are deprecated.", "2021.9")
|
||||||
FanSpeed speed_level_to_enum(int speed_level, int supported_speed_levels);
|
FanSpeed speed_level_to_enum(int speed_level, int supported_speed_levels);
|
||||||
|
ESPDEPRECATED("FanSpeed and speed_enum_to_level() are deprecated.", "2021.9")
|
||||||
int speed_enum_to_level(FanSpeed speed, int supported_speed_levels);
|
int speed_enum_to_level(FanSpeed speed, int supported_speed_levels);
|
||||||
|
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
} // namespace fan
|
} // namespace fan
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -67,6 +67,8 @@ void FanStateCall::perform() const {
|
||||||
this->state_->state_callback_.call();
|
this->state_->state_callback_.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This whole method is deprecated, don't warn about usage of deprecated methods inside of it.
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
FanStateCall &FanStateCall::set_speed(const char *legacy_speed) {
|
FanStateCall &FanStateCall::set_speed(const char *legacy_speed) {
|
||||||
const auto supported_speed_count = this->state_->get_traits().supported_speed_count();
|
const auto supported_speed_count = this->state_->get_traits().supported_speed_count();
|
||||||
if (strcasecmp(legacy_speed, "low") == 0) {
|
if (strcasecmp(legacy_speed, "low") == 0) {
|
||||||
|
|
|
@ -100,6 +100,7 @@ bool MQTTFanComponent::publish_state() {
|
||||||
auto traits = this->state_->get_traits();
|
auto traits = this->state_->get_traits();
|
||||||
if (traits.supports_speed()) {
|
if (traits.supports_speed()) {
|
||||||
const char *payload;
|
const char *payload;
|
||||||
|
// NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations)
|
||||||
switch (fan::speed_level_to_enum(this->state_->speed, traits.supported_speed_count())) {
|
switch (fan::speed_level_to_enum(this->state_->speed, traits.supported_speed_count())) {
|
||||||
case FAN_SPEED_LOW: { // NOLINT(clang-diagnostic-deprecated-declarations)
|
case FAN_SPEED_LOW: { // NOLINT(clang-diagnostic-deprecated-declarations)
|
||||||
payload = "low";
|
payload = "low";
|
||||||
|
|
|
@ -397,6 +397,7 @@ std::string WebServer::fan_json(fan::FanState *obj) {
|
||||||
const auto traits = obj->get_traits();
|
const auto traits = obj->get_traits();
|
||||||
if (traits.supports_speed()) {
|
if (traits.supports_speed()) {
|
||||||
root["speed_level"] = obj->speed;
|
root["speed_level"] = obj->speed;
|
||||||
|
// NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations)
|
||||||
switch (fan::speed_level_to_enum(obj->speed, traits.supported_speed_count())) {
|
switch (fan::speed_level_to_enum(obj->speed, traits.supported_speed_count())) {
|
||||||
case fan::FAN_SPEED_LOW: // NOLINT(clang-diagnostic-deprecated-declarations)
|
case fan::FAN_SPEED_LOW: // NOLINT(clang-diagnostic-deprecated-declarations)
|
||||||
root["speed"] = "low";
|
root["speed"] = "low";
|
||||||
|
|
Loading…
Reference in a new issue