mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 05:24:53 +01:00
Add configuration for cover topics (#2472)
This commit is contained in:
parent
c3b8c84131
commit
a1f9b0d7f2
3 changed files with 41 additions and 1 deletions
|
@ -8,7 +8,11 @@ from esphome.const import (
|
|||
CONF_DEVICE_CLASS,
|
||||
CONF_STATE,
|
||||
CONF_POSITION,
|
||||
CONF_POSITION_COMMAND_TOPIC,
|
||||
CONF_POSITION_STATE_TOPIC,
|
||||
CONF_TILT,
|
||||
CONF_TILT_COMMAND_TOPIC,
|
||||
CONF_TILT_STATE_TOPIC,
|
||||
CONF_STOP,
|
||||
CONF_MQTT_ID,
|
||||
)
|
||||
|
@ -68,7 +72,18 @@ COVER_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).ex
|
|||
cv.GenerateID(): cv.declare_id(Cover),
|
||||
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTCoverComponent),
|
||||
cv.Optional(CONF_DEVICE_CLASS): cv.one_of(*DEVICE_CLASSES, lower=True),
|
||||
# TODO: MQTT topic options
|
||||
cv.Optional(CONF_POSITION_COMMAND_TOPIC): cv.All(
|
||||
cv.requires_component("mqtt"), cv.subscribe_topic
|
||||
),
|
||||
cv.Optional(CONF_POSITION_STATE_TOPIC): cv.All(
|
||||
cv.requires_component("mqtt"), cv.subscribe_topic
|
||||
),
|
||||
cv.Optional(CONF_TILT_COMMAND_TOPIC): cv.All(
|
||||
cv.requires_component("mqtt"), cv.subscribe_topic
|
||||
),
|
||||
cv.Optional(CONF_TILT_STATE_TOPIC): cv.All(
|
||||
cv.requires_component("mqtt"), cv.subscribe_topic
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -83,6 +98,21 @@ async def setup_cover_core_(var, config):
|
|||
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
|
||||
await mqtt.register_mqtt_component(mqtt_, config)
|
||||
|
||||
if CONF_POSITION_STATE_TOPIC in config:
|
||||
cg.add(
|
||||
mqtt_.set_custom_position_state_topic(config[CONF_POSITION_STATE_TOPIC])
|
||||
)
|
||||
if CONF_POSITION_COMMAND_TOPIC in config:
|
||||
cg.add(
|
||||
mqtt_.set_custom_position_command_topic(
|
||||
config[CONF_POSITION_COMMAND_TOPIC]
|
||||
)
|
||||
)
|
||||
if CONF_TILT_STATE_TOPIC in config:
|
||||
cg.add(mqtt_.set_custom_tilt_state_topic(config[CONF_TILT_STATE_TOPIC]))
|
||||
if CONF_TILT_COMMAND_TOPIC in config:
|
||||
cg.add(mqtt_.set_custom_tilt_command_topic(config[CONF_TILT_COMMAND_TOPIC]))
|
||||
|
||||
|
||||
async def register_cover(var, config):
|
||||
if not CORE.has_id(config[CONF_ID]):
|
||||
|
|
|
@ -497,6 +497,8 @@ CONF_PMC_4_0 = "pmc_4_0"
|
|||
CONF_PORT = "port"
|
||||
CONF_POSITION = "position"
|
||||
CONF_POSITION_ACTION = "position_action"
|
||||
CONF_POSITION_COMMAND_TOPIC = "position_command_topic"
|
||||
CONF_POSITION_STATE_TOPIC = "position_state_topic"
|
||||
CONF_POWER = "power"
|
||||
CONF_POWER_FACTOR = "power_factor"
|
||||
CONF_POWER_ON_VALUE = "power_on_value"
|
||||
|
@ -654,7 +656,9 @@ CONF_THRESHOLD = "threshold"
|
|||
CONF_THROTTLE = "throttle"
|
||||
CONF_TILT = "tilt"
|
||||
CONF_TILT_ACTION = "tilt_action"
|
||||
CONF_TILT_COMMAND_TOPIC = "tilt_command_topic"
|
||||
CONF_TILT_LAMBDA = "tilt_lambda"
|
||||
CONF_TILT_STATE_TOPIC = "tilt_state_topic"
|
||||
CONF_TIME = "time"
|
||||
CONF_TIME_ID = "time_id"
|
||||
CONF_TIMEOUT = "timeout"
|
||||
|
|
|
@ -2285,6 +2285,12 @@ cover:
|
|||
id: template_cover
|
||||
state: CLOSED
|
||||
assumed_state: no
|
||||
has_position: yes
|
||||
position_state_topic: position/state/topic
|
||||
position_command_topic: position/command/topic
|
||||
tilt_lambda: !lambda 'return 0.5;'
|
||||
tilt_state_topic: tilt/state/topic
|
||||
tilt_command_topic: tilt/command/topic
|
||||
- platform: am43
|
||||
name: 'Test AM43'
|
||||
id: am43_test
|
||||
|
|
Loading…
Reference in a new issue