diff --git a/homeassistant/components/alexa/capabilities.py b/homeassistant/components/alexa/capabilities.py index 10b382c8dcf..db1fa990c54 100644 --- a/homeassistant/components/alexa/capabilities.py +++ b/homeassistant/components/alexa/capabilities.py @@ -19,6 +19,7 @@ from homeassistant.components.alarm_control_panel.const import ( SUPPORT_ALARM_ARM_NIGHT, ) import homeassistant.components.climate.const as climate +from homeassistant.components.lock import STATE_LOCKING, STATE_UNLOCKING import homeassistant.components.media_player.const as media_player from homeassistant.const import ( ATTR_SUPPORTED_FEATURES, @@ -446,9 +447,11 @@ class AlexaLockController(AlexaCapability): if name != "lockState": raise UnsupportedProperty(name) - if self.entity.state == STATE_LOCKED: + # If its unlocking its still locked and not unlocked yet + if self.entity.state in (STATE_UNLOCKING, STATE_LOCKED): return "LOCKED" - if self.entity.state == STATE_UNLOCKED: + # If its locking its still unlocked and not locked yet + if self.entity.state in (STATE_LOCKING, STATE_UNLOCKED): return "UNLOCKED" return "JAMMED" diff --git a/tests/components/alexa/test_capabilities.py b/tests/components/alexa/test_capabilities.py index 92951d4a0e7..dc93ed6d805 100644 --- a/tests/components/alexa/test_capabilities.py +++ b/tests/components/alexa/test_capabilities.py @@ -6,6 +6,7 @@ import pytest from homeassistant.components.alexa import smart_home from homeassistant.components.alexa.errors import UnsupportedProperty from homeassistant.components.climate import const as climate +from homeassistant.components.lock import STATE_JAMMED, STATE_LOCKING, STATE_UNLOCKING from homeassistant.components.media_player.const import ( SUPPORT_PAUSE, SUPPORT_PLAY, @@ -227,17 +228,29 @@ async def test_report_lock_state(hass): """Test LockController implements lockState property.""" hass.states.async_set("lock.locked", STATE_LOCKED, {}) hass.states.async_set("lock.unlocked", STATE_UNLOCKED, {}) + hass.states.async_set("lock.unlocking", STATE_UNLOCKING, {}) + hass.states.async_set("lock.locking", STATE_LOCKING, {}) + hass.states.async_set("lock.jammed", STATE_JAMMED, {}) hass.states.async_set("lock.unknown", STATE_UNKNOWN, {}) properties = await reported_properties(hass, "lock.locked") properties.assert_equal("Alexa.LockController", "lockState", "LOCKED") + properties = await reported_properties(hass, "lock.unlocking") + properties.assert_equal("Alexa.LockController", "lockState", "LOCKED") + properties = await reported_properties(hass, "lock.unlocked") properties.assert_equal("Alexa.LockController", "lockState", "UNLOCKED") + properties = await reported_properties(hass, "lock.locking") + properties.assert_equal("Alexa.LockController", "lockState", "UNLOCKED") + properties = await reported_properties(hass, "lock.unknown") properties.assert_equal("Alexa.LockController", "lockState", "JAMMED") + properties = await reported_properties(hass, "lock.jammed") + properties.assert_equal("Alexa.LockController", "lockState", "JAMMED") + @pytest.mark.parametrize( "supported_color_modes", [["brightness"], ["hs"], ["color_temp"]]