Skip to content

Commit

Permalink
- port "Add post_pending_state attribute to manual alarm_control_panel
Browse files Browse the repository at this point in the history
…home-assistant#9291" to manuql_mqtt
  • Loading branch information
snjoetw committed Sep 16, 2017
1 parent 8015904 commit 360d760
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions homeassistant/components/alarm_control_panel/manual_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
DEFAULT_ARM_NIGHT = 'ARM_NIGHT'
DEFAULT_DISARM = 'DISARM'

ATTR_POST_PENDING_STATE = 'post_pending_state'

DEPENDENCIES = ['mqtt']

PLATFORM_SCHEMA = mqtt.MQTT_BASE_PLATFORM_SCHEMA.extend({
Expand Down Expand Up @@ -224,6 +226,16 @@ def _validate_code(self, code, state):
_LOGGER.warning("Invalid code given for %s", state)
return check

@property
def device_state_attributes(self):
"""Return the state attributes."""
state_attr = {}

if self.state == STATE_ALARM_PENDING:
state_attr[ATTR_POST_PENDING_STATE] = self._state

return state_attr

def async_added_to_hass(self):
"""Subscribe mqtt events.
Expand Down
20 changes: 20 additions & 0 deletions tests/components/alarm_control_panel/test_manual_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def test_arm_home_with_pending(self):
self.assertEqual(STATE_ALARM_PENDING,
self.hass.states.get(entity_id).state)

self.assertTrue(
self.hass.states.is_state_attr(entity_id,
'post_pending_state',
STATE_ALARM_ARMED_HOME))

future = dt_util.utcnow() + timedelta(seconds=1)
with patch(('homeassistant.components.alarm_control_panel.manual_mqtt.'
'dt_util.utcnow'), return_value=future):
Expand Down Expand Up @@ -184,6 +189,11 @@ def test_arm_away_with_pending(self):
self.assertEqual(STATE_ALARM_PENDING,
self.hass.states.get(entity_id).state)

self.assertTrue(
self.hass.states.is_state_attr(entity_id,
'post_pending_state',
STATE_ALARM_ARMED_AWAY))

future = dt_util.utcnow() + timedelta(seconds=1)
with patch(('homeassistant.components.alarm_control_panel.manual_mqtt.'
'dt_util.utcnow'), return_value=future):
Expand Down Expand Up @@ -268,6 +278,11 @@ def test_arm_night_with_pending(self):
self.assertEqual(STATE_ALARM_PENDING,
self.hass.states.get(entity_id).state)

self.assertTrue(
self.hass.states.is_state_attr(entity_id,
'post_pending_state',
STATE_ALARM_ARMED_NIGHT))

future = dt_util.utcnow() + timedelta(seconds=1)
with patch(('homeassistant.components.alarm_control_panel.manual_mqtt.'
'dt_util.utcnow'), return_value=future):
Expand Down Expand Up @@ -360,6 +375,11 @@ def test_trigger_with_pending(self):
self.assertEqual(STATE_ALARM_PENDING,
self.hass.states.get(entity_id).state)

self.assertTrue(
self.hass.states.is_state_attr(entity_id,
'post_pending_state',
STATE_ALARM_TRIGGERED))

future = dt_util.utcnow() + timedelta(seconds=2)
with patch(('homeassistant.components.alarm_control_panel.manual_mqtt.'
'dt_util.utcnow'), return_value=future):
Expand Down

0 comments on commit 360d760

Please sign in to comment.