mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Schlage cleanup: Stop passing logs to last_changed_by (#99738)
This commit is contained in:
parent
b60401b2b1
commit
031a9224fb
@ -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."""
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user