mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 15:30:21 +00:00
[mitsubishi_cn105] Use register_apply_action for set_remote_temperature and clear_remote_temperature (#19706)
This commit is contained in:
@@ -10,9 +10,8 @@ from esphome.const import (
|
||||
CONF_UPDATE_INTERVAL,
|
||||
CONF_USE_FAHRENHEIT,
|
||||
)
|
||||
from esphome.core import ID
|
||||
from esphome.cpp_generator import MockObj
|
||||
from esphome.types import ConfigType, TemplateArgsType
|
||||
from esphome.types import ConfigType
|
||||
|
||||
CODEOWNERS = ["@crnjan"]
|
||||
DEPENDENCIES = ["uart"]
|
||||
@@ -46,18 +45,6 @@ VERTICAL_VANE_DIRECTIONS = {
|
||||
"SWING": VerticalVaneMode.VERTICAL_VANE_MODE_SWING,
|
||||
}
|
||||
|
||||
SetRemoteTemperatureAction = mitsubishi_ns.class_(
|
||||
"SetRemoteTemperatureAction",
|
||||
automation.Action,
|
||||
cg.Parented.template(MitsubishiCN105Component),
|
||||
)
|
||||
|
||||
ClearRemoteTemperatureAction = mitsubishi_ns.class_(
|
||||
"ClearRemoteTemperatureAction",
|
||||
automation.Action,
|
||||
cg.Parented.template(MitsubishiCN105Component),
|
||||
)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
@@ -143,30 +130,16 @@ CLEAR_REMOTE_TEMPERATURE_ACTION_SCHEMA = cv.Schema(
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
automation.register_apply_action(
|
||||
f"{DOMAIN}.set_remote_temperature",
|
||||
SetRemoteTemperatureAction,
|
||||
REMOTE_TEMPERATURE_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
automation.ApplyField(CONF_TEMPERATURE, "set_remote_temperature", cg.float_),
|
||||
)
|
||||
async def remote_temperature_action_to_code(
|
||||
config: ConfigType,
|
||||
action_id: ID,
|
||||
template_arg: cg.TemplateArguments,
|
||||
args: TemplateArgsType,
|
||||
) -> MockObj:
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
temperature = await cg.templatable(config[CONF_TEMPERATURE], args, float)
|
||||
cg.add(var.set_temperature(temperature))
|
||||
return var
|
||||
|
||||
|
||||
automation.register_parented_action(
|
||||
automation.register_apply_action(
|
||||
f"{DOMAIN}.clear_remote_temperature",
|
||||
ClearRemoteTemperatureAction,
|
||||
CLEAR_REMOTE_TEMPERATURE_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
automation.ApplyCall("clear_remote_temperature()"),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "mitsubishi_cn105_component.h"
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
|
||||
namespace esphome::mitsubishi_cn105 {
|
||||
|
||||
template<typename... Ts>
|
||||
class SetRemoteTemperatureAction final : public Action<Ts...>, public Parented<MitsubishiCN105Component> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(float, temperature)
|
||||
|
||||
void play(const Ts &...x) override { this->parent_->set_remote_temperature(this->temperature_.value(x...)); }
|
||||
};
|
||||
|
||||
template<typename... Ts>
|
||||
class ClearRemoteTemperatureAction final : public Action<Ts...>, public Parented<MitsubishiCN105Component> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->clear_remote_temperature(); }
|
||||
};
|
||||
|
||||
} // namespace esphome::mitsubishi_cn105
|
||||
@@ -1,3 +1,4 @@
|
||||
from collections.abc import Callable
|
||||
import logging
|
||||
|
||||
from esphome import automation
|
||||
@@ -12,10 +13,9 @@ from esphome.const import (
|
||||
CONF_UART_ID,
|
||||
CONF_UPDATE_INTERVAL,
|
||||
)
|
||||
from esphome.core import CORE, ID
|
||||
from esphome.cpp_generator import MockObj
|
||||
from esphome.core import CORE
|
||||
from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor
|
||||
from esphome.types import ConfigType, TemplateArgsType
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from . import (
|
||||
CONF_MITSUBISHI_CN105_ID,
|
||||
@@ -44,20 +44,6 @@ MitsubishiCN105Climate = mitsubishi_ns.class_(
|
||||
cg.Parented.template(MitsubishiCN105Component),
|
||||
)
|
||||
|
||||
# Legacy climate action compatibility. Remove in 2027.2.0.
|
||||
LegacySetRemoteTemperatureAction = mitsubishi_ns.class_(
|
||||
"LegacySetRemoteTemperatureAction",
|
||||
automation.Action,
|
||||
cg.Parented.template(MitsubishiCN105Climate),
|
||||
)
|
||||
|
||||
# Legacy climate action compatibility. Remove in 2027.2.0.
|
||||
LegacyClearRemoteTemperatureAction = mitsubishi_ns.class_(
|
||||
"LegacyClearRemoteTemperatureAction",
|
||||
automation.Action,
|
||||
cg.Parented.template(MitsubishiCN105Climate),
|
||||
)
|
||||
|
||||
|
||||
# Legacy climate-owned hub compatibility. Remove in 2027.2.0.
|
||||
def _has_top_level_hub_config() -> bool:
|
||||
@@ -204,53 +190,36 @@ LEGACY_CLEAR_REMOTE_TEMPERATURE_ACTION_SCHEMA = cv.Schema(
|
||||
)
|
||||
|
||||
|
||||
# Legacy climate action compatibility. Remove in 2027.2.0.
|
||||
@automation.register_action(
|
||||
def _warn_legacy_action(name: str) -> Callable[[ConfigType], ConfigType]:
|
||||
# Legacy climate action compatibility. Remove in 2027.2.0.
|
||||
def validator(config: ConfigType) -> ConfigType:
|
||||
_LOGGER.warning(
|
||||
"The 'climate.%s.%s' action is deprecated. Use '%s.%s' instead. "
|
||||
"It will be removed in ESPHome 2027.2.0.",
|
||||
DOMAIN,
|
||||
name,
|
||||
DOMAIN,
|
||||
name,
|
||||
)
|
||||
return config
|
||||
|
||||
return validator
|
||||
|
||||
|
||||
automation.register_apply_action(
|
||||
f"climate.{DOMAIN}.set_remote_temperature",
|
||||
LegacySetRemoteTemperatureAction,
|
||||
LEGACY_REMOTE_TEMPERATURE_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
cv.All(
|
||||
LEGACY_REMOTE_TEMPERATURE_ACTION_SCHEMA,
|
||||
_warn_legacy_action("set_remote_temperature"),
|
||||
),
|
||||
automation.ApplyField(CONF_TEMPERATURE, "set_remote_temperature", cg.float_),
|
||||
)
|
||||
async def legacy_remote_temperature_action_to_code(
|
||||
config: ConfigType,
|
||||
action_id: ID,
|
||||
template_arg: cg.TemplateArguments,
|
||||
args: TemplateArgsType,
|
||||
) -> MockObj:
|
||||
_LOGGER.warning(
|
||||
"The 'climate.%s.set_remote_temperature' action is deprecated. Use "
|
||||
"'%s.set_remote_temperature' instead. It will be removed in ESPHome "
|
||||
"2027.2.0.",
|
||||
DOMAIN,
|
||||
DOMAIN,
|
||||
)
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
temperature = await cg.templatable(config[CONF_TEMPERATURE], args, float)
|
||||
cg.add(var.set_temperature(temperature))
|
||||
return var
|
||||
|
||||
|
||||
# Legacy climate action compatibility. Remove in 2027.2.0.
|
||||
@automation.register_action(
|
||||
automation.register_apply_action(
|
||||
f"climate.{DOMAIN}.clear_remote_temperature",
|
||||
LegacyClearRemoteTemperatureAction,
|
||||
LEGACY_CLEAR_REMOTE_TEMPERATURE_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
cv.All(
|
||||
LEGACY_CLEAR_REMOTE_TEMPERATURE_ACTION_SCHEMA,
|
||||
_warn_legacy_action("clear_remote_temperature"),
|
||||
),
|
||||
automation.ApplyCall("clear_remote_temperature()"),
|
||||
)
|
||||
async def legacy_clear_temperature_action_to_code(
|
||||
config: ConfigType,
|
||||
action_id: ID,
|
||||
template_arg: cg.TemplateArguments,
|
||||
args: TemplateArgsType,
|
||||
) -> MockObj:
|
||||
_LOGGER.warning(
|
||||
"The 'climate.%s.clear_remote_temperature' action is deprecated. Use "
|
||||
"'%s.clear_remote_temperature' instead. It will be removed in ESPHome "
|
||||
"2027.2.0.",
|
||||
DOMAIN,
|
||||
DOMAIN,
|
||||
)
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "mitsubishi_cn105_component.h"
|
||||
#include "mitsubishi_cn105.h"
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/climate/climate.h"
|
||||
#include "mitsubishi_cn105_swing_mode_manager.h"
|
||||
@@ -31,20 +30,4 @@ class MitsubishiCN105Climate final : public climate::Climate,
|
||||
SwingModeManager swing_mode_manager_;
|
||||
};
|
||||
|
||||
// Legacy climate action compatibility. Remove in 2027.2.0.
|
||||
template<typename... Ts>
|
||||
class LegacySetRemoteTemperatureAction final : public Action<Ts...>, public Parented<MitsubishiCN105Climate> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(float, temperature)
|
||||
|
||||
void play(const Ts &...x) override { this->parent_->set_remote_temperature(this->temperature_.value(x...)); }
|
||||
};
|
||||
|
||||
// Legacy climate action compatibility. Remove in 2027.2.0.
|
||||
template<typename... Ts>
|
||||
class LegacyClearRemoteTemperatureAction final : public Action<Ts...>, public Parented<MitsubishiCN105Climate> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->clear_remote_temperature(); }
|
||||
};
|
||||
|
||||
} // namespace esphome::mitsubishi_cn105
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <vector>
|
||||
#include "esphome/components/uart/uart_component.h"
|
||||
#include "esphome/components/mitsubishi_cn105/mitsubishi_cn105.h"
|
||||
#include "esphome/components/mitsubishi_cn105/automation.h"
|
||||
#include "esphome/components/mitsubishi_cn105/mitsubishi_cn105_component.h"
|
||||
#include "esphome/components/mitsubishi_cn105/mitsubishi_cn105_climate.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user