diff --git a/components/aux_ac/aux_ac.h b/components/aux_ac/aux_ac.h index 4481fa1..68d0912 100644 --- a/components/aux_ac/aux_ac.h +++ b/components/aux_ac/aux_ac.h @@ -113,7 +113,8 @@ namespace esphome static const uint32_t AC_PACKET_TIMEOUT_MIN; }; - const std::string Constants::AC_FIRMWARE_VERSION = "0.2.14"; + // AUX_AC_FIRMWARE_VERSION will be defined by the ESPHome code generator at compile time + const std::string Constants::AC_FIRMWARE_VERSION = AUX_AC_FIRMWARE_VERSION; // custom fan modes const std::string Constants::MUTE = "mute"; @@ -128,8 +129,9 @@ namespace esphome const float Constants::AC_MIN_TEMPERATURE = 16.0; const float Constants::AC_MAX_TEMPERATURE = 32.0; const float Constants::AC_TEMPERATURE_STEP = 0.5; - const uint8_t Constants::AC_MIN_INVERTER_POWER_LIMIT = 30; // 30% - const uint8_t Constants::AC_MAX_INVERTER_POWER_LIMIT = 100; // 100% + // AUX_AC_MIN_INVERTER_POWER_LIMIT and AUX_AC_MAX_INVERTER_POWER_LIMIT will be defined by the ESPHome code generator at compile time + const uint8_t Constants::AC_MIN_INVERTER_POWER_LIMIT = AUX_AC_MIN_INVERTER_POWER_LIMIT; + const uint8_t Constants::AC_MAX_INVERTER_POWER_LIMIT = AUX_AC_MAX_INVERTER_POWER_LIMIT; const uint32_t Constants::AC_STATES_REQUEST_INTERVAL = 7000; // таймаут загрузки пакета // По расчетам выходит: @@ -141,8 +143,9 @@ namespace esphome // команды будут теряться. От такой коллизии мы не защищены в любом случае. Но чем меньше таймаут, // тем меньше шансов на коллизию. // Из этих соображений выбраны границы диапазона (_MIN и _MAX значения). - const uint32_t Constants::AC_PACKET_TIMEOUT_MAX = 600; - const uint32_t Constants::AC_PACKET_TIMEOUT_MIN = 150; + // AUX_AC_PACKET_TIMEOUT_MAX and AUX_AC_PACKET_TIMEOUT_MIN will be defined by the ESPHome code generator at compile time + const uint32_t Constants::AC_PACKET_TIMEOUT_MAX = AUX_AC_PACKET_TIMEOUT_MAX; + const uint32_t Constants::AC_PACKET_TIMEOUT_MIN = AUX_AC_PACKET_TIMEOUT_MIN; //**************************************************************************************************************************************************** //********************************************************* ОСНОВНЫЕ СТРУКТУРЫ *********************************************************************** diff --git a/components/aux_ac/climate.py b/components/aux_ac/climate.py index a9699b2..2080d25 100644 --- a/components/aux_ac/climate.py +++ b/components/aux_ac/climate.py @@ -1,4 +1,5 @@ import logging +from esphome.core import CORE, Define import esphome.config_validation as cv import esphome.codegen as cg from esphome.components import climate, uart, sensor, binary_sensor, text_sensor @@ -32,6 +33,12 @@ from esphome.components.climate import ( ClimateSwingMode, ) +AUX_AC_FIRMWARE_VERSION = '0.2.15' +AC_PACKET_TIMEOUT_MIN = 150 +AC_PACKET_TIMEOUT_MAX = 600 +AC_POWER_LIMIT_MIN = 30 +AC_POWER_LIMIT_MAX = 100 + _LOGGER = logging.getLogger(__name__) CODEOWNERS = ["@GrKoR"] @@ -120,8 +127,6 @@ AirConPowerLimitationOnAction = aux_ac_ns.class_( ) -AC_PACKET_TIMEOUT_MIN = 150 -AC_PACKET_TIMEOUT_MAX = 600 def validate_packet_timeout(value): minV = AC_PACKET_TIMEOUT_MIN maxV = AC_PACKET_TIMEOUT_MAX @@ -130,8 +135,6 @@ def validate_packet_timeout(value): raise cv.Invalid(f"Timeout should be in range: {minV}..{maxV}.") -AC_POWER_LIMIT_MIN = 30 -AC_POWER_LIMIT_MAX = 100 def validate_power_limit_range(value): minV = AC_POWER_LIMIT_MIN maxV = AC_POWER_LIMIT_MAX @@ -182,7 +185,7 @@ def validate_raw_data(value): def output_info(config): - """_LOGGER.info(config.items())""" + _LOGGER.info("AUX_AC firmware version: %s", AUX_AC_FIRMWARE_VERSION) return config @@ -330,6 +333,21 @@ CONFIG_SCHEMA = cv.All( async def to_code(config): + CORE.add_define( + Define("AUX_AC_FIRMWARE_VERSION", '"'+AUX_AC_FIRMWARE_VERSION+'"') + ) + CORE.add_define( + Define("AUX_AC_PACKET_TIMEOUT_MIN", AC_PACKET_TIMEOUT_MIN) + ) + CORE.add_define( + Define("AUX_AC_PACKET_TIMEOUT_MAX", AC_PACKET_TIMEOUT_MAX) + ) + CORE.add_define( + Define("AUX_AC_MIN_INVERTER_POWER_LIMIT", AC_POWER_LIMIT_MIN) + ) + CORE.add_define( + Define("AUX_AC_MAX_INVERTER_POWER_LIMIT", AC_POWER_LIMIT_MAX) + ) var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await climate.register_climate(var, config) @@ -386,7 +404,7 @@ async def to_code(config): conf = config[CONF_PRESET_REPORTER] sens = await text_sensor.new_text_sensor(conf) cg.add(var.set_preset_reporter_sensor(sens)) - + if CONF_INVERTER_POWER_LIMIT_VALUE in config: conf = config[CONF_INVERTER_POWER_LIMIT_VALUE] sens = await sensor.new_sensor(conf) @@ -414,13 +432,13 @@ async def to_code(config): cg.add(var.set_custom_fan_modes(config[CONF_CUSTOM_FAN_MODES])) - DISPLAY_ACTION_SCHEMA = maybe_simple_id( { cv.Required(CONF_ID): cv.use_id(AirCon), } ) + @automation.register_action( "aux_ac.display_off", AirConDisplayOffAction, DISPLAY_ACTION_SCHEMA ) @@ -428,6 +446,7 @@ async def display_off_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren) + @automation.register_action( "aux_ac.display_on", AirConDisplayOnAction, DISPLAY_ACTION_SCHEMA ) @@ -436,13 +455,13 @@ async def display_on_to_code(config, action_id, template_arg, args): return cg.new_Pvariable(action_id, template_arg, paren) - VLOUVER_ACTION_SCHEMA = maybe_simple_id( { cv.Required(CONF_ID): cv.use_id(AirCon), } ) + @automation.register_action( "aux_ac.vlouver_stop", AirConVLouverStopAction, VLOUVER_ACTION_SCHEMA ) @@ -450,6 +469,7 @@ async def vlouver_stop_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren) + @automation.register_action( "aux_ac.vlouver_swing", AirConVLouverSwingAction, VLOUVER_ACTION_SCHEMA ) @@ -457,6 +477,7 @@ async def vlouver_swing_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren) + @automation.register_action( "aux_ac.vlouver_top", AirConVLouverTopAction, VLOUVER_ACTION_SCHEMA ) @@ -464,6 +485,7 @@ async def vlouver_top_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren) + @automation.register_action( "aux_ac.vlouver_middle_above", AirConVLouverMiddleAboveAction, VLOUVER_ACTION_SCHEMA ) @@ -471,6 +493,7 @@ async def vlouver_middle_above_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren) + @automation.register_action( "aux_ac.vlouver_middle", AirConVLouverMiddleAction, VLOUVER_ACTION_SCHEMA ) @@ -478,6 +501,7 @@ async def vlouver_middle_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren) + @automation.register_action( "aux_ac.vlouver_middle_below", AirConVLouverMiddleBelowAction, VLOUVER_ACTION_SCHEMA ) @@ -485,6 +509,7 @@ async def vlouver_middle_below_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren) + @automation.register_action( "aux_ac.vlouver_bottom", AirConVLouverBottomAction, VLOUVER_ACTION_SCHEMA ) @@ -493,7 +518,6 @@ async def vlouver_bottom_to_code(config, action_id, template_arg, args): return cg.new_Pvariable(action_id, template_arg, paren) - VLOUVER_SET_ACTION_SCHEMA = cv.Schema( { cv.Required(CONF_ID): cv.use_id(AirCon), @@ -501,6 +525,7 @@ VLOUVER_SET_ACTION_SCHEMA = cv.Schema( } ) + @automation.register_action( "aux_ac.vlouver_set", AirConVLouverSetAction, VLOUVER_SET_ACTION_SCHEMA ) @@ -512,13 +537,13 @@ async def vlouver_set_to_code(config, action_id, template_arg, args): return var - POWER_LIMITATION_OFF_ACTION_SCHEMA = maybe_simple_id( { cv.Required(CONF_ID): cv.use_id(AirCon), } ) + @automation.register_action( "aux_ac.power_limit_off", AirConPowerLimitationOffAction, POWER_LIMITATION_OFF_ACTION_SCHEMA ) @@ -527,7 +552,6 @@ async def power_limit_off_to_code(config, action_id, template_arg, args): return cg.new_Pvariable(action_id, template_arg, paren) - POWER_LIMITATION_ON_ACTION_SCHEMA = cv.Schema( { cv.Required(CONF_ID): cv.use_id(AirCon), @@ -535,6 +559,7 @@ POWER_LIMITATION_ON_ACTION_SCHEMA = cv.Schema( } ) + @automation.register_action( "aux_ac.power_limit_on", AirConPowerLimitationOnAction, POWER_LIMITATION_ON_ACTION_SCHEMA ) @@ -546,7 +571,6 @@ async def power_limit_on_to_code(config, action_id, template_arg, args): return var - # ********************************************************************************************************* # ВАЖНО! Только для инженеров! # Вызывайте метод aux_ac.send_packet только если понимаете, что делаете! Он не проверяет данные, а передаёт