fix: python code generator fix for custom presets & custom fan modes

This commit is contained in:
GrKoR
2025-11-26 21:14:46 -08:00
parent 5a165d3a3d
commit 53414d8ab4

View File

@@ -26,12 +26,14 @@ from esphome.const import (
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_POWER_FACTOR, DEVICE_CLASS_POWER_FACTOR,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
__version__
) )
from esphome.components.climate import ( from esphome.components.climate import (
ClimateMode, ClimateMode,
ClimatePreset, ClimatePreset,
ClimateSwingMode, ClimateSwingMode,
) )
from pkg_resources import parse_version
AUX_AC_FIRMWARE_VERSION = '0.3.1' AUX_AC_FIRMWARE_VERSION = '0.3.1'
AC_PACKET_TIMEOUT_MIN = 150 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): def validate_packet_timeout(value):
minV = AC_PACKET_TIMEOUT_MIN minV = AC_PACKET_TIMEOUT_MIN
maxV = AC_PACKET_TIMEOUT_MAX maxV = AC_PACKET_TIMEOUT_MAX
@@ -426,6 +433,16 @@ async def to_code(config):
cg.add(var.set_supported_swing_modes(config[CONF_SUPPORTED_SWING_MODES])) cg.add(var.set_supported_swing_modes(config[CONF_SUPPORTED_SWING_MODES]))
if CONF_SUPPORTED_PRESETS in config: if CONF_SUPPORTED_PRESETS in config:
cg.add(var.set_supported_presets(config[CONF_SUPPORTED_PRESETS])) cg.add(var.set_supported_presets(config[CONF_SUPPORTED_PRESETS]))
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: if CONF_CUSTOM_PRESETS in config:
cg.add(var.set_custom_presets(config[CONF_CUSTOM_PRESETS])) cg.add(var.set_custom_presets(config[CONF_CUSTOM_PRESETS]))
if CONF_CUSTOM_FAN_MODES in config: if CONF_CUSTOM_FAN_MODES in config: