|
|
|
|
@@ -33,13 +33,13 @@ from tests.common import (
|
|
|
|
|
async_fire_time_changed,
|
|
|
|
|
)
|
|
|
|
|
from tests.components.alarm_control_panel import common
|
|
|
|
|
from tests.typing import MqttMockHAClientGenerator
|
|
|
|
|
from tests.typing import MqttMockHAClient
|
|
|
|
|
|
|
|
|
|
CODE = "HELLO_CODE"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_fail_setup_without_state_topic(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test for failing with no state topic."""
|
|
|
|
|
with assert_setup_component(0, alarm_control_panel.DOMAIN) as config:
|
|
|
|
|
@@ -57,7 +57,7 @@ async def test_fail_setup_without_state_topic(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_fail_setup_without_command_topic(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test failing with no command topic."""
|
|
|
|
|
with assert_setup_component(0, alarm_control_panel.DOMAIN):
|
|
|
|
|
@@ -87,7 +87,7 @@ async def test_no_pending(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
service,
|
|
|
|
|
expected_state,
|
|
|
|
|
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
|
|
|
|
mqtt_mock: MqttMockHAClient,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test arm method."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -135,7 +135,7 @@ async def test_no_pending_when_code_not_req(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
service,
|
|
|
|
|
expected_state,
|
|
|
|
|
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
|
|
|
|
mqtt_mock: MqttMockHAClient,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test arm method."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -184,7 +184,7 @@ async def test_with_pending(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
service,
|
|
|
|
|
expected_state,
|
|
|
|
|
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
|
|
|
|
mqtt_mock: MqttMockHAClient,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test arm method."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -256,7 +256,7 @@ async def test_with_invalid_code(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
service,
|
|
|
|
|
expected_state,
|
|
|
|
|
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
|
|
|
|
mqtt_mock: MqttMockHAClient,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Attempt to arm without a valid code."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -304,7 +304,7 @@ async def test_with_template_code(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
service,
|
|
|
|
|
expected_state,
|
|
|
|
|
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
|
|
|
|
mqtt_mock: MqttMockHAClient,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Attempt to arm with a template-based code."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -353,7 +353,7 @@ async def test_with_specific_pending(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
service,
|
|
|
|
|
expected_state,
|
|
|
|
|
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
|
|
|
|
mqtt_mock: MqttMockHAClient,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test arm method."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -395,7 +395,7 @@ async def test_with_specific_pending(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_no_pending(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test triggering when no pending submitted method."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -435,7 +435,7 @@ async def test_trigger_no_pending(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_delay(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test trigger method and switch from pending to triggered."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -483,7 +483,7 @@ async def test_trigger_with_delay(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_zero_trigger_time(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test disabled trigger."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -513,7 +513,7 @@ async def test_trigger_zero_trigger_time(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_zero_trigger_time_with_pending(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test disabled trigger."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -543,7 +543,7 @@ async def test_trigger_zero_trigger_time_with_pending(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_pending(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test arm home method."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -596,7 +596,7 @@ async def test_trigger_with_pending(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_disarm_after_trigger(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test disarm after trigger."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -636,7 +636,7 @@ async def test_trigger_with_disarm_after_trigger(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_zero_specific_trigger_time(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test trigger method."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -667,7 +667,7 @@ async def test_trigger_with_zero_specific_trigger_time(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_unused_zero_specific_trigger_time(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test disarm after trigger."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -708,7 +708,7 @@ async def test_trigger_with_unused_zero_specific_trigger_time(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_specific_trigger_time(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test disarm after trigger."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -748,7 +748,7 @@ async def test_trigger_with_specific_trigger_time(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_back_to_back_trigger_with_no_disarm_after_trigger(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test no disarm after back to back trigger."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -806,7 +806,7 @@ async def test_back_to_back_trigger_with_no_disarm_after_trigger(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_disarm_while_pending_trigger(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test disarming while pending state."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -849,7 +849,7 @@ async def test_disarm_while_pending_trigger(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_disarm_during_trigger_with_invalid_code(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test disarming while code is invalid."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -897,7 +897,7 @@ async def test_disarm_during_trigger_with_invalid_code(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_unused_specific_delay(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test trigger method and switch from pending to triggered."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -946,7 +946,7 @@ async def test_trigger_with_unused_specific_delay(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_specific_delay(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test trigger method and switch from pending to triggered."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -995,7 +995,7 @@ async def test_trigger_with_specific_delay(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_pending_and_delay(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test trigger method and switch from pending to triggered."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -1056,7 +1056,7 @@ async def test_trigger_with_pending_and_delay(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_pending_and_specific_delay(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test trigger method and switch from pending to triggered."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -1118,7 +1118,7 @@ async def test_trigger_with_pending_and_specific_delay(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_specific_pending(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test arm home method."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -1167,7 +1167,7 @@ async def test_trigger_with_specific_pending(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_trigger_with_no_disarm_after_trigger(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test disarm after trigger."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -1212,7 +1212,7 @@ async def test_trigger_with_no_disarm_after_trigger(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_arm_away_after_disabled_disarmed(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test pending state with and without zero trigger time."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -1278,7 +1278,7 @@ async def test_arm_away_after_disabled_disarmed(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_disarm_with_template_code(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Attempt to disarm with a valid or invalid template-based code."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -1332,7 +1332,7 @@ async def test_arm_via_command_topic(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
config,
|
|
|
|
|
expected_state,
|
|
|
|
|
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
|
|
|
|
mqtt_mock: MqttMockHAClient,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test arming via command topic."""
|
|
|
|
|
command = config[8:].upper()
|
|
|
|
|
@@ -1374,7 +1374,7 @@ async def test_arm_via_command_topic(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_disarm_pending_via_command_topic(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test disarming pending alarm via command topic."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -1410,7 +1410,7 @@ async def test_disarm_pending_via_command_topic(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_state_changes_are_published_to_mqtt(
|
|
|
|
|
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
|
|
|
|
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test publishing of MQTT messages when state changes."""
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
@@ -1431,7 +1431,6 @@ async def test_state_changes_are_published_to_mqtt(
|
|
|
|
|
|
|
|
|
|
# Component should send disarmed alarm state on startup
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
|
"alarm/state", STATE_ALARM_DISARMED, 0, True
|
|
|
|
|
)
|
|
|
|
|
|