Reduce duplicate publish code in mqtt (#118163)
This commit is contained in:
parent
5d37217d96
commit
80371d3a73
22 changed files with 87 additions and 335 deletions
|
@ -33,7 +33,6 @@ from .const import (
|
|||
CONF_COMMAND_TOPIC,
|
||||
CONF_ENCODING,
|
||||
CONF_QOS,
|
||||
CONF_RETAIN,
|
||||
CONF_STATE_TOPIC,
|
||||
PAYLOAD_NONE,
|
||||
)
|
||||
|
@ -162,12 +161,8 @@ class MqttSwitch(MqttEntity, SwitchEntity, RestoreEntity):
|
|||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
await self.async_publish(
|
||||
self._config[CONF_COMMAND_TOPIC],
|
||||
self._config[CONF_PAYLOAD_ON],
|
||||
self._config[CONF_QOS],
|
||||
self._config[CONF_RETAIN],
|
||||
self._config[CONF_ENCODING],
|
||||
await self.async_publish_with_config(
|
||||
self._config[CONF_COMMAND_TOPIC], self._config[CONF_PAYLOAD_ON]
|
||||
)
|
||||
if self._optimistic:
|
||||
# Optimistically assume that switch has changed state.
|
||||
|
@ -179,12 +174,8 @@ class MqttSwitch(MqttEntity, SwitchEntity, RestoreEntity):
|
|||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
await self.async_publish(
|
||||
self._config[CONF_COMMAND_TOPIC],
|
||||
self._config[CONF_PAYLOAD_OFF],
|
||||
self._config[CONF_QOS],
|
||||
self._config[CONF_RETAIN],
|
||||
self._config[CONF_ENCODING],
|
||||
await self.async_publish_with_config(
|
||||
self._config[CONF_COMMAND_TOPIC], self._config[CONF_PAYLOAD_OFF]
|
||||
)
|
||||
if self._optimistic:
|
||||
# Optimistically assume that switch has changed state.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue