Fix optimistic mode and add tests (#22899)

This commit is contained in:
Erik Montnemery authored and Paulus Schoutsen committed 2019-04-10 13:56:34 -07:00
1 parent 6463b8165f
commit 38d92b2abf
3 files changed
+127 -2

No files matched your search

+10 -2
View File
@@ -79,12 +79,14 @@ class MqttLock(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
def __init__(self, config, config_entry, discovery_hash):
"""Initialize the lock."""
self._config = config
self._unique_id = config.get(CONF_UNIQUE_ID)
self._state = False
self._sub_state = None
self._optimistic = False
# Load config
self._setup_from_config(config)
device_config = config.get(CONF_DEVICE)
MqttAttributes.__init__(self, config)
@@ -101,13 +103,19 @@ class MqttLock(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
async def discovery_update(self, discovery_payload):
"""Handle updated discovery message."""
config = PLATFORM_SCHEMA(discovery_payload)
self._config = config
self._setup_from_config(config)
await self.attributes_discovery_update(config)
await self.availability_discovery_update(config)
await self.device_info_discovery_update(config)
await self._subscribe_topics()
self.async_write_ha_state()
def _setup_from_config(self, config):
"""(Re)Setup the entity."""
self._config = config
self._optimistic = config[CONF_OPTIMISTIC]
async def _subscribe_topics(self):
"""(Re)Subscribe to topics."""
value_template = self._config.get(CONF_VALUE_TEMPLATE)