Add configuration for climate topics (#2473)

This commit is contained in:
definitio
2021-10-10 18:55:22 +03:00
committed by GitHub
parent a1f9b0d7f2
commit 42739f0b22
3 changed files with 174 additions and 3 deletions
+142 -3
View File
@@ -4,22 +4,38 @@ from esphome.cpp_helpers import setup_entity
from esphome import automation
from esphome.components import mqtt
from esphome.const import (
CONF_ACTION_STATE_TOPIC,
CONF_AWAY,
CONF_AWAY_COMMAND_TOPIC,
CONF_AWAY_STATE_TOPIC,
CONF_CURRENT_TEMPERATURE_STATE_TOPIC,
CONF_CUSTOM_FAN_MODE,
CONF_CUSTOM_PRESET,
CONF_FAN_MODE,
CONF_FAN_MODE_COMMAND_TOPIC,
CONF_FAN_MODE_STATE_TOPIC,
CONF_ID,
CONF_MAX_TEMPERATURE,
CONF_MIN_TEMPERATURE,
CONF_MODE,
CONF_MODE_COMMAND_TOPIC,
CONF_MODE_STATE_TOPIC,
CONF_PRESET,
CONF_SWING_MODE,
CONF_SWING_MODE_COMMAND_TOPIC,
CONF_SWING_MODE_STATE_TOPIC,
CONF_TARGET_TEMPERATURE,
CONF_TARGET_TEMPERATURE_COMMAND_TOPIC,
CONF_TARGET_TEMPERATURE_STATE_TOPIC,
CONF_TARGET_TEMPERATURE_HIGH,
CONF_TARGET_TEMPERATURE_HIGH_COMMAND_TOPIC,
CONF_TARGET_TEMPERATURE_HIGH_STATE_TOPIC,
CONF_TARGET_TEMPERATURE_LOW,
CONF_TARGET_TEMPERATURE_LOW_COMMAND_TOPIC,
CONF_TARGET_TEMPERATURE_LOW_STATE_TOPIC,
CONF_TEMPERATURE_STEP,
CONF_VISUAL,
CONF_MQTT_ID,
CONF_FAN_MODE,
CONF_SWING_MODE,
)
from esphome.core import CORE, coroutine_with_priority
@@ -97,7 +113,54 @@ CLIMATE_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).
cv.Optional(CONF_TEMPERATURE_STEP): cv.temperature,
}
),
# TODO: MQTT topic options
cv.Optional(CONF_ACTION_STATE_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_AWAY_COMMAND_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_AWAY_STATE_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_CURRENT_TEMPERATURE_STATE_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_FAN_MODE_COMMAND_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_FAN_MODE_STATE_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_MODE_COMMAND_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_MODE_STATE_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_SWING_MODE_COMMAND_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_SWING_MODE_STATE_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_TARGET_TEMPERATURE_COMMAND_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_TARGET_TEMPERATURE_STATE_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_TARGET_TEMPERATURE_HIGH_COMMAND_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_TARGET_TEMPERATURE_HIGH_STATE_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_TARGET_TEMPERATURE_LOW_COMMAND_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
cv.Optional(CONF_TARGET_TEMPERATURE_LOW_STATE_TOPIC): cv.All(
cv.requires_component("mqtt"), cv.publish_topic
),
}
)
@@ -117,6 +180,82 @@ async def setup_climate_core_(var, config):
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
await mqtt.register_mqtt_component(mqtt_, config)
if CONF_ACTION_STATE_TOPIC in config:
cg.add(mqtt_.set_custom_action_state_topic(config[CONF_ACTION_STATE_TOPIC]))
if CONF_AWAY_COMMAND_TOPIC in config:
cg.add(mqtt_.set_custom_away_command_topic(config[CONF_AWAY_COMMAND_TOPIC]))
if CONF_AWAY_STATE_TOPIC in config:
cg.add(mqtt_.set_custom_away_state_topic(config[CONF_AWAY_STATE_TOPIC]))
if CONF_CURRENT_TEMPERATURE_STATE_TOPIC in config:
cg.add(
mqtt_.set_custom_current_temperature_state_topic(
config[CONF_CURRENT_TEMPERATURE_STATE_TOPIC]
)
)
if CONF_FAN_MODE_COMMAND_TOPIC in config:
cg.add(
mqtt_.set_custom_fan_mode_command_topic(
config[CONF_FAN_MODE_COMMAND_TOPIC]
)
)
if CONF_FAN_MODE_STATE_TOPIC in config:
cg.add(
mqtt_.set_custom_fan_mode_state_topic(config[CONF_FAN_MODE_STATE_TOPIC])
)
if CONF_MODE_COMMAND_TOPIC in config:
cg.add(mqtt_.set_custom_mode_command_topic(config[CONF_MODE_COMMAND_TOPIC]))
if CONF_MODE_STATE_TOPIC in config:
cg.add(mqtt_.set_custom_state_topic(config[CONF_MODE_STATE_TOPIC]))
if CONF_SWING_MODE_COMMAND_TOPIC in config:
cg.add(
mqtt_.set_custom_swing_mode_command_topic(
config[CONF_SWING_MODE_COMMAND_TOPIC]
)
)
if CONF_SWING_MODE_STATE_TOPIC in config:
cg.add(
mqtt_.set_custom_swing_mode_state_topic(
config[CONF_SWING_MODE_STATE_TOPIC]
)
)
if CONF_TARGET_TEMPERATURE_COMMAND_TOPIC in config:
cg.add(
mqtt_.set_custom_target_temperature_command_topic(
config[CONF_TARGET_TEMPERATURE_COMMAND_TOPIC]
)
)
if CONF_TARGET_TEMPERATURE_STATE_TOPIC in config:
cg.add(
mqtt_.set_custom_target_temperature_state_topic(
config[CONF_TARGET_TEMPERATURE_STATE_TOPIC]
)
)
if CONF_TARGET_TEMPERATURE_HIGH_COMMAND_TOPIC in config:
cg.add(
mqtt_.set_custom_target_temperature_high_command_topic(
config[CONF_TARGET_TEMPERATURE_HIGH_COMMAND_TOPIC]
)
)
if CONF_TARGET_TEMPERATURE_HIGH_STATE_TOPIC in config:
cg.add(
mqtt_.set_custom_target_temperature_high_state_topic(
config[CONF_TARGET_TEMPERATURE_HIGH_STATE_TOPIC]
)
)
if CONF_TARGET_TEMPERATURE_LOW_COMMAND_TOPIC in config:
cg.add(
mqtt_.set_custom_target_temperature_low_command_topic(
config[CONF_TARGET_TEMPERATURE_LOW_COMMAND_TOPIC]
)
)
if CONF_TARGET_TEMPERATURE_LOW_STATE_TOPIC in config:
cg.add(
mqtt_.set_custom_target_temperature_state_topic(
config[CONF_TARGET_TEMPERATURE_LOW_STATE_TOPIC]
)
)
async def register_climate(var, config):
if not CORE.has_id(config[CONF_ID]):