mirror of
https://github.com/home-assistant/core.git
synced 2026-09-28 02:18:10 -04:00
Add Homee alarm-control-panel platform (#140041)
* Add alarm control panel * Add alarm control panel tests * add disarm function * reuse state setting code * change sleeping to night * review change 1 * fix review comments * fix review comments
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
{
|
||||
"id": -1,
|
||||
"name": "homee",
|
||||
"profile": 1,
|
||||
"image": "default",
|
||||
"favorite": 0,
|
||||
"order": 0,
|
||||
"protocol": 0,
|
||||
"routing": 0,
|
||||
"state": 1,
|
||||
"state_changed": 16,
|
||||
"added": 16,
|
||||
"history": 1,
|
||||
"cube_type": 0,
|
||||
"note": "",
|
||||
"services": 0,
|
||||
"phonetic_name": "",
|
||||
"owner": 0,
|
||||
"security": 0,
|
||||
"attributes": [
|
||||
{
|
||||
"id": 1,
|
||||
"node_id": -1,
|
||||
"instance": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 200,
|
||||
"current_value": 0.0,
|
||||
"target_value": 0.0,
|
||||
"last_value": 2.0,
|
||||
"unit": "n/a",
|
||||
"step_value": 1.0,
|
||||
"editable": 1,
|
||||
"type": 205,
|
||||
"state": 1,
|
||||
"last_changed": 1735815716,
|
||||
"changed_by": 2,
|
||||
"changed_by_id": 4,
|
||||
"based_on": 1,
|
||||
"data": "",
|
||||
"name": "",
|
||||
"options": {
|
||||
"history": {
|
||||
"day": 182,
|
||||
"week": 26,
|
||||
"month": 6,
|
||||
"stepped": true
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 18,
|
||||
"node_id": -1,
|
||||
"instance": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 100,
|
||||
"current_value": 15.0,
|
||||
"target_value": 15.0,
|
||||
"last_value": 15.0,
|
||||
"unit": "%",
|
||||
"step_value": 0.1,
|
||||
"editable": 0,
|
||||
"type": 311,
|
||||
"state": 1,
|
||||
"last_changed": 1739390161,
|
||||
"changed_by": 1,
|
||||
"changed_by_id": 0,
|
||||
"based_on": 1,
|
||||
"data": "",
|
||||
"name": "",
|
||||
"options": {
|
||||
"history": {
|
||||
"day": 1,
|
||||
"week": 26,
|
||||
"month": 6
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 19,
|
||||
"node_id": -1,
|
||||
"instance": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 100,
|
||||
"current_value": 5.0,
|
||||
"target_value": 5.0,
|
||||
"last_value": 10.0,
|
||||
"unit": "%",
|
||||
"step_value": 0.1,
|
||||
"editable": 0,
|
||||
"type": 312,
|
||||
"state": 1,
|
||||
"last_changed": 1739390161,
|
||||
"changed_by": 1,
|
||||
"changed_by_id": 0,
|
||||
"based_on": 1,
|
||||
"data": "",
|
||||
"name": "",
|
||||
"options": {
|
||||
"history": {
|
||||
"day": 1,
|
||||
"week": 26,
|
||||
"month": 6
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 20,
|
||||
"node_id": -1,
|
||||
"instance": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 100,
|
||||
"current_value": 10.0,
|
||||
"target_value": 10.0,
|
||||
"last_value": 10.0,
|
||||
"unit": "%",
|
||||
"step_value": 0.1,
|
||||
"editable": 0,
|
||||
"type": 313,
|
||||
"state": 1,
|
||||
"last_changed": 1739390161,
|
||||
"changed_by": 1,
|
||||
"changed_by_id": 0,
|
||||
"based_on": 1,
|
||||
"data": "",
|
||||
"name": "",
|
||||
"options": {
|
||||
"history": {
|
||||
"day": 1,
|
||||
"week": 26,
|
||||
"month": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
# serializer version: 1
|
||||
# name: test_alarm_control_panel_snapshot[alarm_control_panel.testhomee_status-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'alarm_control_panel',
|
||||
'entity_category': None,
|
||||
'entity_id': 'alarm_control_panel.testhomee_status',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Status',
|
||||
'platform': 'homee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 39>,
|
||||
'translation_key': 'homee_mode',
|
||||
'unique_id': '00055511EECC--1-1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_alarm_control_panel_snapshot[alarm_control_panel.testhomee_status-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'changed_by': 'user - 4',
|
||||
'code_arm_required': False,
|
||||
'code_format': None,
|
||||
'friendly_name': 'TestHomee Status',
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 39>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'alarm_control_panel.testhomee_status',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'armed_home',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,96 @@
|
||||
"""Test Homee alarm control panels."""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
|
||||
SERVICE_ALARM_ARM_AWAY,
|
||||
SERVICE_ALARM_ARM_HOME,
|
||||
SERVICE_ALARM_ARM_NIGHT,
|
||||
SERVICE_ALARM_ARM_VACATION,
|
||||
SERVICE_ALARM_DISARM,
|
||||
)
|
||||
from homeassistant.components.homee.const import DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import build_mock_node, setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
async def setup_alarm_control_panel(
|
||||
hass: HomeAssistant, mock_homee: MagicMock, mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Setups the integration for select tests."""
|
||||
mock_homee.nodes = [build_mock_node("homee.json")]
|
||||
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("service", "state"),
|
||||
[
|
||||
(SERVICE_ALARM_ARM_HOME, 0),
|
||||
(SERVICE_ALARM_ARM_NIGHT, 1),
|
||||
(SERVICE_ALARM_ARM_AWAY, 2),
|
||||
(SERVICE_ALARM_ARM_VACATION, 3),
|
||||
],
|
||||
)
|
||||
async def test_alarm_control_panel_services(
|
||||
hass: HomeAssistant,
|
||||
mock_homee: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
service: str,
|
||||
state: int,
|
||||
) -> None:
|
||||
"""Test alarm control panel services."""
|
||||
await setup_alarm_control_panel(hass, mock_homee, mock_config_entry)
|
||||
|
||||
await hass.services.async_call(
|
||||
ALARM_CONTROL_PANEL_DOMAIN,
|
||||
service,
|
||||
{ATTR_ENTITY_ID: "alarm_control_panel.testhomee_status"},
|
||||
blocking=True,
|
||||
)
|
||||
mock_homee.set_value.assert_called_once_with(-1, 1, state)
|
||||
|
||||
|
||||
async def test_alarm_control_panel_service_disarm_error(
|
||||
hass: HomeAssistant,
|
||||
mock_homee: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test that disarm service calls no action."""
|
||||
await setup_alarm_control_panel(hass, mock_homee, mock_config_entry)
|
||||
|
||||
with pytest.raises(ServiceValidationError) as exc_info:
|
||||
await hass.services.async_call(
|
||||
ALARM_CONTROL_PANEL_DOMAIN,
|
||||
SERVICE_ALARM_DISARM,
|
||||
{ATTR_ENTITY_ID: "alarm_control_panel.testhomee_status"},
|
||||
blocking=True,
|
||||
)
|
||||
assert exc_info.value.translation_domain == DOMAIN
|
||||
assert exc_info.value.translation_key == "disarm_not_supported"
|
||||
|
||||
|
||||
async def test_alarm_control_panel_snapshot(
|
||||
hass: HomeAssistant,
|
||||
mock_homee: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the alarm-control_panel snapshots."""
|
||||
with patch(
|
||||
"homeassistant.components.homee.PLATFORMS", [Platform.ALARM_CONTROL_PANEL]
|
||||
):
|
||||
await setup_alarm_control_panel(hass, mock_homee, mock_config_entry)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
Reference in New Issue
Block a user