@@ -546,11 +546,12 @@ def __init__(
546546 self ._attr_target_temperature_step = config [CONF_TEMP_STEP ]
547547 self ._attr_hvac_modes = config [CONF_MODES_LIST ]
548548 self ._attr_fan_modes = config .get (CONF_FAN_LIST )
549- if (
550- isinstance (self ._attr_fan_modes , list )
551- and HVAC_FAN_MAX_HIGH in self ._attr_fan_modes
552- and HVAC_FAN_AUTO_MAX in self ._attr_fan_modes
553- ):
549+ self ._quirk_fan_max_high = all ([
550+ isinstance (self ._attr_fan_modes , list ),
551+ HVAC_FAN_MAX_HIGH in self ._attr_fan_modes ,
552+ HVAC_FAN_AUTO_MAX in self ._attr_fan_modes ,
553+ ])
554+ if self ._quirk_fan_max_high :
554555 new_fan_list = []
555556 for val in self ._attr_fan_modes :
556557 if val == HVAC_FAN_MAX_HIGH :
@@ -560,6 +561,9 @@ def __init__(
560561 else :
561562 new_fan_list .append (val )
562563 self ._attr_fan_modes = new_fan_list if len (new_fan_list ) else None
564+ self ._quirk_fan_prettify = all (mode not in (self ._attr_fan_modes or []) for mode in [FAN_LOW , FAN_HIGH ])
565+ if self ._quirk_fan_prettify and self ._attr_fan_modes :
566+ self ._attr_fan_modes = [self .fan_prettify (mode ) for mode in self ._attr_fan_modes ]
563567 self ._attr_fan_mode = (
564568 self ._attr_fan_modes [0 ]
565569 if isinstance (self ._attr_fan_modes , list ) and len (self ._attr_fan_modes )
@@ -585,6 +589,24 @@ def __init__(
585589 if self ._attr_swing_mode is not None :
586590 self ._support_flags = self ._support_flags | ClimateEntityFeature .SWING_MODE
587591
592+ def fan_prettify (self , mode ):
593+ if not self ._quirk_fan_prettify :
594+ return mode
595+ if mode == HVAC_FAN_MIN :
596+ return FAN_LOW
597+ if mode == HVAC_FAN_MAX :
598+ return FAN_HIGH
599+ return mode
600+
601+ def fan_unprettify (self , mode ):
602+ if not self ._quirk_fan_prettify :
603+ return mode
604+ if mode == FAN_LOW :
605+ return HVAC_FAN_MIN
606+ if mode == FAN_HIGH :
607+ return HVAC_FAN_MAX
608+ return mode
609+
588610 async def async_added_to_hass (self ):
589611 # Replacing `async_track_state_change` with `async_track_state_change_event`
590612 # See, https://developers.home-assistant.io/blog/2024/04/13/deprecate_async_track_state_change/
@@ -792,17 +814,15 @@ async def state_message_received(message: mqtt.ReceiveMessage) -> None:
792814 if "FanSpeed" in payload :
793815 fan_mode = payload ["FanSpeed" ].lower ()
794816 # ELECTRA_AC fan modes fix
795- if HVAC_FAN_MAX_HIGH in (
796- self ._attr_fan_modes or []
797- ) and HVAC_FAN_AUTO_MAX in (self ._attr_fan_modes or []):
817+ if self ._quirk_fan_max_high :
798818 if fan_mode == HVAC_FAN_MAX :
799819 self ._attr_fan_mode = FAN_HIGH
800820 elif fan_mode == HVAC_FAN_AUTO :
801821 self ._attr_fan_mode = HVAC_FAN_MAX
802822 else :
803- self ._attr_fan_mode = fan_mode
823+ self ._attr_fan_mode = self . fan_prettify ( fan_mode )
804824 else :
805- self ._attr_fan_mode = fan_mode
825+ self ._attr_fan_mode = self . fan_prettify ( fan_mode )
806826 _LOGGER .debug (self ._attr_fan_mode )
807827
808828 if self ._attr_hvac_mode is not HVACMode .OFF :
@@ -933,24 +953,12 @@ async def async_set_temperature(self, **kwargs):
933953 async def async_set_fan_mode (self , fan_mode ):
934954 """Set new target fan mode."""
935955 if fan_mode not in (self ._attr_fan_modes or []):
936- # tweak for some ELECTRA_AC devices
937- if HVAC_FAN_MAX_HIGH in (
938- self ._attr_fan_modes or []
939- ) and HVAC_FAN_AUTO_MAX in (self ._attr_fan_modes or []):
940- if fan_mode != FAN_HIGH and fan_mode != HVAC_FAN_MAX :
941- _LOGGER .error (
942- "Invalid swing mode selected. Got '%s'. Allowed modes are:" ,
943- fan_mode ,
944- )
945- _LOGGER .error (self ._attr_fan_modes )
946- return
947- else :
948- _LOGGER .error (
949- "Invalid swing mode selected. Got '%s'. Allowed modes are:" ,
950- fan_mode ,
951- )
952- _LOGGER .error (self ._attr_fan_modes )
953- return
956+ _LOGGER .error (
957+ "Invalid fan mode selected. Got '%s'. Allowed modes are:" ,
958+ fan_mode ,
959+ )
960+ _LOGGER .error (self ._attr_fan_modes )
961+ return
954962 self ._attr_fan_mode = fan_mode
955963 if not self ._attr_hvac_mode == HVACMode .OFF :
956964 self .power_mode = STATE_ON
@@ -1193,14 +1201,12 @@ async def set_mode(self, hvac_mode):
11931201
11941202 async def send_ir (self ):
11951203 """Send the payload to tasmota mqtt topic."""
1196- fan_speed = self .fan_mode
1204+ fan_speed = self .fan_unprettify ( self . _attr_fan_mode )
11971205 # tweak for some ELECTRA_AC devices
1198- if HVAC_FAN_MAX_HIGH in (self ._attr_fan_modes or []) and HVAC_FAN_AUTO_MAX in (
1199- self ._attr_fan_modes or []
1200- ):
1201- if self .fan_mode == FAN_HIGH :
1206+ if self ._quirk_fan_max_high :
1207+ if fan_speed == FAN_HIGH :
12021208 fan_speed = HVAC_FAN_MAX
1203- if self . fan_mode == HVAC_FAN_MAX :
1209+ elif fan_speed == HVAC_FAN_MAX :
12041210 fan_speed = HVAC_FAN_AUTO
12051211
12061212 # Set the swing mode - default off
0 commit comments