Intialize mqtt lock in an unknown state in pessimistic mode (#100943)

Intialize mqtt lock as unknown in pessimistic mode
This commit is contained in:
Jan Bouwhuis 2023-09-26 19:53:45 +02:00 committed by GitHub
parent 734c4e8e32
commit 20a2e129fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View file

@ -150,7 +150,6 @@ class MqttLock(MqttEntity, LockEntity):
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the lock."""
self._attr_is_locked = False
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
@ -160,10 +159,13 @@ class MqttLock(MqttEntity, LockEntity):
def _setup_from_config(self, config: ConfigType) -> None:
"""(Re)Setup the entity."""
self._optimistic = (
config[CONF_OPTIMISTIC] or self._config.get(CONF_STATE_TOPIC) is None
)
self._attr_assumed_state = bool(self._optimistic)
if (
optimistic := config[CONF_OPTIMISTIC]
or config.get(CONF_STATE_TOPIC) is None
):
self._attr_is_locked = False
self._optimistic = optimistic
self._attr_assumed_state = bool(optimistic)
self._compiled_pattern = config.get(CONF_CODE_FORMAT)
self._attr_code_format = (