From 031a9224fb5efcdd1a9c5079f8e3cd29720f6a98 Mon Sep 17 00:00:00 2001 From: David Knowles Date: Sat, 7 Oct 2023 09:04:23 -0400 Subject: [PATCH] Schlage cleanup: Stop passing logs to last_changed_by (#99738) --- homeassistant/components/schlage/lock.py | 6 +----- tests/components/schlage/test_lock.py | 22 +--------------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/schlage/lock.py b/homeassistant/components/schlage/lock.py index ff9c60c0b55..0b5e35492de 100644 --- a/homeassistant/components/schlage/lock.py +++ b/homeassistant/components/schlage/lock.py @@ -48,11 +48,7 @@ class SchlageLockEntity(SchlageEntity, LockEntity): """Update our internal state attributes.""" self._attr_is_locked = self._lock.is_locked self._attr_is_jammed = self._lock.is_jammed - # Only update changed_by if we get a valid value. This way a previous - # value will stay intact if the latest log message isn't related to a - # lock state change. - if changed_by := self._lock.last_changed_by(self._lock_data.logs): - self._attr_changed_by = changed_by + self._attr_changed_by = self._lock.last_changed_by() async def async_lock(self, **kwargs: Any) -> None: """Lock the device.""" diff --git a/tests/components/schlage/test_lock.py b/tests/components/schlage/test_lock.py index bf32d76836c..0972aa97033 100644 --- a/tests/components/schlage/test_lock.py +++ b/tests/components/schlage/test_lock.py @@ -3,8 +3,6 @@ from datetime import timedelta from unittest.mock import Mock -from pyschlage.exceptions import UnknownError - from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_ENTITY_ID, SERVICE_LOCK, SERVICE_UNLOCK @@ -62,26 +60,8 @@ async def test_changed_by( # Make the coordinator refresh data. async_fire_time_changed(hass, utcnow() + timedelta(seconds=31)) await hass.async_block_till_done() - mock_lock.last_changed_by.assert_called_once_with([]) + mock_lock.last_changed_by.assert_called_once_with() lock_device = hass.states.get("lock.vault_door") assert lock_device is not None assert lock_device.attributes.get("changed_by") == "access code - foo" - - -async def test_changed_by_uses_previous_logs_on_failure( - hass: HomeAssistant, mock_lock: Mock, mock_added_config_entry: ConfigEntry -) -> None: - """Test that a failure to load logs is not terminal.""" - mock_lock.last_changed_by.reset_mock() - mock_lock.last_changed_by.return_value = "thumbturn" - mock_lock.logs.side_effect = UnknownError("Cannot load logs") - - # Make the coordinator refresh data. - async_fire_time_changed(hass, utcnow() + timedelta(seconds=31)) - await hass.async_block_till_done() - mock_lock.last_changed_by.assert_called_once_with([]) - - lock_device = hass.states.get("lock.vault_door") - assert lock_device is not None - assert lock_device.attributes.get("changed_by") == "thumbturn"