Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing code_required check in async_alarm_arm_night #21858

Merged
merged 2 commits into from Mar 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/mqtt/alarm_control_panel.py
Expand Up @@ -227,7 +227,8 @@ async def async_alarm_arm_night(self, code=None):

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),
Expand Down
42 changes: 42 additions & 0 deletions tests/components/mqtt/test_alarm_control_panel.py
Expand Up @@ -135,6 +135,27 @@ def test_arm_home_not_publishes_mqtt_with_invalid_code_when_req(self):
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, {
Expand Down Expand Up @@ -230,6 +251,27 @@ def test_arm_night_not_publishes_mqtt_with_invalid_code_when_req(self):
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, {
Expand Down