mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Suppress excessive warnings about deprecated Fan interfaces (#2270)
This commit is contained in:
		
				
					committed by
					
						 Jesse Hills
						Jesse Hills
					
				
			
			
				
	
			
			
			
						parent
						
							1b5f11bbee
						
					
				
				
					commit
					23ead416d5
				
			| @@ -243,6 +243,9 @@ void APIConnection::cover_command(const CoverCommandRequest &msg) { | ||||
| #endif | ||||
|  | ||||
| #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) { | ||||
|   if (!this->state_subscription_) | ||||
|     return false; | ||||
| @@ -291,13 +294,13 @@ 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) | ||||
|     call.set_direction(static_cast<fan::FanDirection>(msg.direction)); | ||||
|   call.perform(); | ||||
| } | ||||
| #pragma GCC diagnostic pop | ||||
| #endif | ||||
|  | ||||
| #ifdef USE_LIGHT | ||||
|   | ||||
| @@ -4,14 +4,15 @@ | ||||
| namespace esphome { | ||||
| 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) { | ||||
|   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);  // 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) { | ||||
|   const auto enum_level = static_cast<int>(speed) + 1; | ||||
|   const auto speed_level = roundf(enum_level / 3.0f * supported_speed_levels); | ||||
|   | ||||
| @@ -4,8 +4,16 @@ | ||||
| namespace esphome { | ||||
| 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); | ||||
| ESPDEPRECATED("FanSpeed and speed_enum_to_level() are deprecated.", "2021.9") | ||||
| int speed_enum_to_level(FanSpeed speed, int supported_speed_levels); | ||||
|  | ||||
| #pragma GCC diagnostic pop | ||||
|  | ||||
| }  // namespace fan | ||||
| }  // namespace esphome | ||||
|   | ||||
| @@ -67,6 +67,8 @@ void FanStateCall::perform() const { | ||||
|   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) { | ||||
|   const auto supported_speed_count = this->state_->get_traits().supported_speed_count(); | ||||
|   if (strcasecmp(legacy_speed, "low") == 0) { | ||||
|   | ||||
| @@ -100,6 +100,7 @@ bool MQTTFanComponent::publish_state() { | ||||
|   auto traits = this->state_->get_traits(); | ||||
|   if (traits.supports_speed()) { | ||||
|     const char *payload; | ||||
|     // NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations) | ||||
|     switch (fan::speed_level_to_enum(this->state_->speed, traits.supported_speed_count())) { | ||||
|       case FAN_SPEED_LOW: {  // NOLINT(clang-diagnostic-deprecated-declarations) | ||||
|         payload = "low"; | ||||
|   | ||||
| @@ -397,6 +397,7 @@ std::string WebServer::fan_json(fan::FanState *obj) { | ||||
|     const auto traits = obj->get_traits(); | ||||
|     if (traits.supports_speed()) { | ||||
|       root["speed_level"] = obj->speed; | ||||
|       // NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations) | ||||
|       switch (fan::speed_level_to_enum(obj->speed, traits.supported_speed_count())) { | ||||
|         case fan::FAN_SPEED_LOW:  // NOLINT(clang-diagnostic-deprecated-declarations) | ||||
|           root["speed"] = "low"; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user