mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Add configuration entities to Tuya multifunction alarm (#148556)
This commit is contained in:
parent
ab6ac94af9
commit
1c35aff510
@ -315,6 +315,8 @@ class DPCode(StrEnum):
|
||||
SWITCH_6 = "switch_6" # Switch 6
|
||||
SWITCH_7 = "switch_7" # Switch 7
|
||||
SWITCH_8 = "switch_8" # Switch 8
|
||||
SWITCH_ALARM_LIGHT = "switch_alarm_light"
|
||||
SWITCH_ALARM_SOUND = "switch_alarm_sound"
|
||||
SWITCH_BACKLIGHT = "switch_backlight" # Backlight switch
|
||||
SWITCH_CHARGE = "switch_charge"
|
||||
SWITCH_CONTROLLER = "switch_controller"
|
||||
|
@ -370,6 +370,12 @@
|
||||
},
|
||||
"sterilization": {
|
||||
"default": "mdi:minus-circle-outline"
|
||||
},
|
||||
"arm_beep": {
|
||||
"default": "mdi:volume-high"
|
||||
},
|
||||
"siren": {
|
||||
"default": "mdi:alarm-light"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -906,6 +906,12 @@
|
||||
},
|
||||
"sterilization": {
|
||||
"name": "Sterilization"
|
||||
},
|
||||
"arm_beep": {
|
||||
"name": "Arm beep"
|
||||
},
|
||||
"siren": {
|
||||
"name": "Siren"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -431,6 +431,22 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
),
|
||||
# Alarm Host
|
||||
# https://developer.tuya.com/en/docs/iot/alarm-hosts?id=K9gf48r87hyjk
|
||||
"mal": (
|
||||
SwitchEntityDescription(
|
||||
key=DPCode.SWITCH_ALARM_SOUND,
|
||||
# This switch is called "Arm Beep" in the official Tuya app
|
||||
translation_key="arm_beep",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
SwitchEntityDescription(
|
||||
key=DPCode.SWITCH_ALARM_LIGHT,
|
||||
# This switch is called "Siren" in the official Tuya app
|
||||
translation_key="siren",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
),
|
||||
# Sous Vide Cooker
|
||||
# https://developer.tuya.com/en/docs/iot/categorymzj?id=Kaiuz2vy130ux
|
||||
"mzj": (
|
||||
|
@ -60,6 +60,11 @@ DEVICE_MOCKS = {
|
||||
Platform.SELECT,
|
||||
Platform.SWITCH,
|
||||
],
|
||||
"mal_alarm_host": [
|
||||
# Alarm Host support
|
||||
Platform.ALARM_CONTROL_PANEL,
|
||||
Platform.SWITCH,
|
||||
],
|
||||
"mcs_door_sensor": [
|
||||
# https://github.com/home-assistant/core/issues/108301
|
||||
Platform.BINARY_SENSOR,
|
||||
|
225
tests/components/tuya/fixtures/mal_alarm_host.json
Normal file
225
tests/components/tuya/fixtures/mal_alarm_host.json
Normal file
@ -0,0 +1,225 @@
|
||||
{
|
||||
"id": "123123aba12312312dazub",
|
||||
"name": "Multifunction alarm",
|
||||
"category": "mal",
|
||||
"product_id": "gyitctrjj1kefxp2",
|
||||
"product_name": "Multifunction alarm",
|
||||
"online": true,
|
||||
"sub": false,
|
||||
"time_zone": "+02:00",
|
||||
"active_time": "2024-12-02T20:08:56+00:00",
|
||||
"create_time": "2024-12-02T20:08:56+00:00",
|
||||
"update_time": "2024-12-02T20:08:56+00:00",
|
||||
"function": {
|
||||
"master_mode": {
|
||||
"type": "Enum",
|
||||
"value": {
|
||||
"range": ["disarmed", "arm", "home", "sos"]
|
||||
}
|
||||
},
|
||||
"delay_set": {
|
||||
"type": "Integer",
|
||||
"value": {
|
||||
"unit": "s",
|
||||
"min": 0,
|
||||
"max": 999,
|
||||
"scale": 0,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
"alarm_time": {
|
||||
"type": "Integer",
|
||||
"value": {
|
||||
"unit": "min",
|
||||
"min": 0,
|
||||
"max": 999,
|
||||
"scale": 0,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
"switch_alarm_sound": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"switch_alarm_light": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"switch_mode_sound": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"switch_kb_sound": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"switch_kb_light": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"muffling": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"switch_alarm_propel": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"alarm_delay_time": {
|
||||
"type": "Integer",
|
||||
"value": {
|
||||
"unit": "s",
|
||||
"min": 0,
|
||||
"max": 999,
|
||||
"scale": 0,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
"master_state": {
|
||||
"type": "Enum",
|
||||
"value": {
|
||||
"range": ["normal", "alarm"]
|
||||
}
|
||||
},
|
||||
"sub_class": {
|
||||
"type": "Enum",
|
||||
"value": {
|
||||
"range": ["remote_controller", "detector"]
|
||||
}
|
||||
},
|
||||
"sub_admin": {
|
||||
"type": "Raw",
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
"status_range": {
|
||||
"master_mode": {
|
||||
"type": "Enum",
|
||||
"value": {
|
||||
"range": ["disarmed", "arm", "home", "sos"]
|
||||
}
|
||||
},
|
||||
"delay_set": {
|
||||
"type": "Integer",
|
||||
"value": {
|
||||
"unit": "s",
|
||||
"min": 0,
|
||||
"max": 999,
|
||||
"scale": 0,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
"alarm_time": {
|
||||
"type": "Integer",
|
||||
"value": {
|
||||
"unit": "min",
|
||||
"min": 0,
|
||||
"max": 999,
|
||||
"scale": 0,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
"switch_alarm_sound": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"switch_alarm_light": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"switch_mode_sound": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"switch_kb_sound": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"switch_kb_light": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"telnet_state": {
|
||||
"type": "Enum",
|
||||
"value": {
|
||||
"range": [
|
||||
"normal",
|
||||
"network_no",
|
||||
"phone_no",
|
||||
"sim_card_no",
|
||||
"network_search",
|
||||
"signal_level_1",
|
||||
"signal_level_2",
|
||||
"signal_level_3",
|
||||
"signal_level_4",
|
||||
"signal_level_5"
|
||||
]
|
||||
}
|
||||
},
|
||||
"muffling": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"alarm_msg": {
|
||||
"type": "Raw",
|
||||
"value": {}
|
||||
},
|
||||
"switch_alarm_propel": {
|
||||
"type": "Boolean",
|
||||
"value": {}
|
||||
},
|
||||
"alarm_delay_time": {
|
||||
"type": "Integer",
|
||||
"value": {
|
||||
"unit": "s",
|
||||
"min": 0,
|
||||
"max": 999,
|
||||
"scale": 0,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
"master_state": {
|
||||
"type": "Enum",
|
||||
"value": {
|
||||
"range": ["normal", "alarm"]
|
||||
}
|
||||
},
|
||||
"sub_class": {
|
||||
"type": "Enum",
|
||||
"value": {
|
||||
"range": ["remote_controller", "detector"]
|
||||
}
|
||||
},
|
||||
"sub_admin": {
|
||||
"type": "Raw",
|
||||
"value": {}
|
||||
},
|
||||
"sub_state": {
|
||||
"type": "Enum",
|
||||
"value": {
|
||||
"range": ["normal", "alarm", "fault", "others"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"master_mode": "disarmed",
|
||||
"delay_set": 15,
|
||||
"alarm_time": 3,
|
||||
"switch_alarm_sound": true,
|
||||
"switch_alarm_light": true,
|
||||
"switch_mode_sound": true,
|
||||
"switch_kb_sound": false,
|
||||
"switch_kb_light": false,
|
||||
"telnet_state": "sim_card_no",
|
||||
"muffling": false,
|
||||
"alarm_msg": "AFMAZQBuAHMAbwByACAATABvAHcAIABCAGEAdAB0AGUAcgB5AAoAWgBvAG4AZQA6ADAAMAA1AEUAbgB0AHIAYQBuAGMAZQ==",
|
||||
"switch_alarm_propel": true,
|
||||
"alarm_delay_time": 20,
|
||||
"master_state": "normal",
|
||||
"sub_class": "remote_controller",
|
||||
"sub_admin": "AgEFCggC////HABLAGkAdABjAGgAZQBuACAAUwBtAG8AawBlACBjAAL///8gAHUAbgBkAGUAbABlAHQAYQBiAGwAZQA6AEUATwBMADFkAAL///8gAHUAbgBkAGUAbABlAHQAYQBiAGwAZQA6AEUATwBMADJlAAL///8gAHUAbgBkAGUAbABlAHQAYQBiAGwAZQA6AEUATwBMADNmAAL///8gAHUAbgBkAGUAbABlAHQAYQBiAGwAZQA6AEUATwBMADQ=",
|
||||
"sub_state": "normal"
|
||||
},
|
||||
"set_up": true,
|
||||
"support_local": true
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
# serializer version: 1
|
||||
# name: test_platform_setup_and_discovery[mal_alarm_host][alarm_control_panel.multifunction_alarm-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.multifunction_alarm',
|
||||
'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': None,
|
||||
'platform': 'tuya',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 11>,
|
||||
'translation_key': None,
|
||||
'unique_id': 'tuya.123123aba12312312dazubmaster_mode',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_platform_setup_and_discovery[mal_alarm_host][alarm_control_panel.multifunction_alarm-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'changed_by': None,
|
||||
'code_arm_required': False,
|
||||
'code_format': None,
|
||||
'friendly_name': 'Multifunction alarm',
|
||||
'supported_features': <AlarmControlPanelEntityFeature: 11>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'alarm_control_panel.multifunction_alarm',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'disarmed',
|
||||
})
|
||||
# ---
|
@ -579,6 +579,102 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_platform_setup_and_discovery[mal_alarm_host][switch.multifunction_alarm_arm_beep-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': 'switch',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.multifunction_alarm_arm_beep',
|
||||
'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': 'Arm beep',
|
||||
'platform': 'tuya',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'arm_beep',
|
||||
'unique_id': 'tuya.123123aba12312312dazubswitch_alarm_sound',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_platform_setup_and_discovery[mal_alarm_host][switch.multifunction_alarm_arm_beep-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Multifunction alarm Arm beep',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.multifunction_alarm_arm_beep',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_platform_setup_and_discovery[mal_alarm_host][switch.multifunction_alarm_siren-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': 'switch',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.multifunction_alarm_siren',
|
||||
'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': 'Siren',
|
||||
'platform': 'tuya',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'siren',
|
||||
'unique_id': 'tuya.123123aba12312312dazubswitch_alarm_light',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_platform_setup_and_discovery[mal_alarm_host][switch.multifunction_alarm_siren-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Multifunction alarm Siren',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.multifunction_alarm_siren',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_platform_setup_and_discovery[sfkzq_valve_controller][switch.sprinkler_cesare_switch-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
|
57
tests/components/tuya/test_alarm_control_panel.py
Normal file
57
tests/components/tuya/test_alarm_control_panel.py
Normal file
@ -0,0 +1,57 @@
|
||||
"""Test Tuya Alarm Control Panel platform."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from tuya_sharing import CustomerDevice
|
||||
|
||||
from homeassistant.components.tuya import ManagerCompat
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import DEVICE_MOCKS, initialize_entry
|
||||
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
[k for k, v in DEVICE_MOCKS.items() if Platform.ALARM_CONTROL_PANEL in v],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: ManagerCompat,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_device: CustomerDevice,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test platform setup and discovery."""
|
||||
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
[k for k, v in DEVICE_MOCKS.items() if Platform.ALARM_CONTROL_PANEL not in v],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
|
||||
async def test_platform_setup_no_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: ManagerCompat,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_device: CustomerDevice,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test platform setup without discovery."""
|
||||
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
||||
|
||||
assert not er.async_entries_for_config_entry(
|
||||
entity_registry, mock_config_entry.entry_id
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user