Fix missing code_required check in async_alarm_arm_night (#21858)

* Fix missing code_required check in async_alarm_arm_night

* Remove double code validation
Test added
This commit is contained in:
Marco M 2019-03-10 14:25:01 +01:00 committed by emontnemery
parent 6f77d9bc34
commit 05333f60d7
2 changed files with 44 additions and 1 deletions

View File

@ -227,7 +227,8 @@ class MqttAlarm(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
This method is a coroutine.
"""
if not self._validate_code(code, 'arming night'):
code_required = self._config.get(CONF_CODE_ARM_REQUIRED)
if code_required and not self._validate_code(code, 'arming night'):
return
mqtt.async_publish(
self.hass, self._config.get(CONF_COMMAND_TOPIC),

View File

@ -135,6 +135,27 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
self.hass.block_till_done()
assert call_count == self.mock_publish.call_count
def test_arm_home_publishes_mqtt_when_code_not_req(self):
"""Test publishing of MQTT messages.
When code_arm_required = False
"""
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'alarm/state',
'command_topic': 'alarm/command',
'code': '1234',
'code_arm_required': False
}
})
common.alarm_arm_home(self.hass)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'alarm/command', 'ARM_HOME', 0, False)
def test_arm_away_publishes_mqtt(self):
"""Test publishing of MQTT messages while armed."""
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
@ -230,6 +251,27 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
self.hass.block_till_done()
assert call_count == self.mock_publish.call_count
def test_arm_night_publishes_mqtt_when_code_not_req(self):
"""Test publishing of MQTT messages.
When code_arm_required = False
"""
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
alarm_control_panel.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'alarm/state',
'command_topic': 'alarm/command',
'code': '1234',
'code_arm_required': False
}
})
common.alarm_arm_night(self.hass)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'alarm/command', 'ARM_NIGHT', 0, False)
def test_disarm_publishes_mqtt(self):
"""Test publishing of MQTT messages while disarmed."""
assert setup_component(self.hass, alarm_control_panel.DOMAIN, {