parent
9917bb76fb
commit
a5d943b5f1
2 changed files with 67 additions and 66 deletions
|
@ -129,14 +129,14 @@ def validate_options(value):
|
|||
):
|
||||
_LOGGER.warning(
|
||||
"using 'value_template' for 'position_topic' is deprecated "
|
||||
"and will be removed from Home Assistant in version 2021.6"
|
||||
"and will be removed from Home Assistant in version 2021.6, "
|
||||
"please replace it with 'position_template'"
|
||||
)
|
||||
|
||||
if CONF_TILT_INVERT_STATE in value:
|
||||
_LOGGER.warning(
|
||||
"'tilt_invert_state' is deprecated "
|
||||
"and will be removed from Home Assistant in version 2021.6"
|
||||
"and will be removed from Home Assistant in version 2021.6, "
|
||||
"please invert tilt using 'tilt_min' & 'tilt_max'"
|
||||
)
|
||||
|
||||
|
@ -172,9 +172,7 @@ PLATFORM_SCHEMA = vol.All(
|
|||
CONF_TILT_CLOSED_POSITION, default=DEFAULT_TILT_CLOSED_POSITION
|
||||
): int,
|
||||
vol.Optional(CONF_TILT_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
||||
vol.Optional(
|
||||
CONF_TILT_INVERT_STATE, default=DEFAULT_TILT_INVERT_STATE
|
||||
): cv.boolean,
|
||||
vol.Optional(CONF_TILT_INVERT_STATE): cv.boolean,
|
||||
vol.Optional(CONF_TILT_MAX, default=DEFAULT_TILT_MAX): int,
|
||||
vol.Optional(CONF_TILT_MIN, default=DEFAULT_TILT_MIN): int,
|
||||
vol.Optional(
|
||||
|
@ -247,15 +245,22 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||
)
|
||||
self._tilt_optimistic = config[CONF_TILT_STATE_OPTIMISTIC]
|
||||
|
||||
template = self._config.get(CONF_VALUE_TEMPLATE)
|
||||
if template is not None:
|
||||
template.hass = self.hass
|
||||
value_template = self._config.get(CONF_VALUE_TEMPLATE)
|
||||
if value_template is not None:
|
||||
value_template.hass = self.hass
|
||||
|
||||
set_position_template = self._config.get(CONF_SET_POSITION_TEMPLATE)
|
||||
if set_position_template is not None:
|
||||
set_position_template.hass = self.hass
|
||||
|
||||
get_position_template = self._config.get(CONF_GET_POSITION_TEMPLATE)
|
||||
if get_position_template is not None:
|
||||
get_position_template.hass = self.hass
|
||||
|
||||
set_tilt_template = self._config.get(CONF_TILT_COMMAND_TEMPLATE)
|
||||
if set_tilt_template is not None:
|
||||
set_tilt_template.hass = self.hass
|
||||
|
||||
tilt_status_template = self._config.get(CONF_TILT_STATUS_TEMPLATE)
|
||||
if tilt_status_template is not None:
|
||||
tilt_status_template.hass = self.hass
|
||||
|
@ -290,24 +295,21 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||
def state_message_received(msg):
|
||||
"""Handle new MQTT state messages."""
|
||||
payload = msg.payload
|
||||
template = self._config.get(CONF_VALUE_TEMPLATE)
|
||||
if template is not None:
|
||||
payload = template.async_render_with_possible_json_value(payload)
|
||||
value_template = self._config.get(CONF_VALUE_TEMPLATE)
|
||||
if value_template is not None:
|
||||
payload = value_template.async_render_with_possible_json_value(payload)
|
||||
|
||||
if payload == self._config[CONF_STATE_STOPPED]:
|
||||
if (
|
||||
self._optimistic
|
||||
or self._config.get(CONF_GET_POSITION_TOPIC) is None
|
||||
):
|
||||
self._state = (
|
||||
STATE_CLOSED if self._state == STATE_CLOSING else STATE_OPEN
|
||||
)
|
||||
else:
|
||||
if self._config.get(CONF_GET_POSITION_TOPIC) is not None:
|
||||
self._state = (
|
||||
STATE_CLOSED
|
||||
if self._position == DEFAULT_POSITION_CLOSED
|
||||
else STATE_OPEN
|
||||
)
|
||||
else:
|
||||
self._state = (
|
||||
STATE_CLOSED if self._state == STATE_CLOSING else STATE_OPEN
|
||||
)
|
||||
elif payload == self._config[CONF_STATE_OPENING]:
|
||||
self._state = STATE_OPENING
|
||||
elif payload == self._config[CONF_STATE_CLOSING]:
|
||||
|
@ -616,7 +618,7 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||
max_percent = 100
|
||||
min_percent = 0
|
||||
position_percentage = min(max(position_percentage, min_percent), max_percent)
|
||||
if range_type == TILT_PAYLOAD and self._config[CONF_TILT_INVERT_STATE]:
|
||||
if range_type == TILT_PAYLOAD and self._config.get(CONF_TILT_INVERT_STATE):
|
||||
return 100 - position_percentage
|
||||
return position_percentage
|
||||
|
||||
|
@ -640,6 +642,6 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||
position = round(current_range * (percentage / 100.0))
|
||||
position += offset
|
||||
|
||||
if range_type == TILT_PAYLOAD and self._config[CONF_TILT_INVERT_STATE]:
|
||||
if range_type == TILT_PAYLOAD and self._config.get(CONF_TILT_INVERT_STATE):
|
||||
position = max_range - position + offset
|
||||
return position
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue