From 53414d8ab48efea2d38eb22fa87abbc34ccb301b Mon Sep 17 00:00:00 2001 From: GrKoR Date: Wed, 26 Nov 2025 21:14:46 -0800 Subject: [PATCH] fix: python code generator fix for custom presets & custom fan modes --- components/aux_ac/climate.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/components/aux_ac/climate.py b/components/aux_ac/climate.py index a60326d..0b0fa2c 100644 --- a/components/aux_ac/climate.py +++ b/components/aux_ac/climate.py @@ -26,12 +26,14 @@ from esphome.const import ( DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_POWER_FACTOR, STATE_CLASS_MEASUREMENT, + __version__ ) from esphome.components.climate import ( ClimateMode, ClimatePreset, ClimateSwingMode, ) +from pkg_resources import parse_version AUX_AC_FIRMWARE_VERSION = '0.3.1' AC_PACKET_TIMEOUT_MIN = 150 @@ -127,6 +129,11 @@ AirConPowerLimitationOnAction = aux_ac_ns.class_( ) +def use_new_api(): + current_version = parse_version(__version__) + return current_version >= parse_version("2025.11.0") + + def validate_packet_timeout(value): minV = AC_PACKET_TIMEOUT_MIN maxV = AC_PACKET_TIMEOUT_MAX @@ -426,10 +433,20 @@ async def to_code(config): cg.add(var.set_supported_swing_modes(config[CONF_SUPPORTED_SWING_MODES])) if CONF_SUPPORTED_PRESETS in config: cg.add(var.set_supported_presets(config[CONF_SUPPORTED_PRESETS])) - if CONF_CUSTOM_PRESETS in config: - cg.add(var.set_custom_presets(config[CONF_CUSTOM_PRESETS])) - if CONF_CUSTOM_FAN_MODES in config: - cg.add(var.set_custom_fan_modes(config[CONF_CUSTOM_FAN_MODES])) + if use_new_api(): + if CONF_CUSTOM_PRESETS in config: + presets = config[CONF_CUSTOM_PRESETS] + c_str_presets = [cg.RawExpression(f"aux_ac::Constants::{p}.c_str()") for p in presets] + cg.add(var.set_custom_presets(c_str_presets)) + if CONF_CUSTOM_FAN_MODES in config: + fan_modes = config[CONF_CUSTOM_FAN_MODES] + c_str_fan_modes = [cg.RawExpression(f"aux_ac::Constants::{p}.c_str()") for p in fan_modes] + cg.add(var.set_custom_fan_modes(c_str_fan_modes)) + else: + if CONF_CUSTOM_PRESETS in config: + cg.add(var.set_custom_presets(config[CONF_CUSTOM_PRESETS])) + if CONF_CUSTOM_FAN_MODES in config: + cg.add(var.set_custom_fan_modes(config[CONF_CUSTOM_FAN_MODES])) DISPLAY_ACTION_SCHEMA = maybe_simple_id(