From 3d9f4bf2aac73e9ab69fea9c8326fce8a37270ad Mon Sep 17 00:00:00 2001 From: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com> Date: Sat, 23 Feb 2019 19:52:37 -0600 Subject: [PATCH] SmartThings Lock platform state attributes enhancement (#21379) * Add additional lock metadata * Fixed attribute name in test --- homeassistant/components/smartthings/lock.py | 5 ++++- tests/components/smartthings/test_lock.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/smartthings/lock.py b/homeassistant/components/smartthings/lock.py index bc5ab7a8ccd..c7ab091454c 100644 --- a/homeassistant/components/smartthings/lock.py +++ b/homeassistant/components/smartthings/lock.py @@ -10,9 +10,12 @@ DEPENDENCIES = ['smartthings'] ST_STATE_LOCKED = 'locked' ST_LOCK_ATTR_MAP = { - 'method': 'method', 'codeId': 'code_id', + 'codeName': 'code_name', + 'lockName': 'lock_name', + 'method': 'method', 'timeout': 'timeout', + 'usedCode': 'used_code' } diff --git a/tests/components/smartthings/test_lock.py b/tests/components/smartthings/test_lock.py index 3739a2dc9b5..922abbb161f 100644 --- a/tests/components/smartthings/test_lock.py +++ b/tests/components/smartthings/test_lock.py @@ -5,6 +5,7 @@ The only mocking required is of the underlying SmartThings API object so real HTTP calls are not initiated during testing. """ from pysmartthings import Attribute, Capability +from pysmartthings.device import Status from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN from homeassistant.components.smartthings import lock @@ -45,8 +46,15 @@ async def test_entity_and_device_attributes(hass, device_factory): async def test_lock(hass, device_factory): """Test the lock locks successfully.""" # Arrange - device = device_factory('Lock_1', [Capability.lock], - {Attribute.lock: 'unlocked'}) + device = device_factory('Lock_1', [Capability.lock]) + device.status.attributes[Attribute.lock] = Status( + 'unlocked', None, { + 'method': 'Manual', + 'codeId': None, + 'codeName': 'Code 1', + 'lockName': 'Front Door', + 'usedCode': 'Code 2' + }) await setup_platform(hass, LOCK_DOMAIN, device) # Act await hass.services.async_call( @@ -56,6 +64,12 @@ async def test_lock(hass, device_factory): state = hass.states.get('lock.lock_1') assert state is not None assert state.state == 'locked' + assert state.attributes['method'] == 'Manual' + assert state.attributes['lock_state'] == 'locked' + assert state.attributes['code_name'] == 'Code 1' + assert state.attributes['used_code'] == 'Code 2' + assert state.attributes['lock_name'] == 'Front Door' + assert 'code_id' not in state.attributes async def test_unlock(hass, device_factory):